Site Root : C++StaticAssert

C++ Static Assert


StaticAssert is like assert for C++, except that the test is done at compile time. Of course this can only be done when the test is possible at compile time.


const char *stiName = { "Normal" };

StaticAssert((sizeof(stiName) / sizeof(stiName)) == 100, WrongSizeOfArray);

Here the array is one element in size, and we have a StaticAssert that will fail if the array is not 100 in size with an error of WrongSizeOfArray.

boost also provides a Static Assert (, but if you don't want all of boost, or you can't get it to compile, then this might still be of use to you.


This is simply a packaged standalone header of the StaticAssert shown in Modern C++ Design: Generic Programming and Design Patterns Applied Section 2.1 by Andrei Alexandrescu.

Original Link

See StaticAssert.hxx for more details.

Caolan McNamara (2003) <>

Download Package

Last generated at Sun Feb 7 00:44:59 2016 Caolán McNamara <> Created with WebMake/0.5