Brian Silverman | 72890c2 | 2015-09-19 14:37:37 -0400 | [diff] [blame] | 1 | // This file is part of Eigen, a lightweight C++ template library |
| 2 | // for linear algebra. |
| 3 | // |
| 4 | // Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr> |
| 5 | // |
| 6 | // This Source Code Form is subject to the terms of the Mozilla |
| 7 | // Public License v. 2.0. If a copy of the MPL was not distributed |
| 8 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 9 | |
| 10 | #include "main.h" |
| 11 | |
Austin Schuh | 189376f | 2018-12-20 22:11:15 +1100 | [diff] [blame] | 12 | template<typename From, typename To> |
| 13 | bool check_is_convertible(const From&, const To&) |
| 14 | { |
| 15 | return internal::is_convertible<From,To>::value; |
| 16 | } |
| 17 | |
Brian Silverman | 72890c2 | 2015-09-19 14:37:37 -0400 | [diff] [blame] | 18 | void test_meta() |
| 19 | { |
| 20 | VERIFY((internal::conditional<(3<4),internal::true_type, internal::false_type>::type::value)); |
| 21 | VERIFY(( internal::is_same<float,float>::value)); |
| 22 | VERIFY((!internal::is_same<float,double>::value)); |
| 23 | VERIFY((!internal::is_same<float,float&>::value)); |
| 24 | VERIFY((!internal::is_same<float,const float&>::value)); |
| 25 | |
| 26 | VERIFY(( internal::is_same<float,internal::remove_all<const float&>::type >::value)); |
| 27 | VERIFY(( internal::is_same<float,internal::remove_all<const float*>::type >::value)); |
| 28 | VERIFY(( internal::is_same<float,internal::remove_all<const float*&>::type >::value)); |
| 29 | VERIFY(( internal::is_same<float,internal::remove_all<float**>::type >::value)); |
| 30 | VERIFY(( internal::is_same<float,internal::remove_all<float**&>::type >::value)); |
| 31 | VERIFY(( internal::is_same<float,internal::remove_all<float* const *&>::type >::value)); |
| 32 | VERIFY(( internal::is_same<float,internal::remove_all<float* const>::type >::value)); |
| 33 | |
| 34 | // test add_const |
| 35 | VERIFY(( internal::is_same< internal::add_const<float>::type, const float >::value)); |
| 36 | VERIFY(( internal::is_same< internal::add_const<float*>::type, float* const>::value)); |
| 37 | VERIFY(( internal::is_same< internal::add_const<float const*>::type, float const* const>::value)); |
| 38 | VERIFY(( internal::is_same< internal::add_const<float&>::type, float& >::value)); |
| 39 | |
| 40 | // test remove_const |
| 41 | VERIFY(( internal::is_same< internal::remove_const<float const* const>::type, float const* >::value)); |
| 42 | VERIFY(( internal::is_same< internal::remove_const<float const*>::type, float const* >::value)); |
| 43 | VERIFY(( internal::is_same< internal::remove_const<float* const>::type, float* >::value)); |
| 44 | |
| 45 | // test add_const_on_value_type |
| 46 | VERIFY(( internal::is_same< internal::add_const_on_value_type<float&>::type, float const& >::value)); |
| 47 | VERIFY(( internal::is_same< internal::add_const_on_value_type<float*>::type, float const* >::value)); |
| 48 | |
| 49 | VERIFY(( internal::is_same< internal::add_const_on_value_type<float>::type, const float >::value)); |
| 50 | VERIFY(( internal::is_same< internal::add_const_on_value_type<const float>::type, const float >::value)); |
| 51 | |
| 52 | VERIFY(( internal::is_same< internal::add_const_on_value_type<const float* const>::type, const float* const>::value)); |
| 53 | VERIFY(( internal::is_same< internal::add_const_on_value_type<float* const>::type, const float* const>::value)); |
| 54 | |
| 55 | VERIFY(( internal::is_same<float,internal::remove_reference<float&>::type >::value)); |
| 56 | VERIFY(( internal::is_same<const float,internal::remove_reference<const float&>::type >::value)); |
| 57 | VERIFY(( internal::is_same<float,internal::remove_pointer<float*>::type >::value)); |
| 58 | VERIFY(( internal::is_same<const float,internal::remove_pointer<const float*>::type >::value)); |
| 59 | VERIFY(( internal::is_same<float,internal::remove_pointer<float* const >::type >::value)); |
| 60 | |
Austin Schuh | 189376f | 2018-12-20 22:11:15 +1100 | [diff] [blame] | 61 | VERIFY(( internal::is_convertible<float,double>::value )); |
| 62 | VERIFY(( internal::is_convertible<int,double>::value )); |
| 63 | VERIFY(( internal::is_convertible<double,int>::value )); |
| 64 | VERIFY((!internal::is_convertible<std::complex<double>,double>::value )); |
| 65 | VERIFY(( internal::is_convertible<Array33f,Matrix3f>::value )); |
| 66 | // VERIFY((!internal::is_convertible<Matrix3f,Matrix3d>::value )); //does not work because the conversion is prevented by a static assertion |
| 67 | VERIFY((!internal::is_convertible<Array33f,int>::value )); |
| 68 | VERIFY((!internal::is_convertible<MatrixXf,float>::value )); |
| 69 | { |
| 70 | float f; |
| 71 | MatrixXf A, B; |
| 72 | VectorXf a, b; |
| 73 | VERIFY(( check_is_convertible(a.dot(b), f) )); |
| 74 | VERIFY(( check_is_convertible(a.transpose()*b, f) )); |
| 75 | VERIFY((!check_is_convertible(A*B, f) )); |
| 76 | VERIFY(( check_is_convertible(A*B, A) )); |
| 77 | } |
| 78 | |
Brian Silverman | 72890c2 | 2015-09-19 14:37:37 -0400 | [diff] [blame] | 79 | VERIFY(internal::meta_sqrt<1>::ret == 1); |
| 80 | #define VERIFY_META_SQRT(X) VERIFY(internal::meta_sqrt<X>::ret == int(std::sqrt(double(X)))) |
| 81 | VERIFY_META_SQRT(2); |
| 82 | VERIFY_META_SQRT(3); |
| 83 | VERIFY_META_SQRT(4); |
| 84 | VERIFY_META_SQRT(5); |
| 85 | VERIFY_META_SQRT(6); |
| 86 | VERIFY_META_SQRT(8); |
| 87 | VERIFY_META_SQRT(9); |
| 88 | VERIFY_META_SQRT(15); |
| 89 | VERIFY_META_SQRT(16); |
| 90 | VERIFY_META_SQRT(17); |
| 91 | VERIFY_META_SQRT(255); |
| 92 | VERIFY_META_SQRT(256); |
| 93 | VERIFY_META_SQRT(257); |
| 94 | VERIFY_META_SQRT(1023); |
| 95 | VERIFY_META_SQRT(1024); |
| 96 | VERIFY_META_SQRT(1025); |
| 97 | } |