Cycles: svn merge -r41225:41232 ^/trunk/blender
[blender.git] / extern / Eigen2 / Eigen / src / Core / util / StaticAssert.h
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra. Eigen itself is part of the KDE project.
3 //
4 // Copyright (C) 2008 Gael Guennebaud <g.gael@free.fr>
5 // Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
6 //
7 // Eigen is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU Lesser General Public
9 // License as published by the Free Software Foundation; either
10 // version 3 of the License, or (at your option) any later version.
11 //
12 // Alternatively, you can redistribute it and/or
13 // modify it under the terms of the GNU General Public License as
14 // published by the Free Software Foundation; either version 2 of
15 // the License, or (at your option) any later version.
16 //
17 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
18 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
20 // GNU General Public License for more details.
21 //
22 // You should have received a copy of the GNU Lesser General Public
23 // License and a copy of the GNU General Public License along with
24 // Eigen. If not, see <http://www.gnu.org/licenses/>.
25
26 #ifndef EIGEN_STATIC_ASSERT_H
27 #define EIGEN_STATIC_ASSERT_H
28
29 /* Some notes on Eigen's static assertion mechanism:
30  *
31  *  - in EIGEN_STATIC_ASSERT(CONDITION,MSG) the parameter CONDITION must be a compile time boolean
32  *    expression, and MSG an enum listed in struct ei_static_assert<true>
33  *
34  *  - define EIGEN_NO_STATIC_ASSERT to disable them (and save compilation time)
35  *    in that case, the static assertion is converted to the following runtime assert:
36  *      ei_assert(CONDITION && "MSG")
37  *
38  *  - currently EIGEN_STATIC_ASSERT can only be used in function scope
39  *
40  */
41
42 #ifndef EIGEN_NO_STATIC_ASSERT
43
44   #ifdef __GXX_EXPERIMENTAL_CXX0X__
45
46     // if native static_assert is enabled, let's use it
47     #define EIGEN_STATIC_ASSERT(X,MSG) static_assert(X,#MSG);
48
49   #else // CXX0X
50
51     template<bool condition>
52     struct ei_static_assert {};
53
54     template<>
55     struct ei_static_assert<true>
56     {
57       enum {
58         YOU_TRIED_CALLING_A_VECTOR_METHOD_ON_A_MATRIX,
59         YOU_MIXED_VECTORS_OF_DIFFERENT_SIZES,
60         YOU_MIXED_MATRICES_OF_DIFFERENT_SIZES,
61         THIS_METHOD_IS_ONLY_FOR_VECTORS_OF_A_SPECIFIC_SIZE,
62         THIS_METHOD_IS_ONLY_FOR_MATRICES_OF_A_SPECIFIC_SIZE,
63         YOU_MADE_A_PROGRAMMING_MISTAKE,
64         YOU_CALLED_A_FIXED_SIZE_METHOD_ON_A_DYNAMIC_SIZE_MATRIX_OR_VECTOR,
65         UNALIGNED_LOAD_AND_STORE_OPERATIONS_UNIMPLEMENTED_ON_ALTIVEC,
66         NUMERIC_TYPE_MUST_BE_FLOATING_POINT,
67         COEFFICIENT_WRITE_ACCESS_TO_SELFADJOINT_NOT_SUPPORTED,
68         WRITING_TO_TRIANGULAR_PART_WITH_UNIT_DIAGONAL_IS_NOT_SUPPORTED,
69         THIS_METHOD_IS_ONLY_FOR_FIXED_SIZE,
70         INVALID_MATRIX_PRODUCT,
71         INVALID_VECTOR_VECTOR_PRODUCT__IF_YOU_WANTED_A_DOT_OR_COEFF_WISE_PRODUCT_YOU_MUST_USE_THE_EXPLICIT_FUNCTIONS,
72         INVALID_MATRIX_PRODUCT__IF_YOU_WANTED_A_COEFF_WISE_PRODUCT_YOU_MUST_USE_THE_EXPLICIT_FUNCTION,
73         YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY,
74         THIS_METHOD_IS_ONLY_FOR_COLUMN_MAJOR_MATRICES,
75         THIS_METHOD_IS_ONLY_FOR_ROW_MAJOR_MATRICES,
76         INVALID_MATRIX_TEMPLATE_PARAMETERS,
77         BOTH_MATRICES_MUST_HAVE_THE_SAME_STORAGE_ORDER,
78         THIS_METHOD_IS_ONLY_FOR_DIAGONAL_MATRIX
79       };
80     };
81
82     // Specialized implementation for MSVC to avoid "conditional
83     // expression is constant" warnings.  This implementation doesn't
84     // appear to work under GCC, hence the multiple implementations.
85     #ifdef _MSC_VER
86
87       #define EIGEN_STATIC_ASSERT(CONDITION,MSG) \
88         {Eigen::ei_static_assert<CONDITION ? true : false>::MSG;}
89
90     #else
91
92       #define EIGEN_STATIC_ASSERT(CONDITION,MSG) \
93         if (Eigen::ei_static_assert<CONDITION ? true : false>::MSG) {}
94
95     #endif
96
97   #endif // not CXX0X
98
99 #else // EIGEN_NO_STATIC_ASSERT
100
101   #define EIGEN_STATIC_ASSERT(CONDITION,MSG) ei_assert((CONDITION) && #MSG);
102
103 #endif // EIGEN_NO_STATIC_ASSERT
104
105
106 // static assertion failing if the type \a TYPE is not a vector type
107 #define EIGEN_STATIC_ASSERT_VECTOR_ONLY(TYPE) \
108   EIGEN_STATIC_ASSERT(TYPE::IsVectorAtCompileTime, \
109                       YOU_TRIED_CALLING_A_VECTOR_METHOD_ON_A_MATRIX)
110
111 // static assertion failing if the type \a TYPE is not fixed-size
112 #define EIGEN_STATIC_ASSERT_FIXED_SIZE(TYPE) \
113   EIGEN_STATIC_ASSERT(TYPE::SizeAtCompileTime!=Eigen::Dynamic, \
114                       YOU_CALLED_A_FIXED_SIZE_METHOD_ON_A_DYNAMIC_SIZE_MATRIX_OR_VECTOR)
115
116 // static assertion failing if the type \a TYPE is not a vector type of the given size
117 #define EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(TYPE, SIZE) \
118   EIGEN_STATIC_ASSERT(TYPE::IsVectorAtCompileTime && TYPE::SizeAtCompileTime==SIZE, \
119                       THIS_METHOD_IS_ONLY_FOR_VECTORS_OF_A_SPECIFIC_SIZE)
120
121 // static assertion failing if the type \a TYPE is not a vector type of the given size
122 #define EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(TYPE, ROWS, COLS) \
123   EIGEN_STATIC_ASSERT(TYPE::RowsAtCompileTime==ROWS && TYPE::ColsAtCompileTime==COLS, \
124                       THIS_METHOD_IS_ONLY_FOR_MATRICES_OF_A_SPECIFIC_SIZE)
125
126 // static assertion failing if the two vector expression types are not compatible (same fixed-size or dynamic size)
127 #define EIGEN_STATIC_ASSERT_SAME_VECTOR_SIZE(TYPE0,TYPE1) \
128   EIGEN_STATIC_ASSERT( \
129       (int(TYPE0::SizeAtCompileTime)==Eigen::Dynamic \
130     || int(TYPE1::SizeAtCompileTime)==Eigen::Dynamic \
131     || int(TYPE0::SizeAtCompileTime)==int(TYPE1::SizeAtCompileTime)),\
132     YOU_MIXED_VECTORS_OF_DIFFERENT_SIZES)
133
134 #define EIGEN_PREDICATE_SAME_MATRIX_SIZE(TYPE0,TYPE1) \
135       ((int(TYPE0::RowsAtCompileTime)==Eigen::Dynamic \
136     || int(TYPE1::RowsAtCompileTime)==Eigen::Dynamic \
137     || int(TYPE0::RowsAtCompileTime)==int(TYPE1::RowsAtCompileTime)) \
138    && (int(TYPE0::ColsAtCompileTime)==Eigen::Dynamic \
139     || int(TYPE1::ColsAtCompileTime)==Eigen::Dynamic \
140     || int(TYPE0::ColsAtCompileTime)==int(TYPE1::ColsAtCompileTime)))
141
142 // static assertion failing if it is guaranteed at compile-time that the two matrix expression types have different sizes
143 #define EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(TYPE0,TYPE1) \
144   EIGEN_STATIC_ASSERT( \
145      EIGEN_PREDICATE_SAME_MATRIX_SIZE(TYPE0,TYPE1),\
146     YOU_MIXED_MATRICES_OF_DIFFERENT_SIZES)
147
148 #endif // EIGEN_STATIC_ASSERT_H