mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-08-12 11:49:02 +08:00
variadic version of assert which can take a parameter pack as its input.
This commit is contained in:
parent
edf46bd7a2
commit
3a197a60e6
@ -1076,4 +1076,28 @@ namespace Eigen {
|
|||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef EIGEN_HAS_VARIADIC_TEMPLATES
|
||||||
|
// Provide a variadic version of assert which can take a parameter pack as its input
|
||||||
|
// The eigen_assert macro used here might have been redefined to use other macros such as EIGEN_THROW, such as used in Eigen's test suite, therefore this needs to be defined after the other macros.
|
||||||
|
// Note that this does not provide as nice a string to assert as a straight forward call to eigen_assert, so we add a message to the assert.
|
||||||
|
#if defined(EIGEN_NO_DEBUG)
|
||||||
|
#define eigen_variadic_assert(x)
|
||||||
|
#else
|
||||||
|
namespace Eigen {
|
||||||
|
namespace internal {
|
||||||
|
inline void variadic_assert(const char*) {}
|
||||||
|
template<typename... Bools> inline void variadic_assert(const char* message, bool first, Bools ... others) {
|
||||||
|
eigen_assert(first && message);
|
||||||
|
variadic_assert(message, others...);
|
||||||
|
EIGEN_UNUSED_VARIABLE(first);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#define EIGEN_VARIADIC_ASSERT_MESSAGE(x) EIGEN_MAKESTRING(x) " in " __FILE__ ":" EIGEN_MAKESTRING(__LINE__)
|
||||||
|
#define eigen_variadic_assert(x) \
|
||||||
|
do { Eigen::internal::variadic_assert(EIGEN_VARIADIC_ASSERT_MESSAGE(x), x); } while(false);
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#endif // EIGEN_MACROS_H
|
#endif // EIGEN_MACROS_H
|
||||||
|
@ -150,6 +150,7 @@ template<typename PlainObjectType, int Options_, template <class> class MakePoin
|
|||||||
EIGEN_STRONG_INLINE const Scalar& operator()(Index firstIndex, Index secondIndex, IndexTypes... otherIndices) const
|
EIGEN_STRONG_INLINE const Scalar& operator()(Index firstIndex, Index secondIndex, IndexTypes... otherIndices) const
|
||||||
{
|
{
|
||||||
EIGEN_STATIC_ASSERT(sizeof...(otherIndices) + 2 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE)
|
EIGEN_STATIC_ASSERT(sizeof...(otherIndices) + 2 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE)
|
||||||
|
eigen_variadic_assert((Eigen::NumTraits<Index>::highest() >= otherIndices)...);
|
||||||
if (PlainObjectType::Options&RowMajor) {
|
if (PlainObjectType::Options&RowMajor) {
|
||||||
const Index index = m_dimensions.IndexOfRowMajor(array<Index, NumIndices>{{firstIndex, secondIndex, otherIndices...}});
|
const Index index = m_dimensions.IndexOfRowMajor(array<Index, NumIndices>{{firstIndex, secondIndex, otherIndices...}});
|
||||||
return m_data[index];
|
return m_data[index];
|
||||||
@ -237,6 +238,7 @@ template<typename PlainObjectType, int Options_, template <class> class MakePoin
|
|||||||
EIGEN_STRONG_INLINE Scalar& operator()(Index firstIndex, Index secondIndex, IndexTypes... otherIndices)
|
EIGEN_STRONG_INLINE Scalar& operator()(Index firstIndex, Index secondIndex, IndexTypes... otherIndices)
|
||||||
{
|
{
|
||||||
static_assert(sizeof...(otherIndices) + 2 == NumIndices || NumIndices == Dynamic, "Number of indices used to access a tensor coefficient must be equal to the rank of the tensor.");
|
static_assert(sizeof...(otherIndices) + 2 == NumIndices || NumIndices == Dynamic, "Number of indices used to access a tensor coefficient must be equal to the rank of the tensor.");
|
||||||
|
eigen_variadic_assert((Eigen::NumTraits<Index>::highest() >= otherIndices)...);
|
||||||
const std::size_t NumDims = sizeof...(otherIndices) + 2;
|
const std::size_t NumDims = sizeof...(otherIndices) + 2;
|
||||||
if (PlainObjectType::Options&RowMajor) {
|
if (PlainObjectType::Options&RowMajor) {
|
||||||
const Index index = m_dimensions.IndexOfRowMajor(array<Index, NumDims>{{firstIndex, secondIndex, otherIndices...}});
|
const Index index = m_dimensions.IndexOfRowMajor(array<Index, NumDims>{{firstIndex, secondIndex, otherIndices...}});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user