aboutsummaryrefslogtreecommitdiff
path: root/test/meta.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/meta.cpp')
-rw-r--r--test/meta.cpp89
1 files changed, 75 insertions, 14 deletions
diff --git a/test/meta.cpp b/test/meta.cpp
index b8dea68e8..7a8b93c3d 100644
--- a/test/meta.cpp
+++ b/test/meta.cpp
@@ -15,14 +15,26 @@ bool check_is_convertible(const From&, const To&)
return internal::is_convertible<From,To>::value;
}
-void test_meta()
+struct FooReturnType {
+ typedef int ReturnType;
+};
+
+struct MyInterface {
+ virtual void func() = 0;
+ virtual ~MyInterface() {}
+};
+struct MyImpl : public MyInterface {
+ void func() {}
+};
+
+EIGEN_DECLARE_TEST(meta)
{
VERIFY((internal::conditional<(3<4),internal::true_type, internal::false_type>::type::value));
VERIFY(( internal::is_same<float,float>::value));
VERIFY((!internal::is_same<float,double>::value));
VERIFY((!internal::is_same<float,float&>::value));
VERIFY((!internal::is_same<float,const float&>::value));
-
+
VERIFY(( internal::is_same<float,internal::remove_all<const float&>::type >::value));
VERIFY(( internal::is_same<float,internal::remove_all<const float*>::type >::value));
VERIFY(( internal::is_same<float,internal::remove_all<const float*&>::type >::value));
@@ -51,23 +63,40 @@ void test_meta()
VERIFY(( internal::is_same< internal::add_const_on_value_type<const float* const>::type, const float* const>::value));
VERIFY(( internal::is_same< internal::add_const_on_value_type<float* const>::type, const float* const>::value));
-
+
VERIFY(( internal::is_same<float,internal::remove_reference<float&>::type >::value));
VERIFY(( internal::is_same<const float,internal::remove_reference<const float&>::type >::value));
VERIFY(( internal::is_same<float,internal::remove_pointer<float*>::type >::value));
VERIFY(( internal::is_same<const float,internal::remove_pointer<const float*>::type >::value));
VERIFY(( internal::is_same<float,internal::remove_pointer<float* const >::type >::value));
-
- VERIFY(( internal::is_convertible<float,double>::value ));
- VERIFY(( internal::is_convertible<int,double>::value ));
- VERIFY(( internal::is_convertible<double,int>::value ));
- VERIFY((!internal::is_convertible<std::complex<double>,double>::value ));
- VERIFY(( internal::is_convertible<Array33f,Matrix3f>::value ));
-// VERIFY((!internal::is_convertible<Matrix3f,Matrix3d>::value )); //does not work because the conversion is prevented by a static assertion
- VERIFY((!internal::is_convertible<Array33f,int>::value ));
- VERIFY((!internal::is_convertible<MatrixXf,float>::value ));
+
+
+ // is_convertible
+ STATIC_CHECK(( internal::is_convertible<float,double>::value ));
+ STATIC_CHECK(( internal::is_convertible<int,double>::value ));
+ STATIC_CHECK(( internal::is_convertible<int, short>::value ));
+ STATIC_CHECK(( internal::is_convertible<short, int>::value ));
+ STATIC_CHECK(( internal::is_convertible<double,int>::value ));
+ STATIC_CHECK(( internal::is_convertible<double,std::complex<double> >::value ));
+ STATIC_CHECK((!internal::is_convertible<std::complex<double>,double>::value ));
+ STATIC_CHECK(( internal::is_convertible<Array33f,Matrix3f>::value ));
+ STATIC_CHECK(( internal::is_convertible<Matrix3f&,Matrix3f>::value ));
+ STATIC_CHECK(( internal::is_convertible<Matrix3f&,Matrix3f&>::value ));
+ STATIC_CHECK(( internal::is_convertible<Matrix3f&,const Matrix3f&>::value ));
+ STATIC_CHECK(( internal::is_convertible<const Matrix3f&,Matrix3f>::value ));
+ 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 ));
+
+ 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 ));
{
- float f;
+ float f = 0.0f;
MatrixXf A, B;
VectorXf a, b;
VERIFY(( check_is_convertible(a.dot(b), f) ));
@@ -75,7 +104,39 @@ void test_meta()
VERIFY((!check_is_convertible(A*B, f) ));
VERIFY(( check_is_convertible(A*B, A) ));
}
-
+
+ #if (EIGEN_COMP_GNUC && EIGEN_COMP_GNUC <= 99) \
+ || (EIGEN_COMP_CLANG && EIGEN_COMP_CLANG <= 909) \
+ || (EIGEN_COMP_MSVC && EIGEN_COMP_MSVC <=1914)
+ // See http://eigen.tuxfamily.org/bz/show_bug.cgi?id=1752,
+ // basically, a fix in the c++ standard breaks our c++98 implementation
+ // of is_convertible for abstract classes.
+ // So the following tests are expected to fail with recent compilers.
+
+ STATIC_CHECK(( !internal::is_convertible<MyInterface, MyImpl>::value ));
+ #if (!EIGEN_COMP_GNUC_STRICT) || (EIGEN_GNUC_AT_LEAST(4,8))
+ // GCC prior to 4.8 fails to compile this test:
+ // error: cannot allocate an object of abstract type 'MyInterface'
+ // In other word, it does not obey SFINAE.
+ // Nevertheless, we don't really care about supporting abstract type as scalar type!
+ STATIC_CHECK(( !internal::is_convertible<MyImpl, MyInterface>::value ));
+ #endif
+ STATIC_CHECK(( internal::is_convertible<MyImpl, const MyInterface&>::value ));
+
+ #endif
+
+ {
+ int i = 0;
+ VERIFY(( check_is_convertible(fix<3>(), i) ));
+ VERIFY((!check_is_convertible(i, fix<DynamicIndex>()) ));
+ }
+
+
+ VERIFY(( internal::has_ReturnType<FooReturnType>::value ));
+ VERIFY(( internal::has_ReturnType<ScalarBinaryOpTraits<int,int> >::value ));
+ VERIFY(( !internal::has_ReturnType<MatrixXf>::value ));
+ VERIFY(( !internal::has_ReturnType<int>::value ));
+
VERIFY(internal::meta_sqrt<1>::ret == 1);
#define VERIFY_META_SQRT(X) VERIFY(internal::meta_sqrt<X>::ret == int(std::sqrt(double(X))))
VERIFY_META_SQRT(2);