11 #ifndef EIGEN_INTEGRAL_CONSTANT_H
12 #define EIGEN_INTEGRAL_CONSTANT_H
18 template<
int N>
class FixedInt;
19 template<
int N>
class VariableAndFixedInt;
51 template<
int N>
class FixedInt
54 static const int value = N;
55 EIGEN_CONSTEXPR
operator int()
const {
return value; }
57 FixedInt( VariableAndFixedInt<N> other) {
58 #ifndef EIGEN_INTERNAL_DEBUGGING
59 EIGEN_UNUSED_VARIABLE(other);
61 eigen_internal_assert(
int(other)==N);
64 FixedInt<-N> operator-()
const {
return FixedInt<-N>(); }
66 FixedInt<N+M> operator+( FixedInt<M>)
const {
return FixedInt<N+M>(); }
68 FixedInt<N-M> operator-( FixedInt<M>)
const {
return FixedInt<N-M>(); }
70 FixedInt<N*M>
operator*( FixedInt<M>)
const {
return FixedInt<N*M>(); }
72 FixedInt<N/M> operator/( FixedInt<M>)
const {
return FixedInt<N/M>(); }
74 FixedInt<N%M> operator%( FixedInt<M>)
const {
return FixedInt<N%M>(); }
76 FixedInt<N|M> operator|( FixedInt<M>)
const {
return FixedInt<N|M>(); }
78 FixedInt<N&M> operator&( FixedInt<M>)
const {
return FixedInt<N&M>(); }
80 #if EIGEN_HAS_CXX14_VARIABLE_TEMPLATES
82 FixedInt operator() ()
const {
return *
this; }
84 VariableAndFixedInt<N> operator() (
int val)
const {
return VariableAndFixedInt<N>(val); }
86 FixedInt ( FixedInt<N> (*)() ) {}
90 FixedInt(std::integral_constant<int,N>) {}
123 template<
int N>
class VariableAndFixedInt
126 static const int value = N;
127 operator int()
const {
return m_value; }
128 VariableAndFixedInt(
int val) { m_value = val; }
133 template<
typename T,
int Default=Dynamic>
struct get_fixed_value {
134 static const int value = Default;
137 template<
int N,
int Default>
struct get_fixed_value<FixedInt<N>,Default> {
138 static const int value = N;
142 template<
int N,
int Default>
struct get_fixed_value<FixedInt<N> (*)(),Default> {
143 static const int value = N;
147 template<
int N,
int Default>
struct get_fixed_value<VariableAndFixedInt<N>,Default> {
148 static const int value = N ;
151 template<
typename T,
int N,
int Default>
152 struct get_fixed_value<variable_if_dynamic<T,N>,Default> {
153 static const int value = N;
156 template<
typename T> EIGEN_DEVICE_FUNC
Index get_runtime_value(
const T &x) {
return x; }
158 template<
int N> EIGEN_DEVICE_FUNC
Index get_runtime_value(FixedInt<N> (*)()) {
return N; }
164 template<
typename T,
int DynamicKey=Dynamic,
typename EnableIf=
void>
struct cleanup_index_type {
typedef T type; };
167 template<
typename T,
int DynamicKey>
struct cleanup_index_type<T,DynamicKey,typename internal::enable_if<internal::is_integral<T>::value>::type> {
typedef Index type; };
171 template<
int N,
int DynamicKey>
struct cleanup_index_type<FixedInt<N> (*)(), DynamicKey> {
typedef FixedInt<N> type; };
175 template<
int N,
int DynamicKey>
struct cleanup_index_type<VariableAndFixedInt<N>, DynamicKey> {
typedef FixedInt<N> type; };
177 template<
int DynamicKey>
struct cleanup_index_type<VariableAndFixedInt<DynamicKey>, DynamicKey> {
typedef Index type; };
180 template<
int N,
int DynamicKey>
struct cleanup_index_type<std::integral_constant<int,N>, DynamicKey> {
typedef FixedInt<N> type; };
185 #ifndef EIGEN_PARSED_BY_DOXYGEN
187 #if EIGEN_HAS_CXX14_VARIABLE_TEMPLATES
189 static const internal::FixedInt<N>
fix{};
192 inline internal::FixedInt<N>
fix() {
return internal::FixedInt<N>(); }
196 template<
int N,
typename T>
197 inline internal::VariableAndFixedInt<N>
fix(T val) {
return internal::VariableAndFixedInt<N>(internal::convert_index<int>(val)); }
200 #else // EIGEN_PARSED_BY_DOXYGEN
235 static const auto fix();
266 static const auto fix(
int val);
268 #endif // EIGEN_PARSED_BY_DOXYGEN
272 #endif // EIGEN_INTEGRAL_CONSTANT_H