Site Root : C++StaticAssert

C++ Static Assert

Purpose

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.

Example

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 (http://www.boost.org/libs/static_assert/static_assert.htm), 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.

References

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

http://www.openoffice.org/servlets/ReadMsg?msgId=930121&listName=dev

See StaticAssert.hxx for more details.

Caolan McNamara (2003) <caolan@skynet.ie>

Download Package

C++StaticAssert/C++StaticAssert.tar.gz
Last generated at Sat Nov 2 12:10:06 2013 Caolán McNamara <caolan@skynet.ie> Created with WebMake/0.5