1 | // Boost.Geometry |
2 | // Unit Test |
3 | |
4 | // Copyright (c) 2019-2020 Oracle and/or its affiliates. |
5 | |
6 | // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle |
7 | |
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 | |
12 | |
13 | #include <geometry_test_common.hpp> |
14 | |
15 | #include <boost/geometry/util/tuples.hpp> |
16 | |
17 | namespace bt = boost::tuples; |
18 | namespace bgt = boost::geometry::tuples; |
19 | namespace bm = boost::mpl; |
20 | |
21 | template <typename T> |
22 | struct is_double |
23 | : std::is_same<T, double> |
24 | {}; |
25 | |
26 | template <typename T> |
27 | struct is_float |
28 | : std::is_same<T, float> |
29 | {}; |
30 | |
31 | |
32 | template <typename Tuple> |
33 | struct is_boost_tuple |
34 | : std::integral_constant<bool, false> |
35 | {}; |
36 | |
37 | template <typename ...Ts> |
38 | struct is_boost_tuple<boost::tuple<Ts...> > |
39 | : std::integral_constant<bool, true> |
40 | {}; |
41 | |
42 | template <typename Tuple> |
43 | struct is_boost_tuples_cons |
44 | : std::integral_constant<bool, false> |
45 | {}; |
46 | |
47 | template <typename HT, typename TT> |
48 | struct is_boost_tuples_cons<boost::tuples::cons<HT, TT> > |
49 | : std::integral_constant<bool, true> |
50 | {}; |
51 | |
52 | template <typename Tuple> |
53 | struct is_std_pair |
54 | : std::integral_constant<bool, false> |
55 | {}; |
56 | |
57 | template <typename F, typename S> |
58 | struct is_std_pair<std::pair<F, S> > |
59 | : std::integral_constant<bool, true> |
60 | {}; |
61 | |
62 | template <typename Tuple> |
63 | struct is_std_tuple |
64 | : std::integral_constant<bool, false> |
65 | {}; |
66 | |
67 | template <typename ...Ts> |
68 | struct is_std_tuple<std::tuple<Ts...> > |
69 | : std::integral_constant<bool, true> |
70 | {}; |
71 | |
72 | template <typename Tuple> |
73 | void test_all() |
74 | { |
75 | typedef Tuple tuple_id; |
76 | tuple_id tup_id(1, 2.0); |
77 | |
78 | BOOST_CHECK_EQUAL((bgt::get<0>(tup_id)), 1); |
79 | BOOST_CHECK_EQUAL((bgt::get<1>(tup_id)), 2.0); |
80 | |
81 | BOOST_CHECK_EQUAL((bgt::size<tuple_id>::value), 2u); |
82 | |
83 | BOOST_CHECK_EQUAL((bgt::find_index_if<tuple_id, is_double>::value), 1u); |
84 | BOOST_CHECK((std::is_same<typename bgt::find_if<tuple_id, is_double>::type, double>::value)); |
85 | |
86 | BOOST_CHECK_EQUAL((bgt::find_index_if<tuple_id, is_float>::value), 2u); |
87 | BOOST_CHECK((std::is_same<typename bgt::find_if<tuple_id, is_float>::type, bg::tuples::detail::null_type>::value)); |
88 | |
89 | typedef typename bgt::push_back<tuple_id, float>::type tuple_idf; |
90 | tuple_idf tup_idf = bgt::push_back<tuple_id, float>::apply(tup_id, 3.0f); |
91 | |
92 | BOOST_CHECK_EQUAL((bgt::get<0>(tup_idf)), 1); |
93 | BOOST_CHECK_EQUAL((bgt::get<1>(tup_idf)), 2.0); |
94 | BOOST_CHECK_EQUAL((bgt::get<2>(tup_idf)), 3.0f); |
95 | |
96 | BOOST_CHECK_EQUAL((bgt::size<tuple_idf>::value), 3u); |
97 | |
98 | BOOST_CHECK_EQUAL((bgt::find_index_if<tuple_idf, is_float>::value), 2u); |
99 | BOOST_CHECK((std::is_same<typename bgt::find_if<tuple_idf, is_float>::type, float>::value)); |
100 | |
101 | BOOST_CHECK(( |
102 | (is_boost_tuple<tuple_id>::value && is_boost_tuples_cons<tuple_idf>::value) |
103 | || (!is_boost_tuple<tuple_id>::value && is_std_tuple<tuple_idf>::value) |
104 | )); |
105 | |
106 | tup_idf = bgt::push_back<tuple_id, float>::apply(std::move(tup_id), 3.0f); |
107 | |
108 | BOOST_CHECK_EQUAL((bgt::get<0>(tup_idf)), 1); |
109 | BOOST_CHECK_EQUAL((bgt::get<1>(tup_idf)), 2.0); |
110 | BOOST_CHECK_EQUAL((bgt::get<2>(tup_idf)), 3.0f); |
111 | } |
112 | |
113 | int test_main(int, char* []) |
114 | { |
115 | test_all<std::tuple<int, double> >(); |
116 | test_all<std::pair<int, double> >(); |
117 | test_all<boost::tuple<int, double> >(); |
118 | |
119 | return 0; |
120 | } |
121 | |