aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2019-10-10 17:41:47 +0200
committerGravatar Gael Guennebaud <g.gael@free.fr>2019-10-10 17:41:47 +0200
commite7d8ba747c7b161eff59959d4d2a5acf788ee00e (patch)
tree93173c2dd314cc541c34148419126a2bf31b678a
parentfb557aec5c1e4d75ef9293952dbfb03bbb357d6d (diff)
bug #1752: make is_convertible equivalent to the std c++11 equivalent and fallback to std::is_convertible when c++11 is enabled.
-rwxr-xr-xEigen/src/Core/util/Meta.h13
-rw-r--r--test/meta.cpp8
2 files changed, 19 insertions, 2 deletions
diff --git a/Eigen/src/Core/util/Meta.h b/Eigen/src/Core/util/Meta.h
index db948cea1..fe9550d71 100755
--- a/Eigen/src/Core/util/Meta.h
+++ b/Eigen/src/Core/util/Meta.h
@@ -174,6 +174,11 @@ template<typename T> struct add_const_on_value_type<T*> { typedef T const
template<typename T> struct add_const_on_value_type<T* const> { typedef T const* const type; };
template<typename T> struct add_const_on_value_type<T const* const> { typedef T const* const type; };
+#if EIGEN_HAS_CXX11
+
+using std::is_convertible;
+
+#else
template<typename From, typename To>
struct is_convertible_impl
@@ -211,6 +216,14 @@ struct is_convertible
enum { value = is_convertible_impl<From,To>::value };
};
+template<typename T>
+struct is_convertible<T,T&> { enum { value = false }; };
+
+template<typename T>
+struct is_convertible<const T,const T&> { enum { value = true }; };
+
+#endif
+
/** \internal Allows to enable/disable an overload
* according to a compile time condition.
*/
diff --git a/test/meta.cpp b/test/meta.cpp
index 51395acd0..b432d9316 100644
--- a/test/meta.cpp
+++ b/test/meta.cpp
@@ -87,8 +87,12 @@ EIGEN_DECLARE_TEST(meta)
STATIC_CHECK(( internal::is_convertible<const Matrix3f&,const Matrix3f&>::value ));
STATIC_CHECK((!internal::is_convertible<const Matrix3f&,Matrix3f&>::value ));
STATIC_CHECK((!internal::is_convertible<const Matrix3f,Matrix3f&>::value ));
- STATIC_CHECK(( internal::is_convertible<Matrix3f,Matrix3f&>::value )); // std::is_convertible returns false here though Matrix3f from; Matrix3f& to = from; is valid.
- //STATIC_CHECK((!internal::is_convertible<Matrix3f,Matrix3d>::value )); //does not work because the conversion is prevented by a static assertion
+ STATIC_CHECK(!( internal::is_convertible<Matrix3f,Matrix3f&>::value ));
+
+ STATIC_CHECK(!( internal::is_convertible<int,int&>::value ));
+ STATIC_CHECK(( internal::is_convertible<const int,const int& >::value ));
+
+ //STATIC_CHECK((!internal::is_convertible<Matrix3f,Matrix3d>::value )); //does not even compile because the conversion is prevented by a static assertion
STATIC_CHECK((!internal::is_convertible<Array33f,int>::value ));
STATIC_CHECK((!internal::is_convertible<MatrixXf,float>::value ));
{