MorphoGraphX
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Namespaces | Macros
StaticAssert.hpp File Reference

Define the STATIC_ASSERT macro. More...

Go to the source code of this file.

Classes

struct  mgx::util::STATIC_ASSERTION_FAILURE< x >
 
struct  mgx::util::STATIC_ASSERTION_FAILURE< true >
 
struct  mgx::util::static_assert_test< x >
 

Namespaces

 mgx
 This namespace contains all the API of MorphoGraphX.
 

Macros

#define _MGX_JOIN(X, Y)
 
#define _MGX_DO_JOIN(X, Y)
 
#define _MGX_DO_JOIN2(X, Y)
 
#define STATIC_ASSERT(B)
 Assertion that works at compile time. More...
 

Detailed Description

Define the STATIC_ASSERT macro.

Macro Definition Documentation

#define STATIC_ASSERT (   B)

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
// ...
}
Note
This will work because, as specified by the standard, a (non-virtual) method of class template is instantiated only if used. So, as long as the user do not try to construct a vector with two values, this specific constructor won't even exist.