You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
4.6 KiB

  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. #include "main.h"
  10. template<typename From, typename To>
  11. bool check_is_convertible(const From&, const To&)
  12. {
  13. return internal::is_convertible<From,To>::value;
  14. }
  15. void test_meta()
  16. {
  17. VERIFY((internal::conditional<(3<4),internal::true_type, internal::false_type>::type::value));
  18. VERIFY(( internal::is_same<float,float>::value));
  19. VERIFY((!internal::is_same<float,double>::value));
  20. VERIFY((!internal::is_same<float,float&>::value));
  21. VERIFY((!internal::is_same<float,const float&>::value));
  22. VERIFY(( internal::is_same<float,internal::remove_all<const float&>::type >::value));
  23. VERIFY(( internal::is_same<float,internal::remove_all<const float*>::type >::value));
  24. VERIFY(( internal::is_same<float,internal::remove_all<const float*&>::type >::value));
  25. VERIFY(( internal::is_same<float,internal::remove_all<float**>::type >::value));
  26. VERIFY(( internal::is_same<float,internal::remove_all<float**&>::type >::value));
  27. VERIFY(( internal::is_same<float,internal::remove_all<float* const *&>::type >::value));
  28. VERIFY(( internal::is_same<float,internal::remove_all<float* const>::type >::value));
  29. // test add_const
  30. VERIFY(( internal::is_same< internal::add_const<float>::type, const float >::value));
  31. VERIFY(( internal::is_same< internal::add_const<float*>::type, float* const>::value));
  32. VERIFY(( internal::is_same< internal::add_const<float const*>::type, float const* const>::value));
  33. VERIFY(( internal::is_same< internal::add_const<float&>::type, float& >::value));
  34. // test remove_const
  35. VERIFY(( internal::is_same< internal::remove_const<float const* const>::type, float const* >::value));
  36. VERIFY(( internal::is_same< internal::remove_const<float const*>::type, float const* >::value));
  37. VERIFY(( internal::is_same< internal::remove_const<float* const>::type, float* >::value));
  38. // test add_const_on_value_type
  39. VERIFY(( internal::is_same< internal::add_const_on_value_type<float&>::type, float const& >::value));
  40. VERIFY(( internal::is_same< internal::add_const_on_value_type<float*>::type, float const* >::value));
  41. VERIFY(( internal::is_same< internal::add_const_on_value_type<float>::type, const float >::value));
  42. VERIFY(( internal::is_same< internal::add_const_on_value_type<const float>::type, const float >::value));
  43. VERIFY(( internal::is_same< internal::add_const_on_value_type<const float* const>::type, const float* const>::value));
  44. VERIFY(( internal::is_same< internal::add_const_on_value_type<float* const>::type, const float* const>::value));
  45. VERIFY(( internal::is_same<float,internal::remove_reference<float&>::type >::value));
  46. VERIFY(( internal::is_same<const float,internal::remove_reference<const float&>::type >::value));
  47. VERIFY(( internal::is_same<float,internal::remove_pointer<float*>::type >::value));
  48. VERIFY(( internal::is_same<const float,internal::remove_pointer<const float*>::type >::value));
  49. VERIFY(( internal::is_same<float,internal::remove_pointer<float* const >::type >::value));
  50. VERIFY(( internal::is_convertible<float,double>::value ));
  51. VERIFY(( internal::is_convertible<int,double>::value ));
  52. VERIFY(( internal::is_convertible<double,int>::value ));
  53. VERIFY((!internal::is_convertible<std::complex<double>,double>::value ));
  54. VERIFY(( internal::is_convertible<Array33f,Matrix3f>::value ));
  55. // VERIFY((!internal::is_convertible<Matrix3f,Matrix3d>::value )); //does not work because the conversion is prevented by a static assertion
  56. VERIFY((!internal::is_convertible<Array33f,int>::value ));
  57. VERIFY((!internal::is_convertible<MatrixXf,float>::value ));
  58. {
  59. float f;
  60. MatrixXf A, B;
  61. VectorXf a, b;
  62. VERIFY(( check_is_convertible(a.dot(b), f) ));
  63. VERIFY(( check_is_convertible(a.transpose()*b, f) ));
  64. VERIFY((!check_is_convertible(A*B, f) ));
  65. VERIFY(( check_is_convertible(A*B, A) ));
  66. }
  67. VERIFY(internal::meta_sqrt<1>::ret == 1);
  68. #define VERIFY_META_SQRT(X) VERIFY(internal::meta_sqrt<X>::ret == int(std::sqrt(double(X))))
  69. VERIFY_META_SQRT(2);
  70. VERIFY_META_SQRT(3);
  71. VERIFY_META_SQRT(4);
  72. VERIFY_META_SQRT(5);
  73. VERIFY_META_SQRT(6);
  74. VERIFY_META_SQRT(8);
  75. VERIFY_META_SQRT(9);
  76. VERIFY_META_SQRT(15);
  77. VERIFY_META_SQRT(16);
  78. VERIFY_META_SQRT(17);
  79. VERIFY_META_SQRT(255);
  80. VERIFY_META_SQRT(256);
  81. VERIFY_META_SQRT(257);
  82. VERIFY_META_SQRT(1023);
  83. VERIFY_META_SQRT(1024);
  84. VERIFY_META_SQRT(1025);
  85. }