aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--Eigen/src/plugins/IndexedViewMethods.h6
-rw-r--r--test/indexed_view.cpp10
2 files changed, 14 insertions, 2 deletions
diff --git a/Eigen/src/plugins/IndexedViewMethods.h b/Eigen/src/plugins/IndexedViewMethods.h
index 90ade05ed..e6098bfc7 100644
--- a/Eigen/src/plugins/IndexedViewMethods.h
+++ b/Eigen/src/plugins/IndexedViewMethods.h
@@ -55,7 +55,9 @@ ivcSize(const Indices& indices) const {
template<typename RowIndices, typename ColIndices>
struct valid_indexed_view_overload {
- enum { value = !(internal::is_integral<RowIndices>::value && internal::is_integral<ColIndices>::value) };
+ // Here we use is_convertible to Index instead of is_integral in order to treat enums as Index.
+ // In c++11 we could use is_integral<T> && is_enum<T> if is_convertible appears to be too permissive.
+ enum { value = !(internal::is_convertible<RowIndices,Index>::value && internal::is_convertible<ColIndices,Index>::value) };
};
public:
@@ -81,7 +83,7 @@ operator()(const RowIndices& rowIndices, const ColIndices& colIndices) EIGEN_IND
(derived(), ivcRow(rowIndices), ivcCol(colIndices));
}
-// The folowing overload returns a Block<> object
+// The following overload returns a Block<> object
template<typename RowIndices, typename ColIndices>
typename internal::enable_if<valid_indexed_view_overload<RowIndices,ColIndices>::value
diff --git a/test/indexed_view.cpp b/test/indexed_view.cpp
index d4d82c54d..3ea8e7c00 100644
--- a/test/indexed_view.cpp
+++ b/test/indexed_view.cpp
@@ -277,6 +277,16 @@ void check_indexed_view()
VERIFY_IS_APPROX( A(legacy::seq(legacy::last,2,-2), legacy::seq(legacy::last-6,7)), A(seq(last,2,-2), seq(last-6,7)) );
VERIFY_IS_APPROX( A(seqN(legacy::last,2,-2), seqN(legacy::last-6,3)), A(seqN(last,2,-2), seqN(last-6,3)) );
+ // check mat(i,j) with weird types for i and j
+ {
+ VERIFY_IS_APPROX( A(B.RowsAtCompileTime-1, 1), A(3,1) );
+ VERIFY_IS_APPROX( A(B.RowsAtCompileTime, 1), A(3,1) );
+ VERIFY_IS_APPROX( A(B.RowsAtCompileTime-1, B.ColsAtCompileTime-1), A(3,3) );
+ VERIFY_IS_APPROX( A(B.RowsAtCompileTime, B.ColsAtCompileTime), A(3,3) );
+ enum { I = 3, J = 4 };
+ VERIFY_IS_APPROX( A(I,J), A(3,4) );
+ }
+
// check extended block API
{
VERIFY( is_same_eq( A.block<3,4>(1,1), A.block(1,1,fix<3>,fix<4>)) );