| Index: platform/assert.h
|
| ===================================================================
|
| --- platform/assert.h (revision 10127)
|
| +++ platform/assert.h (working copy)
|
| @@ -268,6 +268,29 @@
|
|
|
| #define DEBUG_ASSERT(cond)
|
|
|
| +// The COMPILE_ASSERT macro can be used to verify that a compile time
|
| +// expression is true. For example, you could use it to verify the
|
| +// size of a static array:
|
| +//
|
| +// COMPILE_ASSERT(ARRAYSIZE(content_type_names) == CONTENT_NUM_TYPES,
|
| +// content_type_names_incorrect_size);
|
| +//
|
| +// or to make sure a struct is smaller than a certain size:
|
| +//
|
| +// COMPILE_ASSERT(sizeof(foo) < 128, foo_too_large);
|
| +//
|
| +// The second argument to the macro is the name of the variable. If
|
| +// the expression is false, most compilers will issue a warning/error
|
| +// containing the name of the variable.
|
| +
|
| +template <bool>
|
| +struct CompileAssert {
|
| +};
|
| +
|
| +#define COMPILE_ASSERT(expr, msg) \
|
| + typedef CompileAssert<(static_cast<bool>(expr))> \
|
| + msg[static_cast<bool>(expr) ? 1 : -1]
|
| +
|
| #endif // if defined(DEBUG)
|
|
|
|
|
|
|