Wednesday, August 16, 2017

C++11: Static Assertion


static_assert(<bool_constexpr> , <message>); was added to c++11.
Here is an example:

static_assert( (sizeof(long) == 3), "Error: the type int is not 3 bytes");
int main() {return 0;}
// Output During Compile: error C2338: Error: the type int is not 3 bytes

Reference: https://isocpp.org/wiki/faq/cpp11-language-misc#static-assert
                  http://en.cppreference.com/w/cpp/language/static_assert

No comments:

Post a Comment