Thiago R. Adams website

Home CodeBlog Articles Downloads Links Books About

Websites

Assertions in compile time

See:
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2004/n1720.html And:
http://www.boost.org/doc/libs/1_37_0/doc/html/boost_staticassert.html

For simple cases we can use today:

#include <cassert>
namespace private_assertion_namespace
{
    template<bool assertion> struct assertion_class;
    template<> struct assertion_class<true>
    {
        static const bool value = true;
    };
}

#define static_assert(x)  assert(private_assertion_namespace::assertion_class<(x)>::value);

Want to see more? Go to the CodeBlog section.

About the author: I am Thiago Adams. I work as a professional C++ software engineer. I have created this website to share ideas and source code with other people with similar interests.
I would like to hear from you comments, critics, questions and suggestions about this topic or any other part of this website. Email: thiago.adams at gmail dot com