select_most_precise.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Unit Test
  3. // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
  4. // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
  5. // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
  6. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  7. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  8. // Use, modification and distribution is subject to the Boost Software License,
  9. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  10. // http://www.boost.org/LICENSE_1_0.txt)
  11. #include <geometry_test_common.hpp>
  12. #include <boost/geometry/util/select_most_precise.hpp>
  13. struct user_defined {};
  14. template <typename T1, typename T2, typename ExpectedType>
  15. void test()
  16. {
  17. typedef typename bg::select_most_precise<T1, T2>::type type;
  18. bool is_same = boost::is_same<type, ExpectedType>::type::value;
  19. BOOST_CHECK_MESSAGE(is_same,
  20. "The most precise of types " <<
  21. "T1: {" << typeid(T1).name() << " | s: " << sizeof(T1) << "}" <<
  22. " and " <<
  23. "T2: {" << typeid(T2).name() << " | s: " << sizeof(T2) << "}" <<
  24. " does not match " <<
  25. "ExpectedType: {" << typeid(ExpectedType).name() << " | s: " << sizeof(ExpectedType) << "}");
  26. }
  27. int test_main(int, char* [])
  28. {
  29. // fp only
  30. test<float, float, float>();
  31. test<float, double, double>();
  32. test<double, float, double>();
  33. test<double, double, double>();
  34. // integer only
  35. test<int, int, int>();
  36. test<int, short int, int>();
  37. test<short int, int, int>();
  38. test<short int, short int, short int>();
  39. // int/fp
  40. test<double, int, double>();
  41. test<int, double, double>();
  42. test<long double, long double, long double>();
  43. test<float, int, float>();
  44. test<int, float, float>();
  45. if ( sizeof(long double) > sizeof(double) )
  46. {
  47. // This cannot be done for MSVC because double/long double is the same
  48. // This is also true for Android
  49. test<double, long double, long double>();
  50. test<long double, double, long double>();
  51. }
  52. // with any other non-integer/float class
  53. test<int, user_defined, user_defined>();
  54. test<user_defined, int, user_defined>();
  55. test<long double, user_defined, user_defined>();
  56. test<user_defined, long double, user_defined>();
  57. test<user_defined, user_defined, user_defined>();
  58. // should not compile
  59. //test<void, void, void>();
  60. return 0;
  61. }