• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Boost.Geometry
2 // Unit Test
3 
4 // Copyright (c) 2019 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     : boost::is_same<T, double>
24 {};
25 
26 template <typename T>
27 struct is_float
28     : boost::is_same<T, float>
29 {};
30 
31 
32 template <typename Tuple>
33 struct is_boost_tuple
34     : boost::integral_constant<bool, false>
35 {};
36 
37 template <class T0, class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8, class T9>
38 struct is_boost_tuple<boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> >
39     : boost::integral_constant<bool, true>
40 {};
41 
42 template <typename Tuple>
43 struct is_boost_tuples_cons
44     : boost::integral_constant<bool, false>
45 {};
46 
47 template <typename HT, typename TT>
48 struct is_boost_tuples_cons<boost::tuples::cons<HT, TT> >
49     : boost::integral_constant<bool, true>
50 {};
51 
52 template <typename Tuple>
53 struct is_std_pair
54     : boost::integral_constant<bool, false>
55 {};
56 
57 template <typename F, typename S>
58 struct is_std_pair<std::pair<F, S> >
59     : boost::integral_constant<bool, true>
60 {};
61 
62 #if !defined(BOOST_NO_CXX11_HDR_TUPLE) && !defined(BOOST_NO_VARIADIC_TEMPLATES)
63 
64 template <typename Tuple>
65 struct is_std_tuple
66     : boost::integral_constant<bool, false>
67 {};
68 
69 template <typename ...Ts>
70 struct is_std_tuple<std::tuple<Ts...> >
71     : boost::integral_constant<bool, true>
72 {};
73 
74 #endif
75 
76 template <typename Tuple>
test_all()77 void test_all()
78 {
79     typedef Tuple tuple_id;
80     tuple_id tup_id(1, 2.0);
81 
82     BOOST_CHECK_EQUAL((bgt::get<0>(tup_id)), 1);
83     BOOST_CHECK_EQUAL((bgt::get<1>(tup_id)), 2.0);
84 
85     BOOST_CHECK_EQUAL(int(bgt::size<tuple_id>::value), 2);
86 
87     BOOST_CHECK_EQUAL((bgt::find_index_if<tuple_id, is_double>::value), 1);
88     BOOST_CHECK((boost::is_same<typename bgt::find_if<tuple_id, is_double>::type, double>::value));
89 
90     BOOST_CHECK_EQUAL((bgt::find_index_if<tuple_id, is_float>::value), 2);
91     BOOST_CHECK((boost::is_same<typename bgt::find_if<tuple_id, is_float>::type, boost::tuples::null_type>::value));
92 
93     typedef typename bgt::push_back<tuple_id, float>::type tuple_idf;
94     tuple_idf tup_idf = bgt::push_back<tuple_id, float>::apply(tup_id, 3.0f);
95 
96     BOOST_CHECK_EQUAL((bgt::get<0>(tup_idf)), 1);
97     BOOST_CHECK_EQUAL((bgt::get<1>(tup_idf)), 2.0);
98     BOOST_CHECK_EQUAL((bgt::get<2>(tup_idf)), 3.0f);
99 
100     BOOST_CHECK_EQUAL(int(bgt::size<tuple_idf>::value), 3);
101 
102     BOOST_CHECK_EQUAL((bgt::find_index_if<tuple_idf, is_float>::value), 2);
103     BOOST_CHECK((boost::is_same<typename bgt::find_if<tuple_idf, is_float>::type, float>::value));
104 
105 #if !defined(BOOST_NO_CXX11_HDR_TUPLE) && !defined(BOOST_NO_VARIADIC_TEMPLATES)
106 
107     BOOST_CHECK((
108         (is_boost_tuple<tuple_id>::value && is_boost_tuples_cons<tuple_idf>::value)
109      || (!is_boost_tuple<tuple_id>::value && is_std_tuple<tuple_idf>::value)
110         ));
111 
112 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
113 
114     tup_idf = bgt::push_back<tuple_id, float>::apply(std::move(tup_id), 3.0f);
115 
116     BOOST_CHECK_EQUAL((bgt::get<0>(tup_idf)), 1);
117     BOOST_CHECK_EQUAL((bgt::get<1>(tup_idf)), 2.0);
118     BOOST_CHECK_EQUAL((bgt::get<2>(tup_idf)), 3.0f);
119 
120 #endif
121 
122 #else
123 
124     BOOST_CHECK((is_boost_tuples_cons<tuple_idf>::type, float>::value));
125 
126 #endif
127 }
128 
test_main(int,char * [])129 int test_main(int, char* [])
130 {
131     test_all<boost::tuple<int, double> >();
132     test_all<std::pair<int, double> >();
133 
134 #if !defined(BOOST_NO_CXX11_HDR_TUPLE) && !defined(BOOST_NO_VARIADIC_TEMPLATES)
135 
136     test_all<std::tuple<int, double> >();
137 
138 #endif
139 
140     return 0;
141 }
142