comparison DEPENDENCIES/generic/include/boost/container/detail/pair.hpp @ 16:2665513ce2d3

Add boost headers
author Chris Cannam
date Tue, 05 Aug 2014 11:11:38 +0100
parents
children c530137014c0
comparison
equal deleted inserted replaced
15:663ca0da4350 16:2665513ce2d3
1 //////////////////////////////////////////////////////////////////////////////
2 //
3 // (C) Copyright Ion Gaztanaga 2005-2012.
4 //
5 // Distributed under the Boost Software License, Version 1.0.
6 // (See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
8 //
9 // See http://www.boost.org/libs/container for documentation.
10 //
11 //////////////////////////////////////////////////////////////////////////////
12
13 #ifndef BOOST_CONTAINER_CONTAINER_DETAIL_PAIR_HPP
14 #define BOOST_CONTAINER_CONTAINER_DETAIL_PAIR_HPP
15
16 #if defined(_MSC_VER)
17 # pragma once
18 #endif
19
20 #include "config_begin.hpp"
21 #include <boost/container/detail/workaround.hpp>
22
23 #include <boost/container/detail/mpl.hpp>
24 #include <boost/container/detail/type_traits.hpp>
25 #include <boost/container/detail/mpl.hpp>
26 #include <boost/container/detail/type_traits.hpp>
27
28 #include <utility> //std::pair
29 #include <algorithm> //std::swap
30
31 #include <boost/move/utility.hpp>
32 #include <boost/type_traits/is_class.hpp>
33
34 #ifndef BOOST_CONTAINER_PERFECT_FORWARDING
35 #include <boost/container/detail/preprocessor.hpp>
36 #endif
37
38 namespace boost {
39 namespace container {
40 namespace container_detail {
41
42 template <class T1, class T2>
43 struct pair;
44
45 template <class T>
46 struct is_pair
47 {
48 static const bool value = false;
49 };
50
51 template <class T1, class T2>
52 struct is_pair< pair<T1, T2> >
53 {
54 static const bool value = true;
55 };
56
57 template <class T1, class T2>
58 struct is_pair< std::pair<T1, T2> >
59 {
60 static const bool value = true;
61 };
62
63 struct pair_nat;
64
65 struct piecewise_construct_t { };
66 static const piecewise_construct_t piecewise_construct = piecewise_construct_t();
67
68 /*
69 template <class T1, class T2>
70 struct pair
71 {
72 template <class U, class V> pair(pair<U, V>&& p);
73 template <class... Args1, class... Args2>
74 pair(piecewise_construct_t, tuple<Args1...> first_args,
75 tuple<Args2...> second_args);
76
77 template <class U, class V> pair& operator=(const pair<U, V>& p);
78 pair& operator=(pair&& p) noexcept(is_nothrow_move_assignable<T1>::value &&
79 is_nothrow_move_assignable<T2>::value);
80 template <class U, class V> pair& operator=(pair<U, V>&& p);
81
82 void swap(pair& p) noexcept(noexcept(swap(first, p.first)) &&
83 noexcept(swap(second, p.second)));
84 };
85
86 template <class T1, class T2> bool operator==(const pair<T1,T2>&, const pair<T1,T2>&);
87 template <class T1, class T2> bool operator!=(const pair<T1,T2>&, const pair<T1,T2>&);
88 template <class T1, class T2> bool operator< (const pair<T1,T2>&, const pair<T1,T2>&);
89 template <class T1, class T2> bool operator> (const pair<T1,T2>&, const pair<T1,T2>&);
90 template <class T1, class T2> bool operator>=(const pair<T1,T2>&, const pair<T1,T2>&);
91 template <class T1, class T2> bool operator<=(const pair<T1,T2>&, const pair<T1,T2>&);
92 */
93
94
95 template <class T1, class T2>
96 struct pair
97 {
98 private:
99 BOOST_COPYABLE_AND_MOVABLE(pair)
100
101 public:
102 typedef T1 first_type;
103 typedef T2 second_type;
104
105 T1 first;
106 T2 second;
107
108 //Default constructor
109 pair()
110 : first(), second()
111 {}
112
113 //pair copy assignment
114 pair(const pair& x)
115 : first(x.first), second(x.second)
116 {}
117
118 //pair move constructor
119 pair(BOOST_RV_REF(pair) p)
120 : first(::boost::move(p.first)), second(::boost::move(p.second))
121 {}
122
123 template <class D, class S>
124 pair(const pair<D, S> &p)
125 : first(p.first), second(p.second)
126 {}
127
128 template <class D, class S>
129 pair(BOOST_RV_REF_BEG pair<D, S> BOOST_RV_REF_END p)
130 : first(::boost::move(p.first)), second(::boost::move(p.second))
131 {}
132
133 //pair from two values
134 pair(const T1 &t1, const T2 &t2)
135 : first(t1)
136 , second(t2)
137 {}
138
139 template<class U, class V>
140 pair(BOOST_FWD_REF(U) u, BOOST_FWD_REF(V) v)
141 : first(::boost::forward<U>(u))
142 , second(::boost::forward<V>(v))
143 {}
144
145 //And now compatibility with std::pair
146 pair(const std::pair<T1, T2>& x)
147 : first(x.first), second(x.second)
148 {}
149
150 template <class D, class S>
151 pair(const std::pair<D, S>& p)
152 : first(p.first), second(p.second)
153 {}
154
155 pair(BOOST_RV_REF_BEG std::pair<T1, T2> BOOST_RV_REF_END p)
156 : first(::boost::move(p.first)), second(::boost::move(p.second))
157 {}
158
159 template <class D, class S>
160 pair(BOOST_RV_REF_BEG std::pair<D, S> BOOST_RV_REF_END p)
161 : first(::boost::move(p.first)), second(::boost::move(p.second))
162 {}
163
164 //piecewise_construct missing
165 //template <class U, class V> pair(pair<U, V>&& p);
166 //template <class... Args1, class... Args2>
167 // pair(piecewise_construct_t, tuple<Args1...> first_args,
168 // tuple<Args2...> second_args);
169 /*
170 //Variadic versions
171 template<class U>
172 pair(BOOST_CONTAINER_PP_PARAM(U, u), typename container_detail::disable_if
173 < container_detail::is_pair< typename container_detail::remove_ref_const<U>::type >, pair_nat>::type* = 0)
174 : first(::boost::forward<U>(u))
175 , second()
176 {}
177
178 #ifdef BOOST_CONTAINER_PERFECT_FORWARDING
179
180 template<class U, class V, class ...Args>
181 pair(U &&u, V &&v)
182 : first(::boost::forward<U>(u))
183 , second(::boost::forward<V>(v), ::boost::forward<Args>(args)...)
184 {}
185
186 #else
187
188 #define BOOST_PP_LOCAL_MACRO(n) \
189 template<class U, BOOST_PP_ENUM_PARAMS(n, class P)> \
190 pair(BOOST_CONTAINER_PP_PARAM(U, u) \
191 ,BOOST_PP_ENUM(n, BOOST_CONTAINER_PP_PARAM_LIST, _)) \
192 : first(::boost::forward<U>(u)) \
193 , second(BOOST_PP_ENUM(n, BOOST_CONTAINER_PP_PARAM_FORWARD, _)) \
194 {} \
195 //!
196 #define BOOST_PP_LOCAL_LIMITS (1, BOOST_CONTAINER_MAX_CONSTRUCTOR_PARAMETERS)
197 #include BOOST_PP_LOCAL_ITERATE()
198 #endif
199 */
200 //pair copy assignment
201 pair& operator=(BOOST_COPY_ASSIGN_REF(pair) p)
202 {
203 first = p.first;
204 second = p.second;
205 return *this;
206 }
207
208 //pair move assignment
209 pair& operator=(BOOST_RV_REF(pair) p)
210 {
211 first = ::boost::move(p.first);
212 second = ::boost::move(p.second);
213 return *this;
214 }
215
216 template <class D, class S>
217 typename ::boost::container::container_detail::enable_if_c
218 < !(::boost::container::container_detail::is_same<T1, D>::value &&
219 ::boost::container::container_detail::is_same<T2, S>::value)
220 , pair &>::type
221 operator=(const pair<D, S>&p)
222 {
223 first = p.first;
224 second = p.second;
225 return *this;
226 }
227
228 template <class D, class S>
229 typename ::boost::container::container_detail::enable_if_c
230 < !(::boost::container::container_detail::is_same<T1, D>::value &&
231 ::boost::container::container_detail::is_same<T2, S>::value)
232 , pair &>::type
233 operator=(BOOST_RV_REF_BEG pair<D, S> BOOST_RV_REF_END p)
234 {
235 first = ::boost::move(p.first);
236 second = ::boost::move(p.second);
237 return *this;
238 }
239
240 //std::pair copy assignment
241 pair& operator=(const std::pair<T1, T2> &p)
242 {
243 first = p.first;
244 second = p.second;
245 return *this;
246 }
247
248 template <class D, class S>
249 pair& operator=(const std::pair<D, S> &p)
250 {
251 first = ::boost::move(p.first);
252 second = ::boost::move(p.second);
253 return *this;
254 }
255
256 //std::pair move assignment
257 pair& operator=(BOOST_RV_REF_BEG std::pair<T1, T2> BOOST_RV_REF_END p)
258 {
259 first = ::boost::move(p.first);
260 second = ::boost::move(p.second);
261 return *this;
262 }
263
264 template <class D, class S>
265 pair& operator=(BOOST_RV_REF_BEG std::pair<D, S> BOOST_RV_REF_END p)
266 {
267 first = ::boost::move(p.first);
268 second = ::boost::move(p.second);
269 return *this;
270 }
271
272 //swap
273 void swap(pair& p)
274 {
275 using std::swap;
276 swap(this->first, p.first);
277 swap(this->second, p.second);
278 }
279 };
280
281 template <class T1, class T2>
282 inline bool operator==(const pair<T1,T2>& x, const pair<T1,T2>& y)
283 { return static_cast<bool>(x.first == y.first && x.second == y.second); }
284
285 template <class T1, class T2>
286 inline bool operator< (const pair<T1,T2>& x, const pair<T1,T2>& y)
287 { return static_cast<bool>(x.first < y.first ||
288 (!(y.first < x.first) && x.second < y.second)); }
289
290 template <class T1, class T2>
291 inline bool operator!=(const pair<T1,T2>& x, const pair<T1,T2>& y)
292 { return static_cast<bool>(!(x == y)); }
293
294 template <class T1, class T2>
295 inline bool operator> (const pair<T1,T2>& x, const pair<T1,T2>& y)
296 { return y < x; }
297
298 template <class T1, class T2>
299 inline bool operator>=(const pair<T1,T2>& x, const pair<T1,T2>& y)
300 { return static_cast<bool>(!(x < y)); }
301
302 template <class T1, class T2>
303 inline bool operator<=(const pair<T1,T2>& x, const pair<T1,T2>& y)
304 { return static_cast<bool>(!(y < x)); }
305
306 template <class T1, class T2>
307 inline pair<T1, T2> make_pair(T1 x, T2 y)
308 { return pair<T1, T2>(x, y); }
309
310 template <class T1, class T2>
311 inline void swap(pair<T1, T2>& x, pair<T1, T2>& y)
312 {
313 swap(x.first, y.first);
314 swap(x.second, y.second);
315 }
316
317 } //namespace container_detail {
318 } //namespace container {
319
320
321 //Without this specialization recursive flat_(multi)map instantiation fails
322 //because is_enum needs to instantiate the recursive pair, leading to a compilation error).
323 //This breaks the cycle clearly stating that pair is not an enum avoiding any instantiation.
324 template<class T>
325 struct is_enum;
326
327 template<class T, class U>
328 struct is_enum< ::boost::container::container_detail::pair<T, U> >
329 {
330 static const bool value = false;
331 };
332
333 //This specialization is needed to avoid instantiation of pair in
334 //is_class, and allow recursive maps.
335 template <class T1, class T2>
336 struct is_class< ::boost::container::container_detail::pair<T1, T2> >
337 : public ::boost::true_type
338 {};
339
340 #ifdef BOOST_NO_CXX11_RVALUE_REFERENCES
341
342 template<class T1, class T2>
343 struct has_move_emulation_enabled< ::boost::container::container_detail::pair<T1, T2> >
344 : ::boost::true_type
345 {};
346
347 #endif
348
349
350 } //namespace boost {
351
352 #include <boost/container/detail/config_end.hpp>
353
354 #endif //#ifndef BOOST_CONTAINER_DETAIL_PAIR_HPP