Why can't I use assert with std :: is_same?

Can someone explain to me why on Earth this piece of code refuses to work?

#include <cassert>
#include <type_traits>
using namespace std;

int main()
{
    assert(is_same<int, int>::value);
}

Compilation error because, according to the compiler,

prog.cpp:7:33: error: macro "assert" passed 2 arguments, but takes just 1
  assert(is_same<int, int>::value);
                             ^
prog.cpp: In function 'int main()':
prog.cpp:7:2: error: 'assert' was not declared in this scope
  assert(is_same<int, int>::value);
  ^

What? is_same<int, int>::valueundoubtedly is one of the arguments. Also declared in this area assert, and the compiler itself confirmed this in a previous error!

http://ideone.com/LcMVkn

+4
source share
1 answer

A macro breaks your parameters as follows:

    is_same<int , int>::value
 // ^^ par1  ^^// ^^ par2  ^^

assert() - ( ), C-. ++, , (<>), ,. , , .

, , C- :

assert((is_same<int, int>::value));
    // ^                        ^
+5

Source: https://habr.com/ru/post/1660731/


All Articles