mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-08-12 03:39:01 +08:00
Add support for std::integral_constant
This commit is contained in:
parent
bc10201854
commit
d83db761a2
@ -202,22 +202,28 @@ auto seq(FirstType f, LastType l);
|
|||||||
|
|
||||||
#if EIGEN_HAS_CXX11
|
#if EIGEN_HAS_CXX11
|
||||||
template<typename FirstType,typename LastType>
|
template<typename FirstType,typename LastType>
|
||||||
auto seq(FirstType f, LastType l) -> decltype(seqN(f,( typename internal::cleanup_index_type<LastType>::type(l)
|
auto seq(FirstType f, LastType l) -> decltype(seqN(typename internal::cleanup_index_type<FirstType>::type(f),
|
||||||
- typename internal::cleanup_index_type<FirstType>::type(f)+fix<1>())))
|
( typename internal::cleanup_index_type<LastType>::type(l)
|
||||||
|
- typename internal::cleanup_index_type<FirstType>::type(f)+fix<1>())))
|
||||||
{
|
{
|
||||||
return seqN(f,(typename internal::cleanup_index_type<LastType>::type(l)
|
return seqN(typename internal::cleanup_index_type<FirstType>::type(f),
|
||||||
-typename internal::cleanup_index_type<FirstType>::type(f)+fix<1>()));
|
(typename internal::cleanup_index_type<LastType>::type(l)
|
||||||
|
-typename internal::cleanup_index_type<FirstType>::type(f)+fix<1>()));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename FirstType,typename LastType, typename IncrType>
|
template<typename FirstType,typename LastType, typename IncrType>
|
||||||
auto seq(FirstType f, LastType l, IncrType incr)
|
auto seq(FirstType f, LastType l, IncrType incr)
|
||||||
-> decltype(seqN(f, ( typename internal::cleanup_index_type<LastType>::type(l)
|
-> decltype(seqN(typename internal::cleanup_index_type<FirstType>::type(f),
|
||||||
- typename internal::cleanup_index_type<FirstType>::type(f)+typename internal::cleanup_seq_incr<IncrType>::type(incr))
|
( typename internal::cleanup_index_type<LastType>::type(l)
|
||||||
/ typename internal::cleanup_seq_incr<IncrType>::type(incr),typename internal::cleanup_seq_incr<IncrType>::type(incr)))
|
- typename internal::cleanup_index_type<FirstType>::type(f)+typename internal::cleanup_seq_incr<IncrType>::type(incr)
|
||||||
|
) / typename internal::cleanup_seq_incr<IncrType>::type(incr),
|
||||||
|
typename internal::cleanup_seq_incr<IncrType>::type(incr)))
|
||||||
{
|
{
|
||||||
typedef typename internal::cleanup_seq_incr<IncrType>::type CleanedIncrType;
|
typedef typename internal::cleanup_seq_incr<IncrType>::type CleanedIncrType;
|
||||||
return seqN(f,(typename internal::cleanup_index_type<LastType>::type(l)
|
return seqN(typename internal::cleanup_index_type<FirstType>::type(f),
|
||||||
-typename internal::cleanup_index_type<FirstType>::type(f)+CleanedIncrType(incr)) / CleanedIncrType(incr),CleanedIncrType(incr));
|
( typename internal::cleanup_index_type<LastType>::type(l)
|
||||||
|
-typename internal::cleanup_index_type<FirstType>::type(f)+CleanedIncrType(incr)) / CleanedIncrType(incr),
|
||||||
|
CleanedIncrType(incr));
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
|
||||||
|
@ -83,6 +83,10 @@ public:
|
|||||||
#else
|
#else
|
||||||
FixedInt ( FixedInt<N> (*)() ) {}
|
FixedInt ( FixedInt<N> (*)() ) {}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if EIGEN_HAS_CXX11
|
||||||
|
FixedInt(std::integral_constant<int,N>) {}
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
/** \internal
|
/** \internal
|
||||||
@ -170,6 +174,10 @@ template<int N, int DynamicKey> struct cleanup_index_type<VariableAndFixedInt<N>
|
|||||||
// If VariableAndFixedInt matches DynamicKey, then we turn it to a pure runtime-value (aka Index):
|
// If VariableAndFixedInt matches DynamicKey, then we turn it to a pure runtime-value (aka Index):
|
||||||
template<int DynamicKey> struct cleanup_index_type<VariableAndFixedInt<DynamicKey>, DynamicKey> { typedef Index type; };
|
template<int DynamicKey> struct cleanup_index_type<VariableAndFixedInt<DynamicKey>, DynamicKey> { typedef Index type; };
|
||||||
|
|
||||||
|
#if EIGEN_HAS_CXX11
|
||||||
|
template<int N, int DynamicKey> struct cleanup_index_type<std::integral_constant<int,N>, DynamicKey> { typedef FixedInt<N> type; };
|
||||||
|
#endif
|
||||||
|
|
||||||
} // end namespace internal
|
} // end namespace internal
|
||||||
|
|
||||||
#ifndef EIGEN_PARSED_BY_DOXYGEN
|
#ifndef EIGEN_PARSED_BY_DOXYGEN
|
||||||
|
@ -204,6 +204,15 @@ void check_indexed_view()
|
|||||||
VERIFY( is_same_seq_type( seq(2,fix<5>), seqN(2,4) ) );
|
VERIFY( is_same_seq_type( seq(2,fix<5>), seqN(2,4) ) );
|
||||||
#if EIGEN_HAS_CXX11
|
#if EIGEN_HAS_CXX11
|
||||||
VERIFY( is_same_seq_type( seq(fix<2>,fix<5>), seqN(fix<2>,fix<4>) ) );
|
VERIFY( is_same_seq_type( seq(fix<2>,fix<5>), seqN(fix<2>,fix<4>) ) );
|
||||||
|
VERIFY( is_same_seq( seqN(2,std::integral_constant<int,5>(),std::integral_constant<int,-2>()), seqN(2,fix<5>,fix<-2>()) ) );
|
||||||
|
VERIFY( is_same_seq( seq(std::integral_constant<int,1>(),std::integral_constant<int,5>(),std::integral_constant<int,2>()),
|
||||||
|
seq(fix<1>,fix<5>,fix<2>()) ) );
|
||||||
|
VERIFY( is_same_seq_type( seqN(2,std::integral_constant<int,5>(),std::integral_constant<int,-2>()), seqN(2,fix<5>,fix<-2>()) ) );
|
||||||
|
VERIFY( is_same_seq_type( seq(std::integral_constant<int,1>(),std::integral_constant<int,5>(),std::integral_constant<int,2>()),
|
||||||
|
seq(fix<1>,fix<5>,fix<2>()) ) );
|
||||||
|
|
||||||
|
VERIFY( is_same_seq_type( seqN(2,std::integral_constant<int,5>()), seqN(2,fix<5>) ) );
|
||||||
|
VERIFY( is_same_seq_type( seq(std::integral_constant<int,1>(),std::integral_constant<int,5>()), seq(fix<1>,fix<5>) ) );
|
||||||
#else
|
#else
|
||||||
// sorry, no compile-time size recovery in c++98/03
|
// sorry, no compile-time size recovery in c++98/03
|
||||||
VERIFY( is_same_seq( seq(fix<2>,fix<5>), seqN(fix<2>,fix<4>) ) );
|
VERIFY( is_same_seq( seq(fix<2>,fix<5>), seqN(fix<2>,fix<4>) ) );
|
||||||
|
Loading…
x
Reference in New Issue
Block a user