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