StaticAssert.h
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
5 // Copyright (C) 2008 Benoit Jacob <jacob.benoit.1@gmail.com>
6 //
7 // This Source Code Form is subject to the terms of the Mozilla
8 // Public License v. 2.0. If a copy of the MPL was not distributed
9 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 
11 #ifndef EIGEN_STATIC_ASSERT_H
12 #define EIGEN_STATIC_ASSERT_H
13 
14 /* Some notes on Eigen's static assertion mechanism:
15  *
16  * - in EIGEN_STATIC_ASSERT(CONDITION,MSG) the parameter CONDITION must be a compile time boolean
17  * expression, and MSG an enum listed in struct internal::static_assertion<true>
18  *
19  * - define EIGEN_NO_STATIC_ASSERT to disable them (and save compilation time)
20  * in that case, the static assertion is converted to the following runtime assert:
21  * eigen_assert(CONDITION && "MSG")
22  *
23  * - currently EIGEN_STATIC_ASSERT can only be used in function scope
24  *
25  */
26 
27 #ifndef EIGEN_NO_STATIC_ASSERT
28 
29  #if defined(__GXX_EXPERIMENTAL_CXX0X__) || (defined(_MSC_VER) && (_MSC_VER >= 1600))
30 
31  // if native static_assert is enabled, let's use it
32  #define EIGEN_STATIC_ASSERT(X,MSG) static_assert(X,#MSG);
33 
34  #else // not CXX0X
35 
36  namespace Eigen {
37 
38  namespace internal {
39 
40  template<bool condition>
41  struct static_assertion {};
42 
43  template<>
44  struct static_assertion<true>
45  {
46  enum {
93  OBJECT_ALLOCATED_ON_STACK_IS_TOO_BIG
94  };
95  };
96 
97  } // end namespace internal
98 
99  } // end namespace Eigen
100 
101  // Specialized implementation for MSVC to avoid "conditional
102  // expression is constant" warnings. This implementation doesn't
103  // appear to work under GCC, hence the multiple implementations.
104  #ifdef _MSC_VER
105 
106  #define EIGEN_STATIC_ASSERT(CONDITION,MSG) \
107  {Eigen::internal::static_assertion<bool(CONDITION)>::MSG;}
108 
109  #else
110 
111  #define EIGEN_STATIC_ASSERT(CONDITION,MSG) \
112  if (Eigen::internal::static_assertion<bool(CONDITION)>::MSG) {}
113 
114  #endif
115 
116  #endif // not CXX0X
117 
118 #else // EIGEN_NO_STATIC_ASSERT
119 
120  #define EIGEN_STATIC_ASSERT(CONDITION,MSG) eigen_assert((CONDITION) && #MSG);
121 
122 #endif // EIGEN_NO_STATIC_ASSERT
123 
124 
125 // static assertion failing if the type \a TYPE is not a vector type
126 #define EIGEN_STATIC_ASSERT_VECTOR_ONLY(TYPE) \
127  EIGEN_STATIC_ASSERT(TYPE::IsVectorAtCompileTime, \
128  YOU_TRIED_CALLING_A_VECTOR_METHOD_ON_A_MATRIX)
129 
130 // static assertion failing if the type \a TYPE is not fixed-size
131 #define EIGEN_STATIC_ASSERT_FIXED_SIZE(TYPE) \
132  EIGEN_STATIC_ASSERT(TYPE::SizeAtCompileTime!=Eigen::Dynamic, \
133  YOU_CALLED_A_FIXED_SIZE_METHOD_ON_A_DYNAMIC_SIZE_MATRIX_OR_VECTOR)
134 
135 // static assertion failing if the type \a TYPE is not dynamic-size
136 #define EIGEN_STATIC_ASSERT_DYNAMIC_SIZE(TYPE) \
137  EIGEN_STATIC_ASSERT(TYPE::SizeAtCompileTime==Eigen::Dynamic, \
138  YOU_CALLED_A_DYNAMIC_SIZE_METHOD_ON_A_FIXED_SIZE_MATRIX_OR_VECTOR)
139 
140 // static assertion failing if the type \a TYPE is not a vector type of the given size
141 #define EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(TYPE, SIZE) \
142  EIGEN_STATIC_ASSERT(TYPE::IsVectorAtCompileTime && TYPE::SizeAtCompileTime==SIZE, \
143  THIS_METHOD_IS_ONLY_FOR_VECTORS_OF_A_SPECIFIC_SIZE)
144 
145 // static assertion failing if the type \a TYPE is not a vector type of the given size
146 #define EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(TYPE, ROWS, COLS) \
147  EIGEN_STATIC_ASSERT(TYPE::RowsAtCompileTime==ROWS && TYPE::ColsAtCompileTime==COLS, \
148  THIS_METHOD_IS_ONLY_FOR_MATRICES_OF_A_SPECIFIC_SIZE)
149 
150 // static assertion failing if the two vector expression types are not compatible (same fixed-size or dynamic size)
151 #define EIGEN_STATIC_ASSERT_SAME_VECTOR_SIZE(TYPE0,TYPE1) \
152  EIGEN_STATIC_ASSERT( \
153  (int(TYPE0::SizeAtCompileTime)==Eigen::Dynamic \
154  || int(TYPE1::SizeAtCompileTime)==Eigen::Dynamic \
155  || int(TYPE0::SizeAtCompileTime)==int(TYPE1::SizeAtCompileTime)),\
156  YOU_MIXED_VECTORS_OF_DIFFERENT_SIZES)
157 
158 #define EIGEN_PREDICATE_SAME_MATRIX_SIZE(TYPE0,TYPE1) \
159  ( \
160  (int(TYPE0::SizeAtCompileTime)==0 && int(TYPE1::SizeAtCompileTime)==0) \
161  || (\
162  (int(TYPE0::RowsAtCompileTime)==Eigen::Dynamic \
163  || int(TYPE1::RowsAtCompileTime)==Eigen::Dynamic \
164  || int(TYPE0::RowsAtCompileTime)==int(TYPE1::RowsAtCompileTime)) \
165  && (int(TYPE0::ColsAtCompileTime)==Eigen::Dynamic \
166  || int(TYPE1::ColsAtCompileTime)==Eigen::Dynamic \
167  || int(TYPE0::ColsAtCompileTime)==int(TYPE1::ColsAtCompileTime))\
168  ) \
169  )
170 
171 #ifdef EIGEN2_SUPPORT
172  #define EIGEN_STATIC_ASSERT_NON_INTEGER(TYPE) \
173  eigen_assert(!NumTraits<Scalar>::IsInteger);
174 #else
175  #define EIGEN_STATIC_ASSERT_NON_INTEGER(TYPE) \
176  EIGEN_STATIC_ASSERT(!NumTraits<TYPE>::IsInteger, THIS_FUNCTION_IS_NOT_FOR_INTEGER_NUMERIC_TYPES)
177 #endif
178 
179 
180 // static assertion failing if it is guaranteed at compile-time that the two matrix expression types have different sizes
181 #define EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(TYPE0,TYPE1) \
182  EIGEN_STATIC_ASSERT( \
183  EIGEN_PREDICATE_SAME_MATRIX_SIZE(TYPE0,TYPE1),\
184  YOU_MIXED_MATRICES_OF_DIFFERENT_SIZES)
185 
186 #define EIGEN_STATIC_ASSERT_SIZE_1x1(TYPE) \
187  EIGEN_STATIC_ASSERT((TYPE::RowsAtCompileTime == 1 || TYPE::RowsAtCompileTime == Dynamic) && \
188  (TYPE::ColsAtCompileTime == 1 || TYPE::ColsAtCompileTime == Dynamic), \
189  THIS_METHOD_IS_ONLY_FOR_1x1_EXPRESSIONS)
190 
191 #define EIGEN_STATIC_ASSERT_LVALUE(Derived) \
192  EIGEN_STATIC_ASSERT(internal::is_lvalue<Derived>::value, \
193  THIS_EXPRESSION_IS_NOT_A_LVALUE__IT_IS_READ_ONLY)
194 
195 #define EIGEN_STATIC_ASSERT_ARRAYXPR(Derived) \
196  EIGEN_STATIC_ASSERT((internal::is_same<typename internal::traits<Derived>::XprKind, ArrayXpr>::value), \
197  THIS_METHOD_IS_ONLY_FOR_ARRAYS_NOT_MATRICES)
198 
199 #define EIGEN_STATIC_ASSERT_SAME_XPR_KIND(Derived1, Derived2) \
200  EIGEN_STATIC_ASSERT((internal::is_same<typename internal::traits<Derived1>::XprKind, \
201  typename internal::traits<Derived2>::XprKind \
202  >::value), \
203  YOU_CANNOT_MIX_ARRAYS_AND_MATRICES)
204 
205 
206 #endif // EIGEN_STATIC_ASSERT_H
iterative scaling algorithm to equilibrate rows and column norms in matrices
Definition: matrix.hpp:471


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Mon Jun 10 2019 12:35:11