Macros
Compile time assertion

Macros

#define BLAZE_STATIC_ASSERT(expr)   static_assert( expr, "Compile time condition violated" )
 Compile time assertion macro.In case of an invalid compile time expression, a compilation error is created.
 
#define BLAZE_STATIC_ASSERT_MSG(expr, msg)   static_assert( expr, msg )
 Compile time assertion macro.In case of an invalid compile time expression, a compilation error is created.
 

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 and blaze::BLAZE_STATIC_ASSERT_MSG macros can be used to check a 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.
Both static assertion macros 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 macros: The element type of the rotation matrix is checked at compile time and restricted to be of floating point type.

#include <blaze/util/typetraits/FloatingPoint.h>
template< typename T >
class RotationMatrix {
...
BLAZE_STATIC_ASSERT( IsFloatingPoint<T>::value );
// ... or ...
BLAZE_STATIC_ASSERT_MSG( IsFloatingPoint<T>::value, "Given type is not a floating point type" );
...
};

The static assertion implementation is based on the C++11 static_assert declaration. Thus the error message contains the violated compile time condition and directly refers to the violated static assertion. The following examples show a possible error message from the GNU g++ compiler:

error: static assertion failed: Compile time condition violated
static_assert( expr, "Compile time condition violated" )
^
note: in expansion of macro 'BLAZE_STATIC_ASSERT'
BLAZE_STATIC_ASSERT( IsFloatingPoint<T>::value );
error: static assertion failed: Given type is not a floating point type
static_assert( expr, msg )
^
note: in expansion of macro 'BLAZE_STATIC_ASSERT_MSG'
BLAZE_STATIC_ASSERT_MSG( IsFloatingPoint<T>::value, "Given type is not a floating point type" );