StaticAssert.h
Go to the documentation of this file.
00001 // This file is part of Eigen, a lightweight C++ template library
00002 // for linear algebra.
00003 //
00004 // Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
00005 // Copyright (C) 2008 Benoit Jacob <jacob.benoit.1@gmail.com>
00006 //
00007 // This Source Code Form is subject to the terms of the Mozilla
00008 // Public License v. 2.0. If a copy of the MPL was not distributed
00009 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
00010 
00011 #ifndef EIGEN_STATIC_ASSERT_H
00012 #define EIGEN_STATIC_ASSERT_H
00013 
00014 /* Some notes on Eigen's static assertion mechanism:
00015  *
00016  *  - in EIGEN_STATIC_ASSERT(CONDITION,MSG) the parameter CONDITION must be a compile time boolean
00017  *    expression, and MSG an enum listed in struct internal::static_assertion<true>
00018  *
00019  *  - define EIGEN_NO_STATIC_ASSERT to disable them (and save compilation time)
00020  *    in that case, the static assertion is converted to the following runtime assert:
00021  *      eigen_assert(CONDITION && "MSG")
00022  *
00023  *  - currently EIGEN_STATIC_ASSERT can only be used in function scope
00024  *
00025  */
00026 
00027 #ifndef EIGEN_NO_STATIC_ASSERT
00028 
00029   #if defined(__GXX_EXPERIMENTAL_CXX0X__) || (defined(_MSC_VER) && (_MSC_VER >= 1600))
00030 
00031     // if native static_assert is enabled, let's use it
00032     #define EIGEN_STATIC_ASSERT(X,MSG) static_assert(X,#MSG);
00033 
00034   #else // not CXX0X
00035 
00036     namespace Eigen {
00037 
00038     namespace internal {
00039 
00040     template<bool condition>
00041     struct static_assertion {};
00042 
00043     template<>
00044     struct static_assertion<true>
00045     {
00046       enum {
00047         YOU_TRIED_CALLING_A_VECTOR_METHOD_ON_A_MATRIX,
00048         YOU_MIXED_VECTORS_OF_DIFFERENT_SIZES,
00049         YOU_MIXED_MATRICES_OF_DIFFERENT_SIZES,
00050         THIS_METHOD_IS_ONLY_FOR_VECTORS_OF_A_SPECIFIC_SIZE,
00051         THIS_METHOD_IS_ONLY_FOR_MATRICES_OF_A_SPECIFIC_SIZE,
00052         THIS_METHOD_IS_ONLY_FOR_OBJECTS_OF_A_SPECIFIC_SIZE,
00053         YOU_MADE_A_PROGRAMMING_MISTAKE,
00054         EIGEN_INTERNAL_ERROR_PLEASE_FILE_A_BUG_REPORT,
00055         EIGEN_INTERNAL_COMPILATION_ERROR_OR_YOU_MADE_A_PROGRAMMING_MISTAKE,
00056         YOU_CALLED_A_FIXED_SIZE_METHOD_ON_A_DYNAMIC_SIZE_MATRIX_OR_VECTOR,
00057         YOU_CALLED_A_DYNAMIC_SIZE_METHOD_ON_A_FIXED_SIZE_MATRIX_OR_VECTOR,
00058         UNALIGNED_LOAD_AND_STORE_OPERATIONS_UNIMPLEMENTED_ON_ALTIVEC,
00059         THIS_FUNCTION_IS_NOT_FOR_INTEGER_NUMERIC_TYPES,
00060         FLOATING_POINT_ARGUMENT_PASSED__INTEGER_WAS_EXPECTED,
00061         NUMERIC_TYPE_MUST_BE_REAL,
00062         COEFFICIENT_WRITE_ACCESS_TO_SELFADJOINT_NOT_SUPPORTED,
00063         WRITING_TO_TRIANGULAR_PART_WITH_UNIT_DIAGONAL_IS_NOT_SUPPORTED,
00064         THIS_METHOD_IS_ONLY_FOR_FIXED_SIZE,
00065         INVALID_MATRIX_PRODUCT,
00066         INVALID_VECTOR_VECTOR_PRODUCT__IF_YOU_WANTED_A_DOT_OR_COEFF_WISE_PRODUCT_YOU_MUST_USE_THE_EXPLICIT_FUNCTIONS,
00067         INVALID_MATRIX_PRODUCT__IF_YOU_WANTED_A_COEFF_WISE_PRODUCT_YOU_MUST_USE_THE_EXPLICIT_FUNCTION,
00068         YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY,
00069         THIS_METHOD_IS_ONLY_FOR_COLUMN_MAJOR_MATRICES,
00070         THIS_METHOD_IS_ONLY_FOR_ROW_MAJOR_MATRICES,
00071         INVALID_MATRIX_TEMPLATE_PARAMETERS,
00072         INVALID_MATRIXBASE_TEMPLATE_PARAMETERS,
00073         BOTH_MATRICES_MUST_HAVE_THE_SAME_STORAGE_ORDER,
00074         THIS_METHOD_IS_ONLY_FOR_DIAGONAL_MATRIX,
00075         THE_MATRIX_OR_EXPRESSION_THAT_YOU_PASSED_DOES_NOT_HAVE_THE_EXPECTED_TYPE,
00076         THIS_METHOD_IS_ONLY_FOR_EXPRESSIONS_WITH_DIRECT_MEMORY_ACCESS_SUCH_AS_MAP_OR_PLAIN_MATRICES,
00077         YOU_ALREADY_SPECIFIED_THIS_STRIDE,
00078         INVALID_STORAGE_ORDER_FOR_THIS_VECTOR_EXPRESSION,
00079         THE_BRACKET_OPERATOR_IS_ONLY_FOR_VECTORS__USE_THE_PARENTHESIS_OPERATOR_INSTEAD,
00080         PACKET_ACCESS_REQUIRES_TO_HAVE_INNER_STRIDE_FIXED_TO_1,
00081         THIS_METHOD_IS_ONLY_FOR_SPECIFIC_TRANSFORMATIONS,
00082         YOU_CANNOT_MIX_ARRAYS_AND_MATRICES,
00083         YOU_PERFORMED_AN_INVALID_TRANSFORMATION_CONVERSION,
00084         THIS_EXPRESSION_IS_NOT_A_LVALUE__IT_IS_READ_ONLY,
00085         YOU_ARE_TRYING_TO_USE_AN_INDEX_BASED_ACCESSOR_ON_AN_EXPRESSION_THAT_DOES_NOT_SUPPORT_THAT,
00086         THIS_METHOD_IS_ONLY_FOR_1x1_EXPRESSIONS,
00087         THIS_METHOD_IS_ONLY_FOR_EXPRESSIONS_OF_BOOL,
00088         THIS_METHOD_IS_ONLY_FOR_ARRAYS_NOT_MATRICES,
00089         YOU_PASSED_A_ROW_VECTOR_BUT_A_COLUMN_VECTOR_WAS_EXPECTED,
00090         YOU_PASSED_A_COLUMN_VECTOR_BUT_A_ROW_VECTOR_WAS_EXPECTED,
00091         THE_INDEX_TYPE_MUST_BE_A_SIGNED_TYPE,
00092         THE_STORAGE_ORDER_OF_BOTH_SIDES_MUST_MATCH,
00093         OBJECT_ALLOCATED_ON_STACK_IS_TOO_BIG
00094       };
00095     };
00096 
00097     } // end namespace internal
00098 
00099     } // end namespace Eigen
00100 
00101     // Specialized implementation for MSVC to avoid "conditional
00102     // expression is constant" warnings.  This implementation doesn't
00103     // appear to work under GCC, hence the multiple implementations.
00104     #ifdef _MSC_VER
00105 
00106       #define EIGEN_STATIC_ASSERT(CONDITION,MSG) \
00107         {Eigen::internal::static_assertion<bool(CONDITION)>::MSG;}
00108 
00109     #else
00110 
00111       #define EIGEN_STATIC_ASSERT(CONDITION,MSG) \
00112         if (Eigen::internal::static_assertion<bool(CONDITION)>::MSG) {}
00113 
00114     #endif
00115 
00116   #endif // not CXX0X
00117 
00118 #else // EIGEN_NO_STATIC_ASSERT
00119 
00120   #define EIGEN_STATIC_ASSERT(CONDITION,MSG) eigen_assert((CONDITION) && #MSG);
00121 
00122 #endif // EIGEN_NO_STATIC_ASSERT
00123 
00124 
00125 // static assertion failing if the type \a TYPE is not a vector type
00126 #define EIGEN_STATIC_ASSERT_VECTOR_ONLY(TYPE) \
00127   EIGEN_STATIC_ASSERT(TYPE::IsVectorAtCompileTime, \
00128                       YOU_TRIED_CALLING_A_VECTOR_METHOD_ON_A_MATRIX)
00129 
00130 // static assertion failing if the type \a TYPE is not fixed-size
00131 #define EIGEN_STATIC_ASSERT_FIXED_SIZE(TYPE) \
00132   EIGEN_STATIC_ASSERT(TYPE::SizeAtCompileTime!=Eigen::Dynamic, \
00133                       YOU_CALLED_A_FIXED_SIZE_METHOD_ON_A_DYNAMIC_SIZE_MATRIX_OR_VECTOR)
00134 
00135 // static assertion failing if the type \a TYPE is not dynamic-size
00136 #define EIGEN_STATIC_ASSERT_DYNAMIC_SIZE(TYPE) \
00137   EIGEN_STATIC_ASSERT(TYPE::SizeAtCompileTime==Eigen::Dynamic, \
00138                       YOU_CALLED_A_DYNAMIC_SIZE_METHOD_ON_A_FIXED_SIZE_MATRIX_OR_VECTOR)
00139 
00140 // static assertion failing if the type \a TYPE is not a vector type of the given size
00141 #define EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(TYPE, SIZE) \
00142   EIGEN_STATIC_ASSERT(TYPE::IsVectorAtCompileTime && TYPE::SizeAtCompileTime==SIZE, \
00143                       THIS_METHOD_IS_ONLY_FOR_VECTORS_OF_A_SPECIFIC_SIZE)
00144 
00145 // static assertion failing if the type \a TYPE is not a vector type of the given size
00146 #define EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(TYPE, ROWS, COLS) \
00147   EIGEN_STATIC_ASSERT(TYPE::RowsAtCompileTime==ROWS && TYPE::ColsAtCompileTime==COLS, \
00148                       THIS_METHOD_IS_ONLY_FOR_MATRICES_OF_A_SPECIFIC_SIZE)
00149 
00150 // static assertion failing if the two vector expression types are not compatible (same fixed-size or dynamic size)
00151 #define EIGEN_STATIC_ASSERT_SAME_VECTOR_SIZE(TYPE0,TYPE1) \
00152   EIGEN_STATIC_ASSERT( \
00153       (int(TYPE0::SizeAtCompileTime)==Eigen::Dynamic \
00154     || int(TYPE1::SizeAtCompileTime)==Eigen::Dynamic \
00155     || int(TYPE0::SizeAtCompileTime)==int(TYPE1::SizeAtCompileTime)),\
00156     YOU_MIXED_VECTORS_OF_DIFFERENT_SIZES)
00157 
00158 #define EIGEN_PREDICATE_SAME_MATRIX_SIZE(TYPE0,TYPE1) \
00159      ( \
00160         (int(TYPE0::SizeAtCompileTime)==0 && int(TYPE1::SizeAtCompileTime)==0) \
00161     || (\
00162           (int(TYPE0::RowsAtCompileTime)==Eigen::Dynamic \
00163         || int(TYPE1::RowsAtCompileTime)==Eigen::Dynamic \
00164         || int(TYPE0::RowsAtCompileTime)==int(TYPE1::RowsAtCompileTime)) \
00165       &&  (int(TYPE0::ColsAtCompileTime)==Eigen::Dynamic \
00166         || int(TYPE1::ColsAtCompileTime)==Eigen::Dynamic \
00167         || int(TYPE0::ColsAtCompileTime)==int(TYPE1::ColsAtCompileTime))\
00168        ) \
00169      )
00170 
00171 #ifdef EIGEN2_SUPPORT
00172   #define EIGEN_STATIC_ASSERT_NON_INTEGER(TYPE) \
00173     eigen_assert(!NumTraits<Scalar>::IsInteger);
00174 #else
00175   #define EIGEN_STATIC_ASSERT_NON_INTEGER(TYPE) \
00176     EIGEN_STATIC_ASSERT(!NumTraits<TYPE>::IsInteger, THIS_FUNCTION_IS_NOT_FOR_INTEGER_NUMERIC_TYPES)
00177 #endif
00178 
00179 
00180 // static assertion failing if it is guaranteed at compile-time that the two matrix expression types have different sizes
00181 #define EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(TYPE0,TYPE1) \
00182   EIGEN_STATIC_ASSERT( \
00183      EIGEN_PREDICATE_SAME_MATRIX_SIZE(TYPE0,TYPE1),\
00184     YOU_MIXED_MATRICES_OF_DIFFERENT_SIZES)
00185 
00186 #define EIGEN_STATIC_ASSERT_SIZE_1x1(TYPE) \
00187       EIGEN_STATIC_ASSERT((TYPE::RowsAtCompileTime == 1 || TYPE::RowsAtCompileTime == Dynamic) && \
00188                           (TYPE::ColsAtCompileTime == 1 || TYPE::ColsAtCompileTime == Dynamic), \
00189                           THIS_METHOD_IS_ONLY_FOR_1x1_EXPRESSIONS)
00190 
00191 #define EIGEN_STATIC_ASSERT_LVALUE(Derived) \
00192       EIGEN_STATIC_ASSERT(internal::is_lvalue<Derived>::value, \
00193                           THIS_EXPRESSION_IS_NOT_A_LVALUE__IT_IS_READ_ONLY)
00194 
00195 #define EIGEN_STATIC_ASSERT_ARRAYXPR(Derived) \
00196       EIGEN_STATIC_ASSERT((internal::is_same<typename internal::traits<Derived>::XprKind, ArrayXpr>::value), \
00197                           THIS_METHOD_IS_ONLY_FOR_ARRAYS_NOT_MATRICES)
00198 
00199 #define EIGEN_STATIC_ASSERT_SAME_XPR_KIND(Derived1, Derived2) \
00200       EIGEN_STATIC_ASSERT((internal::is_same<typename internal::traits<Derived1>::XprKind, \
00201                                              typename internal::traits<Derived2>::XprKind \
00202                                             >::value), \
00203                           YOU_CANNOT_MIX_ARRAYS_AND_MATRICES)
00204 
00205 
00206 #endif // EIGEN_STATIC_ASSERT_H


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Thu Aug 27 2015 12:00:57