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// Copyright (c) 2023 Adam Wulkiewicz, Lodz, Poland.
8
9// This file was modified by Oracle on 2021.
10// Modifications copyright (c) 2021, Oracle and/or its affiliates.
11// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
12
13// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
14// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
15
16// Use, modification and distribution is subject to the Boost Software License,
17// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
18// http://www.boost.org/LICENSE_1_0.txt)
19
20
21#include <geometry_test_common.hpp>
22
23#include <boost/geometry/util/condition.hpp>
24#include <boost/geometry/util/select_most_precise.hpp>
25
26
27struct user_defined {};
28
29template <typename T1, typename T2, typename ExpectedType>
30void test()
31{
32 using type = typename bg::select_most_precise<T1, T2>::type;
33 bool is_same = std::is_same<type, ExpectedType>::value;
34
35 BOOST_CHECK_MESSAGE(is_same,
36 "The most precise of types " <<
37 "T1: {" << typeid(T1).name() << " | s: " << sizeof(T1) << "}" <<
38 " and " <<
39 "T2: {" << typeid(T2).name() << " | s: " << sizeof(T2) << "}" <<
40 " does not match " <<
41 "ExpectedType: {" << typeid(ExpectedType).name() << " | s: " << sizeof(ExpectedType) << "}");
42}
43
44int test_main(int, char* [])
45{
46 // fp only
47 test<float, float, float>();
48 test<float, double, double>();
49 test<double, float, double>();
50 test<double, double, double>();
51
52 // integer only
53 test<int, int, int>();
54 test<int, short int, int>();
55 test<short int, int, int>();
56 test<short int, short int, short int>();
57
58 // int/fp
59 test<double, int, double>();
60 test<int, double, double>();
61 test<long double, long double, long double>();
62 test<float, int, float>();
63 test<int, float, float>();
64
65 if (BOOST_GEOMETRY_CONDITION(sizeof(long double) > sizeof(double)))
66 {
67 // This cannot be done for MSVC because double/long double is the same
68 // This is also true for Android
69 test<double, long double, long double>();
70 test<long double, double, long double>();
71 }
72
73 // with any other non-integer/float class
74 test<int, user_defined, user_defined>();
75 test<user_defined, int, user_defined>();
76 test<long double, user_defined, user_defined>();
77 test<user_defined, long double, user_defined>();
78 test<user_defined, user_defined, user_defined>();
79
80 // should not compile
81 //test<void, void, void>();
82
83 return 0;
84}
85

source code of boost/libs/geometry/test/util/select_most_precise.cpp