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       };
00094     };
00095 
00096     } // end namespace internal
00097 
00098     } // end namespace Eigen
00099 
00100     // Specialized implementation for MSVC to avoid "conditional
00101     // expression is constant" warnings.  This implementation doesn't
00102     // appear to work under GCC, hence the multiple implementations.
00103     #ifdef _MSC_VER
00104 
00105       #define EIGEN_STATIC_ASSERT(CONDITION,MSG) \
00106         {Eigen::internal::static_assertion<bool(CONDITION)>::MSG;}
00107 
00108     #else
00109 
00110       #define EIGEN_STATIC_ASSERT(CONDITION,MSG) \
00111         if (Eigen::internal::static_assertion<bool(CONDITION)>::MSG) {}
00112 
00113     #endif
00114 
00115   #endif // not CXX0X
00116 
00117 #else // EIGEN_NO_STATIC_ASSERT
00118 
00119   #define EIGEN_STATIC_ASSERT(CONDITION,MSG) eigen_assert((CONDITION) && #MSG);
00120 
00121 #endif // EIGEN_NO_STATIC_ASSERT
00122 
00123 
00124 // static assertion failing if the type \a TYPE is not a vector type
00125 #define EIGEN_STATIC_ASSERT_VECTOR_ONLY(TYPE) \
00126   EIGEN_STATIC_ASSERT(TYPE::IsVectorAtCompileTime, \
00127                       YOU_TRIED_CALLING_A_VECTOR_METHOD_ON_A_MATRIX)
00128 
00129 // static assertion failing if the type \a TYPE is not fixed-size
00130 #define EIGEN_STATIC_ASSERT_FIXED_SIZE(TYPE) \
00131   EIGEN_STATIC_ASSERT(TYPE::SizeAtCompileTime!=Eigen::Dynamic, \
00132                       YOU_CALLED_A_FIXED_SIZE_METHOD_ON_A_DYNAMIC_SIZE_MATRIX_OR_VECTOR)
00133 
00134 // static assertion failing if the type \a TYPE is not dynamic-size
00135 #define EIGEN_STATIC_ASSERT_DYNAMIC_SIZE(TYPE) \
00136   EIGEN_STATIC_ASSERT(TYPE::SizeAtCompileTime==Eigen::Dynamic, \
00137                       YOU_CALLED_A_DYNAMIC_SIZE_METHOD_ON_A_FIXED_SIZE_MATRIX_OR_VECTOR)
00138 
00139 // static assertion failing if the type \a TYPE is not a vector type of the given size
00140 #define EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(TYPE, SIZE) \
00141   EIGEN_STATIC_ASSERT(TYPE::IsVectorAtCompileTime && TYPE::SizeAtCompileTime==SIZE, \
00142                       THIS_METHOD_IS_ONLY_FOR_VECTORS_OF_A_SPECIFIC_SIZE)
00143 
00144 // static assertion failing if the type \a TYPE is not a vector type of the given size
00145 #define EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(TYPE, ROWS, COLS) \
00146   EIGEN_STATIC_ASSERT(TYPE::RowsAtCompileTime==ROWS && TYPE::ColsAtCompileTime==COLS, \
00147                       THIS_METHOD_IS_ONLY_FOR_MATRICES_OF_A_SPECIFIC_SIZE)
00148 
00149 // static assertion failing if the two vector expression types are not compatible (same fixed-size or dynamic size)
00150 #define EIGEN_STATIC_ASSERT_SAME_VECTOR_SIZE(TYPE0,TYPE1) \
00151   EIGEN_STATIC_ASSERT( \
00152       (int(TYPE0::SizeAtCompileTime)==Eigen::Dynamic \
00153     || int(TYPE1::SizeAtCompileTime)==Eigen::Dynamic \
00154     || int(TYPE0::SizeAtCompileTime)==int(TYPE1::SizeAtCompileTime)),\
00155     YOU_MIXED_VECTORS_OF_DIFFERENT_SIZES)
00156 
00157 #define EIGEN_PREDICATE_SAME_MATRIX_SIZE(TYPE0,TYPE1) \
00158      ( \
00159         (int(TYPE0::SizeAtCompileTime)==0 && int(TYPE1::SizeAtCompileTime)==0) \
00160     || (\
00161           (int(TYPE0::RowsAtCompileTime)==Eigen::Dynamic \
00162         || int(TYPE1::RowsAtCompileTime)==Eigen::Dynamic \
00163         || int(TYPE0::RowsAtCompileTime)==int(TYPE1::RowsAtCompileTime)) \
00164       &&  (int(TYPE0::ColsAtCompileTime)==Eigen::Dynamic \
00165         || int(TYPE1::ColsAtCompileTime)==Eigen::Dynamic \
00166         || int(TYPE0::ColsAtCompileTime)==int(TYPE1::ColsAtCompileTime))\
00167        ) \
00168      )
00169 
00170 #ifdef EIGEN2_SUPPORT
00171   #define EIGEN_STATIC_ASSERT_NON_INTEGER(TYPE) \
00172     eigen_assert(!NumTraits<Scalar>::IsInteger);
00173 #else
00174   #define EIGEN_STATIC_ASSERT_NON_INTEGER(TYPE) \
00175     EIGEN_STATIC_ASSERT(!NumTraits<TYPE>::IsInteger, THIS_FUNCTION_IS_NOT_FOR_INTEGER_NUMERIC_TYPES)
00176 #endif
00177 
00178 
00179 // static assertion failing if it is guaranteed at compile-time that the two matrix expression types have different sizes
00180 #define EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(TYPE0,TYPE1) \
00181   EIGEN_STATIC_ASSERT( \
00182      EIGEN_PREDICATE_SAME_MATRIX_SIZE(TYPE0,TYPE1),\
00183     YOU_MIXED_MATRICES_OF_DIFFERENT_SIZES)
00184 
00185 #define EIGEN_STATIC_ASSERT_SIZE_1x1(TYPE) \
00186       EIGEN_STATIC_ASSERT((TYPE::RowsAtCompileTime == 1 || TYPE::RowsAtCompileTime == Dynamic) && \
00187                           (TYPE::ColsAtCompileTime == 1 || TYPE::ColsAtCompileTime == Dynamic), \
00188                           THIS_METHOD_IS_ONLY_FOR_1x1_EXPRESSIONS)
00189 
00190 #define EIGEN_STATIC_ASSERT_LVALUE(Derived) \
00191       EIGEN_STATIC_ASSERT(internal::is_lvalue<Derived>::value, \
00192                           THIS_EXPRESSION_IS_NOT_A_LVALUE__IT_IS_READ_ONLY)
00193 
00194 #define EIGEN_STATIC_ASSERT_ARRAYXPR(Derived) \
00195       EIGEN_STATIC_ASSERT((internal::is_same<typename internal::traits<Derived>::XprKind, ArrayXpr>::value), \
00196                           THIS_METHOD_IS_ONLY_FOR_ARRAYS_NOT_MATRICES)
00197 
00198 #define EIGEN_STATIC_ASSERT_SAME_XPR_KIND(Derived1, Derived2) \
00199       EIGEN_STATIC_ASSERT((internal::is_same<typename internal::traits<Derived1>::XprKind, \
00200                                              typename internal::traits<Derived2>::XprKind \
00201                                             >::value), \
00202                           YOU_CANNOT_MIX_ARRAYS_AND_MATRICES)
00203 
00204 
00205 #endif // EIGEN_STATIC_ASSERT_H


win_eigen
Author(s): Daniel Stonier
autogenerated on Wed Sep 16 2015 07:12:14