Macros
Compile time assertion

Macros

#define BLAZE_STATIC_ASSERT(expr)
 Compile time assertion macro.In case of an invalid compile time expression, a compilation error is created. More...
 

Detailed Description

Static assertion offers the possibility to stop the compilation process if a specific compile time condition is not met. The blaze::BLAZE_STATIC_ASSERT macro can be used to check an integral constant expression at compile time. If the expression evaluates to false, a compilation error is generated that stops the compilation process. If the expression (hopefully) evaluates to true, the compilation process is not aborted and the static check leaves neither code nor data and is therefore not affecting the performance.
The blaze::BLAZE_STATIC_ASSERT macro can be used wherever a standard typedef statement can be declared, i.e. in namespace scope, in class scope and in function scope. The following examples illustrate the use of the static assertion macro: the type of the rotation matrix is checked at compile time and restricted to be of floating point type.

#include <limits>
template< typename T >
class RotationMatrix {
...
BLAZE_STATIC_ASSERT( !std::numeric_limits<T>::is_integer );
...
};

The static assertion is implemented in such a way that the created error messages for a failed compile time check contains either the term STATIC_ASSERT or STATIC_ASSERT_FAILED. The error message doesn't explicitly explain the source of the error, but is at least useful to catch the eye. The following examples show possible error messages for the GNU g++ and the Intel compiler:

incomplete type ‘blaze::STATIC_ASSERTION_FAILED<false>’ used in nested name specifier
error: incomplete type is not allowed
BLAZE_STATIC_ASSERT( !std::numeric_limits<T>::is_integer );

Note: blaze::BLAZE_STATIC_ASSERT can only can expressions of integral type. Floating point expressions cannot be checked at compile time!

Acknowledgements: blaze::BLAZE_STATIC_ASSERT builds on ideas developed by John Maddock within the Boost C++ framework (www.boost.org). However, it uses a slightly changed compile time check that completely relies on a nested enum variable and doesn't use an old-style C cast.

Macro Definition Documentation

#define BLAZE_STATIC_ASSERT (   expr)
Value:
typedef ::blaze::STATIC_ASSERTION_TEST< ::blaze::STATIC_ASSERTION_FAILED< (expr) != 0 >::value > \
BLAZE_JOIN( BLAZE_STATIC_ASSERTION_TYPEDEF, __LINE__ )

Compile time assertion macro.In case of an invalid compile time expression, a compilation error is created.