I was trying to use std::is_same
to verify the underlying type of a strongly typed enum and I noticed a strange situation where I needed to use double parentheses, but I don't understand why. I've reduced the example down to as follows:
#include <type_traits>
#include <cassert>
#include <stdint.h>
int main(int argc, char *argv[])
{
assert((std::is_same<unsigned int,uint32_t>::value == true)); // OK
assert((std::is_same<unsigned int,uint32_t>::value) == true); // OK
//assert(std::is_same<unsigned int,uint32_t>::value == true); // Compile error
static_assert(std::is_same<unsigned int,uint32_t>::value == true, "BAD"); // OK
return 0;
}
Compile error:
isSameAssert.cpp:9:62: error: macro "assert" passed 2 arguments, but takes just 1
assert(std::is_same<unsigned int,uint32_t>::value == true); // Compile error
^
isSameAssert.cpp: In function ‘int main(int, char**)’:
isSameAssert.cpp:9:5: error: ‘assert’ was not declared in this scope
assert(std::is_same<unsigned int,uint32_t>::value == true); // Compile error
^
make: *** [build/isSameAssert] Error 1
Could anyone explain this or point me to a reference that does?