static_assert.h File Reference

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.

Detailed Description

Define the STATIC_ASSERT macro.

Definition in file static_assert.h.


Define Documentation

#define STATIC_ASSERT ( B,
txt   ) 
Value:
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
    // ...
   }
Note:
This will work because, as specified by the standard, a (non-virtual) method of class template is instanciated 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.

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().

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Generated on Fri May 31 15:37:53 2013 for VVE by  doxygen 1.6.3