diff options
author | Gael Guennebaud <g.gael@free.fr> | 2018-05-18 13:59:55 +0200 |
---|---|---|
committer | Gael Guennebaud <g.gael@free.fr> | 2018-05-18 13:59:55 +0200 |
commit | 4dd767f455f1adfea7cb2febeab3efaa81246845 (patch) | |
tree | 4849b77657771fa8d74beea18cc3968bfe2ccbc4 | |
parent | 345c0ab450d623b79868ea60253db9d0d8bdd5c7 (diff) |
add some internal checks
-rw-r--r-- | Eigen/src/Core/util/XprHelper.h | 6 | ||||
-rw-r--r-- | Eigen/src/plugins/IndexedViewMethods.h | 11 | ||||
-rw-r--r-- | test/indexed_view.cpp | 15 |
3 files changed, 24 insertions, 8 deletions
diff --git a/Eigen/src/Core/util/XprHelper.h b/Eigen/src/Core/util/XprHelper.h index 10328be0d..1217404d6 100644 --- a/Eigen/src/Core/util/XprHelper.h +++ b/Eigen/src/Core/util/XprHelper.h @@ -47,6 +47,12 @@ template<typename T> struct is_valid_index_type }; }; +// true if both types are not valid index types +template<typename RowIndices, typename ColIndices> +struct valid_indexed_view_overload { + enum { value = !(internal::is_valid_index_type<RowIndices>::value && internal::is_valid_index_type<ColIndices>::value) }; +}; + // promote_scalar_arg is an helper used in operation between an expression and a scalar, like: // expression * scalar // Its role is to determine how the type T of the scalar operand should be promoted given the scalar type ExprScalar of the given expression. diff --git a/Eigen/src/plugins/IndexedViewMethods.h b/Eigen/src/plugins/IndexedViewMethods.h index 9ad2d9aee..d435aa597 100644 --- a/Eigen/src/plugins/IndexedViewMethods.h +++ b/Eigen/src/plugins/IndexedViewMethods.h @@ -53,11 +53,6 @@ ivcSize(const Indices& indices) const { return internal::makeIndexedViewCompatible(indices, internal::variable_if_dynamic<Index,SizeAtCompileTime>(derived().size()),Specialized); } -template<typename RowIndices, typename ColIndices> -struct valid_indexed_view_overload { - enum { value = !(internal::is_valid_index_type<RowIndices>::value && internal::is_valid_index_type<ColIndices>::value) }; -}; - public: #endif @@ -72,7 +67,7 @@ struct EIGEN_INDEXED_VIEW_METHOD_TYPE { // This is the generic version template<typename RowIndices, typename ColIndices> -typename internal::enable_if<valid_indexed_view_overload<RowIndices,ColIndices>::value +typename internal::enable_if<internal::valid_indexed_view_overload<RowIndices,ColIndices>::value && internal::traits<typename EIGEN_INDEXED_VIEW_METHOD_TYPE<RowIndices,ColIndices>::type>::ReturnAsIndexedView, typename EIGEN_INDEXED_VIEW_METHOD_TYPE<RowIndices,ColIndices>::type >::type operator()(const RowIndices& rowIndices, const ColIndices& colIndices) EIGEN_INDEXED_VIEW_METHOD_CONST @@ -84,7 +79,7 @@ operator()(const RowIndices& rowIndices, const ColIndices& colIndices) EIGEN_IND // The following overload returns a Block<> object template<typename RowIndices, typename ColIndices> -typename internal::enable_if<valid_indexed_view_overload<RowIndices,ColIndices>::value +typename internal::enable_if<internal::valid_indexed_view_overload<RowIndices,ColIndices>::value && internal::traits<typename EIGEN_INDEXED_VIEW_METHOD_TYPE<RowIndices,ColIndices>::type>::ReturnAsBlock, typename internal::traits<typename EIGEN_INDEXED_VIEW_METHOD_TYPE<RowIndices,ColIndices>::type>::BlockType>::type operator()(const RowIndices& rowIndices, const ColIndices& colIndices) EIGEN_INDEXED_VIEW_METHOD_CONST @@ -102,7 +97,7 @@ operator()(const RowIndices& rowIndices, const ColIndices& colIndices) EIGEN_IND // The following overload returns a Scalar template<typename RowIndices, typename ColIndices> -typename internal::enable_if<valid_indexed_view_overload<RowIndices,ColIndices>::value +typename internal::enable_if<internal::valid_indexed_view_overload<RowIndices,ColIndices>::value && internal::traits<typename EIGEN_INDEXED_VIEW_METHOD_TYPE<RowIndices,ColIndices>::type>::ReturnAsScalar, CoeffReturnType >::type operator()(const RowIndices& rowIndices, const ColIndices& colIndices) EIGEN_INDEXED_VIEW_METHOD_CONST diff --git a/test/indexed_view.cpp b/test/indexed_view.cpp index 71de60d84..033d8833f 100644 --- a/test/indexed_view.cpp +++ b/test/indexed_view.cpp @@ -395,4 +395,19 @@ void test_indexed_view() CALL_SUBTEST_2( check_indexed_view() ); CALL_SUBTEST_3( check_indexed_view() ); // } + + // static checks of some internals: + + #define STATIC_CHECK( COND ) \ + EIGEN_STATIC_ASSERT( (COND) , EIGEN_INTERNAL_ERROR_PLEASE_FILE_A_BUG_REPORT ) + + STATIC_CHECK(( internal::is_valid_index_type<int>::value )); + STATIC_CHECK(( internal::is_valid_index_type<unsigned int>::value )); + STATIC_CHECK(( internal::is_valid_index_type<short>::value )); + STATIC_CHECK(( internal::is_valid_index_type<std::ptrdiff_t>::value )); + STATIC_CHECK(( internal::is_valid_index_type<std::size_t>::value )); + STATIC_CHECK(( !internal::valid_indexed_view_overload<int,int>::value )); + STATIC_CHECK(( !internal::valid_indexed_view_overload<int,std::ptrdiff_t>::value )); + STATIC_CHECK(( !internal::valid_indexed_view_overload<std::ptrdiff_t,int>::value )); + STATIC_CHECK(( !internal::valid_indexed_view_overload<std::size_t,int>::value )); } |