को देखते हुए this test program:यह "कॉल" क्यों केवल एक के बजाय दो तर्क देखने का दावा करता है?
#include <cassert>
#include <string>
#include <type_traits>
const std::string& const_string = "bla";
std::string const & string_const = "blabla";
static_assert(std::is_same<decltype(const_string), decltype(string_const)>::value, "Uhoh");
int main()
{
assert(std::is_same<decltype(const_string), decltype(string_const)>::value);
}
कौन सा दावा है कि दो प्रकार के संकलन समय पर और रनटाइम पर सी ज़ोर का उपयोग कर एक ही हैं। बजना, MSVC2015, और जीसीसी के सभी एक ही त्रुटि की सूचना देती है, इसलिए मैं काफी यकीन है कि it's me हूँ:
main.cpp:13:49: error: too many arguments provided to function-like macro invocation
assert(std::is_same<decltype(const_string), decltype(string_const)>::value);
^
/usr/include/assert.h:91:10: note: macro 'assert' defined here
# define assert(expr) \
^
मैं सिर्फ assert
में दो तर्क नहीं दिखाई दे रहा। और क्या है, static_assert
बस ठीक काम करता है ... तो यहाँ क्या चल रहा है?
मेरा मानना है कि प्रीप्रोसेसर दो "तुलना" देखता है; 'std :: is_same :: value'। प्रीप्रोसेसर को यह बताने का कोई तरीका नहीं है कि वे नहीं हैं। –
molbdnilo
** static_assert ** एक कीवर्ड है, ** ** एक प्रीप्रोसेसर मैक्रो जोर दें। प्रीप्रोसेसर मैक्रोज़ ने गैर-स्मार्ट तरीके से ',' द्वारा तर्क विभाजित किया। अतिरिक्त कोष्ठक इसे रोकते हैं। – Youka