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 Sat Nov 2 12:10:06 2013 Caolán McNamara <> Created with WebMake/0.5