Why this (static_assert) in a definition of a class doesn't work?
template<class IntT, IntT low = IntT(), IntT high = IntT()>
struct X
{
static_assert(std::is_same<decltype(low),decltype(high)>::value,"Different types not allowed");
};
int _tmain(int argc, _TCHAR* argv[])
{
int low, high;
X<char,1,'a'> x;//HERE I SHOULD GET ERROR
cout << sizeof(x);
return 0;
}
static_assertworks fine, is your code that never assert.The template
struct Xdefineslowandhighas of typeIntT. They are both the same type, whatever values they have.When you instantiate the struct (
X<char,1,'a'> x) you are telling the compiler that the type ofIntTischarand are giving tolowthe value1and tohighthe value'a'(i.e. 97). However, the type oflowandhighis alwayscharso thestatic_assertwill never assert.