Define the STATIC_ASSERT macro. More...
#include <config.h>
Go to the source code of this file.
Namespaces | |
namespace | util |
Various utility classes for generic programming. | |
Defines | |
#define | DO_JOIN(X, Y) DO_JOIN2(X,Y) |
#define | DO_JOIN2(X, Y) X##Y |
#define | JOIN(X, Y) DO_JOIN( X, Y ) |
#define | STATIC_ASSERT(B, txt) |
Assertion that works at compile time. |
Define the STATIC_ASSERT macro.
Definition in file static_assert.h.
#define STATIC_ASSERT | ( | B, | |||
txt | ) |
typedef util::static_assert_test<\ sizeof(util::STATIC_ASSERTION_FAILURE< (bool)( B ) >)>\ JOIN(static_assert_typedef_, __LINE__)
Assertion that works at compile time.
If the parameters evaluate to false, the program won't compile. Useful to check that a template method is not used when it is invalid.
A typical example can be found in the implementation of the util::Vector class to make sure the constructor with n (fixed) values are used only if the vector is of dimension n:
template <size_t N, typename T> Vector<N,T>::Vector( const T& v1, const T& v2) { STATIC_ASSERT(N == 2); // Compilation will fail if N != 2 // ... }
Definition at line 48 of file static_assert.h.
Referenced by util::Vector< nCols, double >::cross(), util::Vector< nCols, double >::i(), util::Vector< nCols, double >::j(), util::Vector< nCols, double >::k(), util::Vector< nCols, double >::l(), util::Vector< nCols, double >::projectXY(), util::Vector< nCols, double >::set(), util::Vector< nCols, double >::t(), util::Vector< nCols, double >::Vector(), util::Vector< nCols, double >::x(), util::Vector< nCols, double >::y(), and util::Vector< nCols, double >::z().