C++ Language/Preprocessing/CompileTimeAssertions

From Wikibooks, open books for an open world
Jump to navigation Jump to search

The traditional way to assert the truth of something at compile-time was to use the preprocessor's #error (within some #if block). But some compile-time activity happens after the preprocessor has finished, so modern code uses a static_assert() compile-time assertion.

Additional information about compile-time assertions (includes interactive examples)