diff options
author | Gael Guennebaud <g.gael@free.fr> | 2018-07-12 09:57:19 +0200 |
---|---|---|
committer | Gael Guennebaud <g.gael@free.fr> | 2018-07-12 09:57:19 +0200 |
commit | 21cf4a1a8b0868b6dcb74aa4ebe6317d5316b2e1 (patch) | |
tree | 447fb61ad27dd4dec4707c031a8202a30d5f4778 /test/meta.cpp | |
parent | 8a5955a052f64fc32099b052a221e0b5a8e92cbd (diff) |
Make is_convertible more robust and conformant to std::is_convertible
Diffstat (limited to 'test/meta.cpp')
-rw-r--r-- | test/meta.cpp | 36 |
1 files changed, 29 insertions, 7 deletions
diff --git a/test/meta.cpp b/test/meta.cpp index bd505762e..4904f3ba4 100644 --- a/test/meta.cpp +++ b/test/meta.cpp @@ -19,6 +19,14 @@ struct FooReturnType { typedef int ReturnType; }; +struct MyInterface { + virtual void func() = 0; + virtual ~MyInterface() {} +}; +struct MyImpl : public MyInterface { + void func() {} +}; + void test_meta() { VERIFY((internal::conditional<(3<4),internal::true_type, internal::false_type>::type::value)); @@ -62,14 +70,19 @@ void test_meta() 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 )); + + // 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 )); // 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 )); + STATIC_CHECK((!internal::is_convertible<Array33f,int>::value )); + STATIC_CHECK((!internal::is_convertible<MatrixXf,float>::value )); { float f; MatrixXf A, B; @@ -80,6 +93,15 @@ void test_meta() VERIFY(( check_is_convertible(A*B, A) )); } + STATIC_CHECK(( !internal::is_convertible<MyInterface, MyImpl>::value )); + STATIC_CHECK(( !internal::is_convertible<MyImpl, MyInterface>::value )); + STATIC_CHECK(( internal::is_convertible<MyImpl, const MyInterface&>::value )); + { + int i; + 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 )); |