Chris@16
|
1 // tuple_basic.hpp -----------------------------------------------------
|
Chris@16
|
2
|
Chris@16
|
3 // Copyright (C) 1999, 2000 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
|
Chris@16
|
4 //
|
Chris@16
|
5 // Distributed under the Boost Software License, Version 1.0. (See
|
Chris@16
|
6 // accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
7 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
8
|
Chris@16
|
9 // For more information, see http://www.boost.org
|
Chris@16
|
10
|
Chris@16
|
11 // Outside help:
|
Chris@16
|
12 // This and that, Gary Powell.
|
Chris@16
|
13 // Fixed return types for get_head/get_tail
|
Chris@16
|
14 // ( and other bugs ) per suggestion of Jens Maurer
|
Chris@16
|
15 // simplified element type accessors + bug fix (Jeremy Siek)
|
Chris@16
|
16 // Several changes/additions according to suggestions by Douglas Gregor,
|
Chris@16
|
17 // William Kempf, Vesa Karvonen, John Max Skaller, Ed Brey, Beman Dawes,
|
Chris@16
|
18 // David Abrahams.
|
Chris@16
|
19
|
Chris@16
|
20 // Revision history:
|
Chris@16
|
21 // 2002 05 01 Hugo Duncan: Fix for Borland after Jaakko's previous changes
|
Chris@16
|
22 // 2002 04 18 Jaakko: tuple element types can be void or plain function
|
Chris@16
|
23 // types, as long as no object is created.
|
Chris@16
|
24 // Tuple objects can no hold even noncopyable types
|
Chris@16
|
25 // such as arrays.
|
Chris@16
|
26 // 2001 10 22 John Maddock
|
Chris@16
|
27 // Fixes for Borland C++
|
Chris@16
|
28 // 2001 08 30 David Abrahams
|
Chris@16
|
29 // Added default constructor for cons<>.
|
Chris@16
|
30 // -----------------------------------------------------------------
|
Chris@16
|
31
|
Chris@16
|
32 #ifndef BOOST_TUPLE_BASIC_HPP
|
Chris@16
|
33 #define BOOST_TUPLE_BASIC_HPP
|
Chris@16
|
34
|
Chris@16
|
35
|
Chris@16
|
36 #include <utility> // needed for the assignment from pair to tuple
|
Chris@16
|
37
|
Chris@16
|
38 #include "boost/type_traits/cv_traits.hpp"
|
Chris@16
|
39 #include "boost/type_traits/function_traits.hpp"
|
Chris@16
|
40 #include "boost/utility/swap.hpp"
|
Chris@16
|
41
|
Chris@16
|
42 #include "boost/detail/workaround.hpp" // needed for BOOST_WORKAROUND
|
Chris@16
|
43
|
Chris@101
|
44 #if BOOST_GCC >= 40700
|
Chris@101
|
45 #pragma GCC diagnostic push
|
Chris@101
|
46 #pragma GCC diagnostic ignored "-Wunused-local-typedefs"
|
Chris@101
|
47 #endif
|
Chris@101
|
48
|
Chris@16
|
49 namespace boost {
|
Chris@16
|
50 namespace tuples {
|
Chris@16
|
51
|
Chris@16
|
52 // -- null_type --------------------------------------------------------
|
Chris@16
|
53 struct null_type {};
|
Chris@16
|
54
|
Chris@16
|
55 // a helper function to provide a const null_type type temporary
|
Chris@16
|
56 namespace detail {
|
Chris@16
|
57 inline const null_type cnull() { return null_type(); }
|
Chris@16
|
58
|
Chris@16
|
59
|
Chris@16
|
60 // -- if construct ------------------------------------------------
|
Chris@16
|
61 // Proposed by Krzysztof Czarnecki and Ulrich Eisenecker
|
Chris@16
|
62
|
Chris@16
|
63 template <bool If, class Then, class Else> struct IF { typedef Then RET; };
|
Chris@16
|
64
|
Chris@16
|
65 template <class Then, class Else> struct IF<false, Then, Else> {
|
Chris@16
|
66 typedef Else RET;
|
Chris@16
|
67 };
|
Chris@16
|
68
|
Chris@16
|
69 } // end detail
|
Chris@16
|
70
|
Chris@16
|
71 // - cons forward declaration -----------------------------------------------
|
Chris@16
|
72 template <class HT, class TT> struct cons;
|
Chris@16
|
73
|
Chris@16
|
74
|
Chris@16
|
75 // - tuple forward declaration -----------------------------------------------
|
Chris@16
|
76 template <
|
Chris@16
|
77 class T0 = null_type, class T1 = null_type, class T2 = null_type,
|
Chris@16
|
78 class T3 = null_type, class T4 = null_type, class T5 = null_type,
|
Chris@16
|
79 class T6 = null_type, class T7 = null_type, class T8 = null_type,
|
Chris@16
|
80 class T9 = null_type>
|
Chris@16
|
81 class tuple;
|
Chris@16
|
82
|
Chris@16
|
83 // tuple_length forward declaration
|
Chris@16
|
84 template<class T> struct length;
|
Chris@16
|
85
|
Chris@16
|
86
|
Chris@16
|
87
|
Chris@16
|
88 namespace detail {
|
Chris@16
|
89
|
Chris@16
|
90 // -- generate error template, referencing to non-existing members of this
|
Chris@16
|
91 // template is used to produce compilation errors intentionally
|
Chris@16
|
92 template<class T>
|
Chris@16
|
93 class generate_error;
|
Chris@16
|
94
|
Chris@16
|
95 template<int N>
|
Chris@16
|
96 struct drop_front {
|
Chris@16
|
97 template<class Tuple>
|
Chris@16
|
98 struct apply {
|
Chris@16
|
99 typedef BOOST_DEDUCED_TYPENAME drop_front<N-1>::BOOST_NESTED_TEMPLATE
|
Chris@16
|
100 apply<Tuple> next;
|
Chris@16
|
101 typedef BOOST_DEDUCED_TYPENAME next::type::tail_type type;
|
Chris@16
|
102 static const type& call(const Tuple& tup) {
|
Chris@16
|
103 return next::call(tup).tail;
|
Chris@16
|
104 }
|
Chris@16
|
105 };
|
Chris@16
|
106 };
|
Chris@16
|
107
|
Chris@16
|
108 template<>
|
Chris@16
|
109 struct drop_front<0> {
|
Chris@16
|
110 template<class Tuple>
|
Chris@16
|
111 struct apply {
|
Chris@16
|
112 typedef Tuple type;
|
Chris@16
|
113 static const type& call(const Tuple& tup) {
|
Chris@16
|
114 return tup;
|
Chris@16
|
115 }
|
Chris@16
|
116 };
|
Chris@16
|
117 };
|
Chris@16
|
118
|
Chris@16
|
119 } // end of namespace detail
|
Chris@16
|
120
|
Chris@16
|
121
|
Chris@16
|
122 // -cons type accessors ----------------------------------------
|
Chris@16
|
123 // typename tuples::element<N,T>::type gets the type of the
|
Chris@16
|
124 // Nth element ot T, first element is at index 0
|
Chris@16
|
125 // -------------------------------------------------------
|
Chris@16
|
126
|
Chris@16
|
127 #ifndef BOOST_NO_CV_SPECIALIZATIONS
|
Chris@16
|
128
|
Chris@16
|
129 template<int N, class T>
|
Chris@16
|
130 struct element
|
Chris@16
|
131 {
|
Chris@16
|
132 typedef BOOST_DEDUCED_TYPENAME detail::drop_front<N>::BOOST_NESTED_TEMPLATE
|
Chris@16
|
133 apply<T>::type::head_type type;
|
Chris@16
|
134 };
|
Chris@16
|
135
|
Chris@16
|
136 template<int N, class T>
|
Chris@16
|
137 struct element<N, const T>
|
Chris@16
|
138 {
|
Chris@16
|
139 private:
|
Chris@16
|
140 typedef BOOST_DEDUCED_TYPENAME detail::drop_front<N>::BOOST_NESTED_TEMPLATE
|
Chris@16
|
141 apply<T>::type::head_type unqualified_type;
|
Chris@16
|
142 public:
|
Chris@16
|
143 #if BOOST_WORKAROUND(__BORLANDC__,<0x600)
|
Chris@16
|
144 typedef const unqualified_type type;
|
Chris@16
|
145 #else
|
Chris@16
|
146 typedef BOOST_DEDUCED_TYPENAME boost::add_const<unqualified_type>::type type;
|
Chris@16
|
147 #endif
|
Chris@16
|
148 };
|
Chris@16
|
149 #else // def BOOST_NO_CV_SPECIALIZATIONS
|
Chris@16
|
150
|
Chris@16
|
151 namespace detail {
|
Chris@16
|
152
|
Chris@16
|
153 template<int N, class T, bool IsConst>
|
Chris@16
|
154 struct element_impl
|
Chris@16
|
155 {
|
Chris@16
|
156 typedef BOOST_DEDUCED_TYPENAME detail::drop_front<N>::BOOST_NESTED_TEMPLATE
|
Chris@16
|
157 apply<T>::type::head_type type;
|
Chris@16
|
158 };
|
Chris@16
|
159
|
Chris@16
|
160 template<int N, class T>
|
Chris@16
|
161 struct element_impl<N, T, true /* IsConst */>
|
Chris@16
|
162 {
|
Chris@16
|
163 typedef BOOST_DEDUCED_TYPENAME detail::drop_front<N>::BOOST_NESTED_TEMPLATE
|
Chris@16
|
164 apply<T>::type::head_type unqualified_type;
|
Chris@16
|
165 typedef const unqualified_type type;
|
Chris@16
|
166 };
|
Chris@16
|
167
|
Chris@16
|
168 } // end of namespace detail
|
Chris@16
|
169
|
Chris@16
|
170
|
Chris@16
|
171 template<int N, class T>
|
Chris@16
|
172 struct element:
|
Chris@16
|
173 public detail::element_impl<N, T, ::boost::is_const<T>::value>
|
Chris@16
|
174 {
|
Chris@16
|
175 };
|
Chris@16
|
176
|
Chris@16
|
177 #endif
|
Chris@16
|
178
|
Chris@16
|
179
|
Chris@16
|
180 // -get function templates -----------------------------------------------
|
Chris@16
|
181 // Usage: get<N>(aTuple)
|
Chris@16
|
182
|
Chris@16
|
183 // -- some traits classes for get functions
|
Chris@16
|
184
|
Chris@16
|
185 // access traits lifted from detail namespace to be part of the interface,
|
Chris@16
|
186 // (Joel de Guzman's suggestion). Rationale: get functions are part of the
|
Chris@16
|
187 // interface, so should the way to express their return types be.
|
Chris@16
|
188
|
Chris@16
|
189 template <class T> struct access_traits {
|
Chris@16
|
190 typedef const T& const_type;
|
Chris@16
|
191 typedef T& non_const_type;
|
Chris@16
|
192
|
Chris@16
|
193 typedef const typename boost::remove_cv<T>::type& parameter_type;
|
Chris@16
|
194
|
Chris@16
|
195 // used as the tuple constructors parameter types
|
Chris@16
|
196 // Rationale: non-reference tuple element types can be cv-qualified.
|
Chris@16
|
197 // It should be possible to initialize such types with temporaries,
|
Chris@16
|
198 // and when binding temporaries to references, the reference must
|
Chris@16
|
199 // be non-volatile and const. 8.5.3. (5)
|
Chris@16
|
200 };
|
Chris@16
|
201
|
Chris@16
|
202 template <class T> struct access_traits<T&> {
|
Chris@16
|
203
|
Chris@16
|
204 typedef T& const_type;
|
Chris@16
|
205 typedef T& non_const_type;
|
Chris@16
|
206
|
Chris@16
|
207 typedef T& parameter_type;
|
Chris@16
|
208 };
|
Chris@16
|
209
|
Chris@16
|
210 // get function for non-const cons-lists, returns a reference to the element
|
Chris@16
|
211
|
Chris@16
|
212 template<int N, class HT, class TT>
|
Chris@16
|
213 inline typename access_traits<
|
Chris@16
|
214 typename element<N, cons<HT, TT> >::type
|
Chris@16
|
215 >::non_const_type
|
Chris@101
|
216 get(cons<HT, TT>& c) {
|
Chris@16
|
217 typedef BOOST_DEDUCED_TYPENAME detail::drop_front<N>::BOOST_NESTED_TEMPLATE
|
Chris@16
|
218 apply<cons<HT, TT> > impl;
|
Chris@16
|
219 typedef BOOST_DEDUCED_TYPENAME impl::type cons_element;
|
Chris@16
|
220 return const_cast<cons_element&>(impl::call(c)).head;
|
Chris@16
|
221 }
|
Chris@16
|
222
|
Chris@16
|
223 // get function for const cons-lists, returns a const reference to
|
Chris@16
|
224 // the element. If the element is a reference, returns the reference
|
Chris@16
|
225 // as such (that is, can return a non-const reference)
|
Chris@16
|
226 template<int N, class HT, class TT>
|
Chris@16
|
227 inline typename access_traits<
|
Chris@16
|
228 typename element<N, cons<HT, TT> >::type
|
Chris@16
|
229 >::const_type
|
Chris@101
|
230 get(const cons<HT, TT>& c) {
|
Chris@16
|
231 typedef BOOST_DEDUCED_TYPENAME detail::drop_front<N>::BOOST_NESTED_TEMPLATE
|
Chris@16
|
232 apply<cons<HT, TT> > impl;
|
Chris@16
|
233 return impl::call(c).head;
|
Chris@16
|
234 }
|
Chris@16
|
235
|
Chris@16
|
236 // -- the cons template --------------------------------------------------
|
Chris@16
|
237 namespace detail {
|
Chris@16
|
238
|
Chris@16
|
239 // These helper templates wrap void types and plain function types.
|
Chris@16
|
240 // The reationale is to allow one to write tuple types with those types
|
Chris@16
|
241 // as elements, even though it is not possible to instantiate such object.
|
Chris@16
|
242 // E.g: typedef tuple<void> some_type; // ok
|
Chris@16
|
243 // but: some_type x; // fails
|
Chris@16
|
244
|
Chris@16
|
245 template <class T> class non_storeable_type {
|
Chris@16
|
246 non_storeable_type();
|
Chris@16
|
247 };
|
Chris@16
|
248
|
Chris@16
|
249 template <class T> struct wrap_non_storeable_type {
|
Chris@16
|
250 typedef typename IF<
|
Chris@16
|
251 ::boost::is_function<T>::value, non_storeable_type<T>, T
|
Chris@16
|
252 >::RET type;
|
Chris@16
|
253 };
|
Chris@16
|
254 template <> struct wrap_non_storeable_type<void> {
|
Chris@16
|
255 typedef non_storeable_type<void> type;
|
Chris@16
|
256 };
|
Chris@16
|
257
|
Chris@16
|
258 } // detail
|
Chris@16
|
259
|
Chris@16
|
260 template <class HT, class TT>
|
Chris@16
|
261 struct cons {
|
Chris@16
|
262
|
Chris@16
|
263 typedef HT head_type;
|
Chris@16
|
264 typedef TT tail_type;
|
Chris@16
|
265
|
Chris@16
|
266 typedef typename
|
Chris@16
|
267 detail::wrap_non_storeable_type<head_type>::type stored_head_type;
|
Chris@16
|
268
|
Chris@16
|
269 stored_head_type head;
|
Chris@16
|
270 tail_type tail;
|
Chris@16
|
271
|
Chris@16
|
272 typename access_traits<stored_head_type>::non_const_type
|
Chris@16
|
273 get_head() { return head; }
|
Chris@16
|
274
|
Chris@16
|
275 typename access_traits<tail_type>::non_const_type
|
Chris@16
|
276 get_tail() { return tail; }
|
Chris@16
|
277
|
Chris@16
|
278 typename access_traits<stored_head_type>::const_type
|
Chris@16
|
279 get_head() const { return head; }
|
Chris@16
|
280
|
Chris@16
|
281 typename access_traits<tail_type>::const_type
|
Chris@16
|
282 get_tail() const { return tail; }
|
Chris@16
|
283
|
Chris@16
|
284 cons() : head(), tail() {}
|
Chris@16
|
285 // cons() : head(detail::default_arg<HT>::f()), tail() {}
|
Chris@16
|
286
|
Chris@16
|
287 // the argument for head is not strictly needed, but it prevents
|
Chris@16
|
288 // array type elements. This is good, since array type elements
|
Chris@16
|
289 // cannot be supported properly in any case (no assignment,
|
Chris@16
|
290 // copy works only if the tails are exactly the same type, ...)
|
Chris@16
|
291
|
Chris@16
|
292 cons(typename access_traits<stored_head_type>::parameter_type h,
|
Chris@16
|
293 const tail_type& t)
|
Chris@16
|
294 : head (h), tail(t) {}
|
Chris@16
|
295
|
Chris@16
|
296 template <class T1, class T2, class T3, class T4, class T5,
|
Chris@16
|
297 class T6, class T7, class T8, class T9, class T10>
|
Chris@16
|
298 cons( T1& t1, T2& t2, T3& t3, T4& t4, T5& t5,
|
Chris@16
|
299 T6& t6, T7& t7, T8& t8, T9& t9, T10& t10 )
|
Chris@16
|
300 : head (t1),
|
Chris@16
|
301 tail (t2, t3, t4, t5, t6, t7, t8, t9, t10, detail::cnull())
|
Chris@16
|
302 {}
|
Chris@16
|
303
|
Chris@16
|
304 template <class T2, class T3, class T4, class T5,
|
Chris@16
|
305 class T6, class T7, class T8, class T9, class T10>
|
Chris@16
|
306 cons( const null_type& /*t1*/, T2& t2, T3& t3, T4& t4, T5& t5,
|
Chris@16
|
307 T6& t6, T7& t7, T8& t8, T9& t9, T10& t10 )
|
Chris@16
|
308 : head (),
|
Chris@16
|
309 tail (t2, t3, t4, t5, t6, t7, t8, t9, t10, detail::cnull())
|
Chris@16
|
310 {}
|
Chris@16
|
311
|
Chris@16
|
312
|
Chris@16
|
313 template <class HT2, class TT2>
|
Chris@16
|
314 cons( const cons<HT2, TT2>& u ) : head(u.head), tail(u.tail) {}
|
Chris@16
|
315
|
Chris@16
|
316 template <class HT2, class TT2>
|
Chris@16
|
317 cons& operator=( const cons<HT2, TT2>& u ) {
|
Chris@16
|
318 head=u.head; tail=u.tail; return *this;
|
Chris@16
|
319 }
|
Chris@16
|
320
|
Chris@16
|
321 // must define assignment operator explicitly, implicit version is
|
Chris@16
|
322 // illformed if HT is a reference (12.8. (12))
|
Chris@16
|
323 cons& operator=(const cons& u) {
|
Chris@16
|
324 head = u.head; tail = u.tail; return *this;
|
Chris@16
|
325 }
|
Chris@16
|
326
|
Chris@16
|
327 template <class T1, class T2>
|
Chris@16
|
328 cons& operator=( const std::pair<T1, T2>& u ) {
|
Chris@16
|
329 BOOST_STATIC_ASSERT(length<cons>::value == 2); // check length = 2
|
Chris@16
|
330 head = u.first; tail.head = u.second; return *this;
|
Chris@16
|
331 }
|
Chris@16
|
332
|
Chris@16
|
333 // get member functions (non-const and const)
|
Chris@16
|
334 template <int N>
|
Chris@16
|
335 typename access_traits<
|
Chris@16
|
336 typename element<N, cons<HT, TT> >::type
|
Chris@16
|
337 >::non_const_type
|
Chris@16
|
338 get() {
|
Chris@16
|
339 return boost::tuples::get<N>(*this); // delegate to non-member get
|
Chris@16
|
340 }
|
Chris@16
|
341
|
Chris@16
|
342 template <int N>
|
Chris@16
|
343 typename access_traits<
|
Chris@16
|
344 typename element<N, cons<HT, TT> >::type
|
Chris@16
|
345 >::const_type
|
Chris@16
|
346 get() const {
|
Chris@16
|
347 return boost::tuples::get<N>(*this); // delegate to non-member get
|
Chris@16
|
348 }
|
Chris@16
|
349 };
|
Chris@16
|
350
|
Chris@16
|
351 template <class HT>
|
Chris@16
|
352 struct cons<HT, null_type> {
|
Chris@16
|
353
|
Chris@16
|
354 typedef HT head_type;
|
Chris@16
|
355 typedef null_type tail_type;
|
Chris@16
|
356 typedef cons<HT, null_type> self_type;
|
Chris@16
|
357
|
Chris@16
|
358 typedef typename
|
Chris@16
|
359 detail::wrap_non_storeable_type<head_type>::type stored_head_type;
|
Chris@16
|
360 stored_head_type head;
|
Chris@16
|
361
|
Chris@16
|
362 typename access_traits<stored_head_type>::non_const_type
|
Chris@16
|
363 get_head() { return head; }
|
Chris@16
|
364
|
Chris@16
|
365 null_type get_tail() { return null_type(); }
|
Chris@16
|
366
|
Chris@16
|
367 typename access_traits<stored_head_type>::const_type
|
Chris@16
|
368 get_head() const { return head; }
|
Chris@16
|
369
|
Chris@16
|
370 const null_type get_tail() const { return null_type(); }
|
Chris@16
|
371
|
Chris@16
|
372 // cons() : head(detail::default_arg<HT>::f()) {}
|
Chris@16
|
373 cons() : head() {}
|
Chris@16
|
374
|
Chris@16
|
375 cons(typename access_traits<stored_head_type>::parameter_type h,
|
Chris@16
|
376 const null_type& = null_type())
|
Chris@16
|
377 : head (h) {}
|
Chris@16
|
378
|
Chris@16
|
379 template<class T1>
|
Chris@16
|
380 cons(T1& t1, const null_type&, const null_type&, const null_type&,
|
Chris@16
|
381 const null_type&, const null_type&, const null_type&,
|
Chris@16
|
382 const null_type&, const null_type&, const null_type&)
|
Chris@16
|
383 : head (t1) {}
|
Chris@16
|
384
|
Chris@16
|
385 cons(const null_type&,
|
Chris@16
|
386 const null_type&, const null_type&, const null_type&,
|
Chris@16
|
387 const null_type&, const null_type&, const null_type&,
|
Chris@16
|
388 const null_type&, const null_type&, const null_type&)
|
Chris@16
|
389 : head () {}
|
Chris@16
|
390
|
Chris@16
|
391 template <class HT2>
|
Chris@16
|
392 cons( const cons<HT2, null_type>& u ) : head(u.head) {}
|
Chris@16
|
393
|
Chris@16
|
394 template <class HT2>
|
Chris@16
|
395 cons& operator=(const cons<HT2, null_type>& u )
|
Chris@16
|
396 { head = u.head; return *this; }
|
Chris@16
|
397
|
Chris@16
|
398 // must define assignment operator explicitely, implicit version
|
Chris@16
|
399 // is illformed if HT is a reference
|
Chris@16
|
400 cons& operator=(const cons& u) { head = u.head; return *this; }
|
Chris@16
|
401
|
Chris@16
|
402 template <int N>
|
Chris@16
|
403 typename access_traits<
|
Chris@16
|
404 typename element<N, self_type>::type
|
Chris@16
|
405 >::non_const_type
|
Chris@101
|
406 get() {
|
Chris@16
|
407 return boost::tuples::get<N>(*this);
|
Chris@16
|
408 }
|
Chris@16
|
409
|
Chris@16
|
410 template <int N>
|
Chris@16
|
411 typename access_traits<
|
Chris@16
|
412 typename element<N, self_type>::type
|
Chris@16
|
413 >::const_type
|
Chris@101
|
414 get() const {
|
Chris@16
|
415 return boost::tuples::get<N>(*this);
|
Chris@16
|
416 }
|
Chris@16
|
417
|
Chris@16
|
418 };
|
Chris@16
|
419
|
Chris@16
|
420 // templates for finding out the length of the tuple -------------------
|
Chris@16
|
421
|
Chris@16
|
422 template<class T>
|
Chris@16
|
423 struct length {
|
Chris@16
|
424 BOOST_STATIC_CONSTANT(int, value = 1 + length<typename T::tail_type>::value);
|
Chris@16
|
425 };
|
Chris@16
|
426
|
Chris@16
|
427 template<>
|
Chris@16
|
428 struct length<tuple<> > {
|
Chris@16
|
429 BOOST_STATIC_CONSTANT(int, value = 0);
|
Chris@16
|
430 };
|
Chris@16
|
431
|
Chris@16
|
432 template<>
|
Chris@16
|
433 struct length<tuple<> const> {
|
Chris@16
|
434 BOOST_STATIC_CONSTANT(int, value = 0);
|
Chris@16
|
435 };
|
Chris@16
|
436
|
Chris@16
|
437 template<>
|
Chris@16
|
438 struct length<null_type> {
|
Chris@16
|
439 BOOST_STATIC_CONSTANT(int, value = 0);
|
Chris@16
|
440 };
|
Chris@16
|
441
|
Chris@16
|
442 template<>
|
Chris@16
|
443 struct length<null_type const> {
|
Chris@16
|
444 BOOST_STATIC_CONSTANT(int, value = 0);
|
Chris@16
|
445 };
|
Chris@16
|
446
|
Chris@16
|
447 namespace detail {
|
Chris@16
|
448
|
Chris@16
|
449 // Tuple to cons mapper --------------------------------------------------
|
Chris@16
|
450 template <class T0, class T1, class T2, class T3, class T4,
|
Chris@16
|
451 class T5, class T6, class T7, class T8, class T9>
|
Chris@16
|
452 struct map_tuple_to_cons
|
Chris@16
|
453 {
|
Chris@16
|
454 typedef cons<T0,
|
Chris@16
|
455 typename map_tuple_to_cons<T1, T2, T3, T4, T5,
|
Chris@16
|
456 T6, T7, T8, T9, null_type>::type
|
Chris@16
|
457 > type;
|
Chris@16
|
458 };
|
Chris@16
|
459
|
Chris@16
|
460 // The empty tuple is a null_type
|
Chris@16
|
461 template <>
|
Chris@16
|
462 struct map_tuple_to_cons<null_type, null_type, null_type, null_type, null_type, null_type, null_type, null_type, null_type, null_type>
|
Chris@16
|
463 {
|
Chris@16
|
464 typedef null_type type;
|
Chris@16
|
465 };
|
Chris@16
|
466
|
Chris@16
|
467 } // end detail
|
Chris@16
|
468
|
Chris@16
|
469 // -------------------------------------------------------------------
|
Chris@16
|
470 // -- tuple ------------------------------------------------------
|
Chris@16
|
471 template <class T0, class T1, class T2, class T3, class T4,
|
Chris@16
|
472 class T5, class T6, class T7, class T8, class T9>
|
Chris@16
|
473
|
Chris@16
|
474 class tuple :
|
Chris@16
|
475 public detail::map_tuple_to_cons<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>::type
|
Chris@16
|
476 {
|
Chris@16
|
477 public:
|
Chris@16
|
478 typedef typename
|
Chris@16
|
479 detail::map_tuple_to_cons<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>::type inherited;
|
Chris@16
|
480 typedef typename inherited::head_type head_type;
|
Chris@16
|
481 typedef typename inherited::tail_type tail_type;
|
Chris@16
|
482
|
Chris@16
|
483
|
Chris@16
|
484 // access_traits<T>::parameter_type takes non-reference types as const T&
|
Chris@16
|
485 tuple() {}
|
Chris@16
|
486
|
Chris@16
|
487 tuple(typename access_traits<T0>::parameter_type t0)
|
Chris@16
|
488 : inherited(t0, detail::cnull(), detail::cnull(), detail::cnull(),
|
Chris@16
|
489 detail::cnull(), detail::cnull(), detail::cnull(),
|
Chris@16
|
490 detail::cnull(), detail::cnull(), detail::cnull()) {}
|
Chris@16
|
491
|
Chris@16
|
492 tuple(typename access_traits<T0>::parameter_type t0,
|
Chris@16
|
493 typename access_traits<T1>::parameter_type t1)
|
Chris@16
|
494 : inherited(t0, t1, detail::cnull(), detail::cnull(),
|
Chris@16
|
495 detail::cnull(), detail::cnull(), detail::cnull(),
|
Chris@16
|
496 detail::cnull(), detail::cnull(), detail::cnull()) {}
|
Chris@16
|
497
|
Chris@16
|
498 tuple(typename access_traits<T0>::parameter_type t0,
|
Chris@16
|
499 typename access_traits<T1>::parameter_type t1,
|
Chris@16
|
500 typename access_traits<T2>::parameter_type t2)
|
Chris@16
|
501 : inherited(t0, t1, t2, detail::cnull(), detail::cnull(),
|
Chris@16
|
502 detail::cnull(), detail::cnull(), detail::cnull(),
|
Chris@16
|
503 detail::cnull(), detail::cnull()) {}
|
Chris@16
|
504
|
Chris@16
|
505 tuple(typename access_traits<T0>::parameter_type t0,
|
Chris@16
|
506 typename access_traits<T1>::parameter_type t1,
|
Chris@16
|
507 typename access_traits<T2>::parameter_type t2,
|
Chris@16
|
508 typename access_traits<T3>::parameter_type t3)
|
Chris@16
|
509 : inherited(t0, t1, t2, t3, detail::cnull(), detail::cnull(),
|
Chris@16
|
510 detail::cnull(), detail::cnull(), detail::cnull(),
|
Chris@16
|
511 detail::cnull()) {}
|
Chris@16
|
512
|
Chris@16
|
513 tuple(typename access_traits<T0>::parameter_type t0,
|
Chris@16
|
514 typename access_traits<T1>::parameter_type t1,
|
Chris@16
|
515 typename access_traits<T2>::parameter_type t2,
|
Chris@16
|
516 typename access_traits<T3>::parameter_type t3,
|
Chris@16
|
517 typename access_traits<T4>::parameter_type t4)
|
Chris@16
|
518 : inherited(t0, t1, t2, t3, t4, detail::cnull(), detail::cnull(),
|
Chris@16
|
519 detail::cnull(), detail::cnull(), detail::cnull()) {}
|
Chris@16
|
520
|
Chris@16
|
521 tuple(typename access_traits<T0>::parameter_type t0,
|
Chris@16
|
522 typename access_traits<T1>::parameter_type t1,
|
Chris@16
|
523 typename access_traits<T2>::parameter_type t2,
|
Chris@16
|
524 typename access_traits<T3>::parameter_type t3,
|
Chris@16
|
525 typename access_traits<T4>::parameter_type t4,
|
Chris@16
|
526 typename access_traits<T5>::parameter_type t5)
|
Chris@16
|
527 : inherited(t0, t1, t2, t3, t4, t5, detail::cnull(), detail::cnull(),
|
Chris@16
|
528 detail::cnull(), detail::cnull()) {}
|
Chris@16
|
529
|
Chris@16
|
530 tuple(typename access_traits<T0>::parameter_type t0,
|
Chris@16
|
531 typename access_traits<T1>::parameter_type t1,
|
Chris@16
|
532 typename access_traits<T2>::parameter_type t2,
|
Chris@16
|
533 typename access_traits<T3>::parameter_type t3,
|
Chris@16
|
534 typename access_traits<T4>::parameter_type t4,
|
Chris@16
|
535 typename access_traits<T5>::parameter_type t5,
|
Chris@16
|
536 typename access_traits<T6>::parameter_type t6)
|
Chris@16
|
537 : inherited(t0, t1, t2, t3, t4, t5, t6, detail::cnull(),
|
Chris@16
|
538 detail::cnull(), detail::cnull()) {}
|
Chris@16
|
539
|
Chris@16
|
540 tuple(typename access_traits<T0>::parameter_type t0,
|
Chris@16
|
541 typename access_traits<T1>::parameter_type t1,
|
Chris@16
|
542 typename access_traits<T2>::parameter_type t2,
|
Chris@16
|
543 typename access_traits<T3>::parameter_type t3,
|
Chris@16
|
544 typename access_traits<T4>::parameter_type t4,
|
Chris@16
|
545 typename access_traits<T5>::parameter_type t5,
|
Chris@16
|
546 typename access_traits<T6>::parameter_type t6,
|
Chris@16
|
547 typename access_traits<T7>::parameter_type t7)
|
Chris@16
|
548 : inherited(t0, t1, t2, t3, t4, t5, t6, t7, detail::cnull(),
|
Chris@16
|
549 detail::cnull()) {}
|
Chris@16
|
550
|
Chris@16
|
551 tuple(typename access_traits<T0>::parameter_type t0,
|
Chris@16
|
552 typename access_traits<T1>::parameter_type t1,
|
Chris@16
|
553 typename access_traits<T2>::parameter_type t2,
|
Chris@16
|
554 typename access_traits<T3>::parameter_type t3,
|
Chris@16
|
555 typename access_traits<T4>::parameter_type t4,
|
Chris@16
|
556 typename access_traits<T5>::parameter_type t5,
|
Chris@16
|
557 typename access_traits<T6>::parameter_type t6,
|
Chris@16
|
558 typename access_traits<T7>::parameter_type t7,
|
Chris@16
|
559 typename access_traits<T8>::parameter_type t8)
|
Chris@16
|
560 : inherited(t0, t1, t2, t3, t4, t5, t6, t7, t8, detail::cnull()) {}
|
Chris@16
|
561
|
Chris@16
|
562 tuple(typename access_traits<T0>::parameter_type t0,
|
Chris@16
|
563 typename access_traits<T1>::parameter_type t1,
|
Chris@16
|
564 typename access_traits<T2>::parameter_type t2,
|
Chris@16
|
565 typename access_traits<T3>::parameter_type t3,
|
Chris@16
|
566 typename access_traits<T4>::parameter_type t4,
|
Chris@16
|
567 typename access_traits<T5>::parameter_type t5,
|
Chris@16
|
568 typename access_traits<T6>::parameter_type t6,
|
Chris@16
|
569 typename access_traits<T7>::parameter_type t7,
|
Chris@16
|
570 typename access_traits<T8>::parameter_type t8,
|
Chris@16
|
571 typename access_traits<T9>::parameter_type t9)
|
Chris@16
|
572 : inherited(t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) {}
|
Chris@16
|
573
|
Chris@16
|
574
|
Chris@16
|
575 template<class U1, class U2>
|
Chris@16
|
576 tuple(const cons<U1, U2>& p) : inherited(p) {}
|
Chris@16
|
577
|
Chris@16
|
578 template <class U1, class U2>
|
Chris@16
|
579 tuple& operator=(const cons<U1, U2>& k) {
|
Chris@16
|
580 inherited::operator=(k);
|
Chris@16
|
581 return *this;
|
Chris@16
|
582 }
|
Chris@16
|
583
|
Chris@16
|
584 template <class U1, class U2>
|
Chris@16
|
585 tuple& operator=(const std::pair<U1, U2>& k) {
|
Chris@16
|
586 BOOST_STATIC_ASSERT(length<tuple>::value == 2);// check_length = 2
|
Chris@16
|
587 this->head = k.first;
|
Chris@16
|
588 this->tail.head = k.second;
|
Chris@16
|
589 return *this;
|
Chris@16
|
590 }
|
Chris@16
|
591
|
Chris@16
|
592 };
|
Chris@16
|
593
|
Chris@16
|
594 // The empty tuple
|
Chris@16
|
595 template <>
|
Chris@16
|
596 class tuple<null_type, null_type, null_type, null_type, null_type, null_type, null_type, null_type, null_type, null_type> :
|
Chris@16
|
597 public null_type
|
Chris@16
|
598 {
|
Chris@16
|
599 public:
|
Chris@16
|
600 typedef null_type inherited;
|
Chris@16
|
601 };
|
Chris@16
|
602
|
Chris@16
|
603
|
Chris@16
|
604 // Swallows any assignment (by Doug Gregor)
|
Chris@16
|
605 namespace detail {
|
Chris@16
|
606
|
Chris@16
|
607 struct swallow_assign;
|
Chris@16
|
608 typedef void (detail::swallow_assign::*ignore_t)();
|
Chris@16
|
609 struct swallow_assign {
|
Chris@16
|
610 swallow_assign(ignore_t(*)(ignore_t)) {}
|
Chris@16
|
611 template<typename T>
|
Chris@16
|
612 swallow_assign const& operator=(const T&) const {
|
Chris@16
|
613 return *this;
|
Chris@16
|
614 }
|
Chris@16
|
615 };
|
Chris@16
|
616
|
Chris@16
|
617
|
Chris@16
|
618 } // namespace detail
|
Chris@16
|
619
|
Chris@16
|
620 // "ignore" allows tuple positions to be ignored when using "tie".
|
Chris@16
|
621 inline detail::ignore_t ignore(detail::ignore_t) { return 0; }
|
Chris@16
|
622
|
Chris@16
|
623 // ---------------------------------------------------------------------------
|
Chris@16
|
624 // The call_traits for make_tuple
|
Chris@16
|
625 // Honours the reference_wrapper class.
|
Chris@16
|
626
|
Chris@16
|
627 // Must be instantiated with plain or const plain types (not with references)
|
Chris@16
|
628
|
Chris@16
|
629 // from template<class T> foo(const T& t) : make_tuple_traits<const T>::type
|
Chris@16
|
630 // from template<class T> foo(T& t) : make_tuple_traits<T>::type
|
Chris@16
|
631
|
Chris@16
|
632 // Conversions:
|
Chris@16
|
633 // T -> T,
|
Chris@16
|
634 // references -> compile_time_error
|
Chris@16
|
635 // reference_wrapper<T> -> T&
|
Chris@16
|
636 // const reference_wrapper<T> -> T&
|
Chris@16
|
637 // array -> const ref array
|
Chris@16
|
638
|
Chris@16
|
639
|
Chris@16
|
640 template<class T>
|
Chris@16
|
641 struct make_tuple_traits {
|
Chris@16
|
642 typedef T type;
|
Chris@16
|
643
|
Chris@16
|
644 // commented away, see below (JJ)
|
Chris@16
|
645 // typedef typename IF<
|
Chris@16
|
646 // boost::is_function<T>::value,
|
Chris@16
|
647 // T&,
|
Chris@16
|
648 // T>::RET type;
|
Chris@16
|
649
|
Chris@16
|
650 };
|
Chris@16
|
651
|
Chris@16
|
652 // The is_function test was there originally for plain function types,
|
Chris@16
|
653 // which can't be stored as such (we must either store them as references or
|
Chris@16
|
654 // pointers). Such a type could be formed if make_tuple was called with a
|
Chris@16
|
655 // reference to a function.
|
Chris@16
|
656 // But this would mean that a const qualified function type was formed in
|
Chris@16
|
657 // the make_tuple function and hence make_tuple can't take a function
|
Chris@16
|
658 // reference as a parameter, and thus T can't be a function type.
|
Chris@16
|
659 // So is_function test was removed.
|
Chris@16
|
660 // (14.8.3. says that type deduction fails if a cv-qualified function type
|
Chris@16
|
661 // is created. (It only applies for the case of explicitly specifying template
|
Chris@16
|
662 // args, though?)) (JJ)
|
Chris@16
|
663
|
Chris@16
|
664 template<class T>
|
Chris@16
|
665 struct make_tuple_traits<T&> {
|
Chris@16
|
666 typedef typename
|
Chris@16
|
667 detail::generate_error<T&>::
|
Chris@16
|
668 do_not_use_with_reference_type error;
|
Chris@16
|
669 };
|
Chris@16
|
670
|
Chris@16
|
671 // Arrays can't be stored as plain types; convert them to references.
|
Chris@16
|
672 // All arrays are converted to const. This is because make_tuple takes its
|
Chris@16
|
673 // parameters as const T& and thus the knowledge of the potential
|
Chris@16
|
674 // non-constness of actual argument is lost.
|
Chris@16
|
675 template<class T, int n> struct make_tuple_traits <T[n]> {
|
Chris@16
|
676 typedef const T (&type)[n];
|
Chris@16
|
677 };
|
Chris@16
|
678
|
Chris@16
|
679 template<class T, int n>
|
Chris@16
|
680 struct make_tuple_traits<const T[n]> {
|
Chris@16
|
681 typedef const T (&type)[n];
|
Chris@16
|
682 };
|
Chris@16
|
683
|
Chris@16
|
684 template<class T, int n> struct make_tuple_traits<volatile T[n]> {
|
Chris@16
|
685 typedef const volatile T (&type)[n];
|
Chris@16
|
686 };
|
Chris@16
|
687
|
Chris@16
|
688 template<class T, int n>
|
Chris@16
|
689 struct make_tuple_traits<const volatile T[n]> {
|
Chris@16
|
690 typedef const volatile T (&type)[n];
|
Chris@16
|
691 };
|
Chris@16
|
692
|
Chris@16
|
693 template<class T>
|
Chris@16
|
694 struct make_tuple_traits<reference_wrapper<T> >{
|
Chris@16
|
695 typedef T& type;
|
Chris@16
|
696 };
|
Chris@16
|
697
|
Chris@16
|
698 template<class T>
|
Chris@16
|
699 struct make_tuple_traits<const reference_wrapper<T> >{
|
Chris@16
|
700 typedef T& type;
|
Chris@16
|
701 };
|
Chris@16
|
702
|
Chris@16
|
703 template<>
|
Chris@16
|
704 struct make_tuple_traits<detail::ignore_t(detail::ignore_t)> {
|
Chris@16
|
705 typedef detail::swallow_assign type;
|
Chris@16
|
706 };
|
Chris@16
|
707
|
Chris@16
|
708
|
Chris@16
|
709
|
Chris@16
|
710 namespace detail {
|
Chris@16
|
711
|
Chris@16
|
712 // a helper traits to make the make_tuple functions shorter (Vesa Karvonen's
|
Chris@16
|
713 // suggestion)
|
Chris@16
|
714 template <
|
Chris@16
|
715 class T0 = null_type, class T1 = null_type, class T2 = null_type,
|
Chris@16
|
716 class T3 = null_type, class T4 = null_type, class T5 = null_type,
|
Chris@16
|
717 class T6 = null_type, class T7 = null_type, class T8 = null_type,
|
Chris@16
|
718 class T9 = null_type
|
Chris@16
|
719 >
|
Chris@16
|
720 struct make_tuple_mapper {
|
Chris@16
|
721 typedef
|
Chris@16
|
722 tuple<typename make_tuple_traits<T0>::type,
|
Chris@16
|
723 typename make_tuple_traits<T1>::type,
|
Chris@16
|
724 typename make_tuple_traits<T2>::type,
|
Chris@16
|
725 typename make_tuple_traits<T3>::type,
|
Chris@16
|
726 typename make_tuple_traits<T4>::type,
|
Chris@16
|
727 typename make_tuple_traits<T5>::type,
|
Chris@16
|
728 typename make_tuple_traits<T6>::type,
|
Chris@16
|
729 typename make_tuple_traits<T7>::type,
|
Chris@16
|
730 typename make_tuple_traits<T8>::type,
|
Chris@16
|
731 typename make_tuple_traits<T9>::type> type;
|
Chris@16
|
732 };
|
Chris@16
|
733
|
Chris@16
|
734 } // end detail
|
Chris@16
|
735
|
Chris@16
|
736 // -make_tuple function templates -----------------------------------
|
Chris@16
|
737 inline tuple<> make_tuple() {
|
Chris@16
|
738 return tuple<>();
|
Chris@16
|
739 }
|
Chris@16
|
740
|
Chris@16
|
741 template<class T0>
|
Chris@16
|
742 inline typename detail::make_tuple_mapper<T0>::type
|
Chris@16
|
743 make_tuple(const T0& t0) {
|
Chris@16
|
744 typedef typename detail::make_tuple_mapper<T0>::type t;
|
Chris@16
|
745 return t(t0);
|
Chris@16
|
746 }
|
Chris@16
|
747
|
Chris@16
|
748 template<class T0, class T1>
|
Chris@16
|
749 inline typename detail::make_tuple_mapper<T0, T1>::type
|
Chris@16
|
750 make_tuple(const T0& t0, const T1& t1) {
|
Chris@16
|
751 typedef typename detail::make_tuple_mapper<T0, T1>::type t;
|
Chris@16
|
752 return t(t0, t1);
|
Chris@16
|
753 }
|
Chris@16
|
754
|
Chris@16
|
755 template<class T0, class T1, class T2>
|
Chris@16
|
756 inline typename detail::make_tuple_mapper<T0, T1, T2>::type
|
Chris@16
|
757 make_tuple(const T0& t0, const T1& t1, const T2& t2) {
|
Chris@16
|
758 typedef typename detail::make_tuple_mapper<T0, T1, T2>::type t;
|
Chris@16
|
759 return t(t0, t1, t2);
|
Chris@16
|
760 }
|
Chris@16
|
761
|
Chris@16
|
762 template<class T0, class T1, class T2, class T3>
|
Chris@16
|
763 inline typename detail::make_tuple_mapper<T0, T1, T2, T3>::type
|
Chris@16
|
764 make_tuple(const T0& t0, const T1& t1, const T2& t2, const T3& t3) {
|
Chris@16
|
765 typedef typename detail::make_tuple_mapper<T0, T1, T2, T3>::type t;
|
Chris@16
|
766 return t(t0, t1, t2, t3);
|
Chris@16
|
767 }
|
Chris@16
|
768
|
Chris@16
|
769 template<class T0, class T1, class T2, class T3, class T4>
|
Chris@16
|
770 inline typename detail::make_tuple_mapper<T0, T1, T2, T3, T4>::type
|
Chris@16
|
771 make_tuple(const T0& t0, const T1& t1, const T2& t2, const T3& t3,
|
Chris@16
|
772 const T4& t4) {
|
Chris@16
|
773 typedef typename detail::make_tuple_mapper<T0, T1, T2, T3, T4>::type t;
|
Chris@16
|
774 return t(t0, t1, t2, t3, t4);
|
Chris@16
|
775 }
|
Chris@16
|
776
|
Chris@16
|
777 template<class T0, class T1, class T2, class T3, class T4, class T5>
|
Chris@16
|
778 inline typename detail::make_tuple_mapper<T0, T1, T2, T3, T4, T5>::type
|
Chris@16
|
779 make_tuple(const T0& t0, const T1& t1, const T2& t2, const T3& t3,
|
Chris@16
|
780 const T4& t4, const T5& t5) {
|
Chris@16
|
781 typedef typename detail::make_tuple_mapper<T0, T1, T2, T3, T4, T5>::type t;
|
Chris@16
|
782 return t(t0, t1, t2, t3, t4, t5);
|
Chris@16
|
783 }
|
Chris@16
|
784
|
Chris@16
|
785 template<class T0, class T1, class T2, class T3, class T4, class T5, class T6>
|
Chris@16
|
786 inline typename detail::make_tuple_mapper<T0, T1, T2, T3, T4, T5, T6>::type
|
Chris@16
|
787 make_tuple(const T0& t0, const T1& t1, const T2& t2, const T3& t3,
|
Chris@16
|
788 const T4& t4, const T5& t5, const T6& t6) {
|
Chris@16
|
789 typedef typename detail::make_tuple_mapper
|
Chris@16
|
790 <T0, T1, T2, T3, T4, T5, T6>::type t;
|
Chris@16
|
791 return t(t0, t1, t2, t3, t4, t5, t6);
|
Chris@16
|
792 }
|
Chris@16
|
793
|
Chris@16
|
794 template<class T0, class T1, class T2, class T3, class T4, class T5, class T6,
|
Chris@16
|
795 class T7>
|
Chris@16
|
796 inline typename detail::make_tuple_mapper<T0, T1, T2, T3, T4, T5, T6, T7>::type
|
Chris@16
|
797 make_tuple(const T0& t0, const T1& t1, const T2& t2, const T3& t3,
|
Chris@16
|
798 const T4& t4, const T5& t5, const T6& t6, const T7& t7) {
|
Chris@16
|
799 typedef typename detail::make_tuple_mapper
|
Chris@16
|
800 <T0, T1, T2, T3, T4, T5, T6, T7>::type t;
|
Chris@16
|
801 return t(t0, t1, t2, t3, t4, t5, t6, t7);
|
Chris@16
|
802 }
|
Chris@16
|
803
|
Chris@16
|
804 template<class T0, class T1, class T2, class T3, class T4, class T5, class T6,
|
Chris@16
|
805 class T7, class T8>
|
Chris@16
|
806 inline typename detail::make_tuple_mapper
|
Chris@16
|
807 <T0, T1, T2, T3, T4, T5, T6, T7, T8>::type
|
Chris@16
|
808 make_tuple(const T0& t0, const T1& t1, const T2& t2, const T3& t3,
|
Chris@16
|
809 const T4& t4, const T5& t5, const T6& t6, const T7& t7,
|
Chris@16
|
810 const T8& t8) {
|
Chris@16
|
811 typedef typename detail::make_tuple_mapper
|
Chris@16
|
812 <T0, T1, T2, T3, T4, T5, T6, T7, T8>::type t;
|
Chris@16
|
813 return t(t0, t1, t2, t3, t4, t5, t6, t7, t8);
|
Chris@16
|
814 }
|
Chris@16
|
815
|
Chris@16
|
816 template<class T0, class T1, class T2, class T3, class T4, class T5, class T6,
|
Chris@16
|
817 class T7, class T8, class T9>
|
Chris@16
|
818 inline typename detail::make_tuple_mapper
|
Chris@16
|
819 <T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>::type
|
Chris@16
|
820 make_tuple(const T0& t0, const T1& t1, const T2& t2, const T3& t3,
|
Chris@16
|
821 const T4& t4, const T5& t5, const T6& t6, const T7& t7,
|
Chris@16
|
822 const T8& t8, const T9& t9) {
|
Chris@16
|
823 typedef typename detail::make_tuple_mapper
|
Chris@16
|
824 <T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>::type t;
|
Chris@16
|
825 return t(t0, t1, t2, t3, t4, t5, t6, t7, t8, t9);
|
Chris@16
|
826 }
|
Chris@16
|
827
|
Chris@16
|
828 namespace detail {
|
Chris@16
|
829
|
Chris@16
|
830 template<class T>
|
Chris@16
|
831 struct tie_traits {
|
Chris@16
|
832 typedef T& type;
|
Chris@16
|
833 };
|
Chris@16
|
834
|
Chris@16
|
835 template<>
|
Chris@16
|
836 struct tie_traits<ignore_t(ignore_t)> {
|
Chris@16
|
837 typedef swallow_assign type;
|
Chris@16
|
838 };
|
Chris@16
|
839
|
Chris@16
|
840 template<>
|
Chris@16
|
841 struct tie_traits<void> {
|
Chris@16
|
842 typedef null_type type;
|
Chris@16
|
843 };
|
Chris@16
|
844
|
Chris@16
|
845 template <
|
Chris@16
|
846 class T0 = void, class T1 = void, class T2 = void,
|
Chris@16
|
847 class T3 = void, class T4 = void, class T5 = void,
|
Chris@16
|
848 class T6 = void, class T7 = void, class T8 = void,
|
Chris@16
|
849 class T9 = void
|
Chris@16
|
850 >
|
Chris@16
|
851 struct tie_mapper {
|
Chris@16
|
852 typedef
|
Chris@16
|
853 tuple<typename tie_traits<T0>::type,
|
Chris@16
|
854 typename tie_traits<T1>::type,
|
Chris@16
|
855 typename tie_traits<T2>::type,
|
Chris@16
|
856 typename tie_traits<T3>::type,
|
Chris@16
|
857 typename tie_traits<T4>::type,
|
Chris@16
|
858 typename tie_traits<T5>::type,
|
Chris@16
|
859 typename tie_traits<T6>::type,
|
Chris@16
|
860 typename tie_traits<T7>::type,
|
Chris@16
|
861 typename tie_traits<T8>::type,
|
Chris@16
|
862 typename tie_traits<T9>::type> type;
|
Chris@16
|
863 };
|
Chris@16
|
864
|
Chris@16
|
865 }
|
Chris@16
|
866
|
Chris@16
|
867 // Tie function templates -------------------------------------------------
|
Chris@16
|
868 template<class T0>
|
Chris@16
|
869 inline typename detail::tie_mapper<T0>::type
|
Chris@16
|
870 tie(T0& t0) {
|
Chris@16
|
871 typedef typename detail::tie_mapper<T0>::type t;
|
Chris@16
|
872 return t(t0);
|
Chris@16
|
873 }
|
Chris@16
|
874
|
Chris@16
|
875 template<class T0, class T1>
|
Chris@16
|
876 inline typename detail::tie_mapper<T0, T1>::type
|
Chris@16
|
877 tie(T0& t0, T1& t1) {
|
Chris@16
|
878 typedef typename detail::tie_mapper<T0, T1>::type t;
|
Chris@16
|
879 return t(t0, t1);
|
Chris@16
|
880 }
|
Chris@16
|
881
|
Chris@16
|
882 template<class T0, class T1, class T2>
|
Chris@16
|
883 inline typename detail::tie_mapper<T0, T1, T2>::type
|
Chris@16
|
884 tie(T0& t0, T1& t1, T2& t2) {
|
Chris@16
|
885 typedef typename detail::tie_mapper<T0, T1, T2>::type t;
|
Chris@16
|
886 return t(t0, t1, t2);
|
Chris@16
|
887 }
|
Chris@16
|
888
|
Chris@16
|
889 template<class T0, class T1, class T2, class T3>
|
Chris@16
|
890 inline typename detail::tie_mapper<T0, T1, T2, T3>::type
|
Chris@16
|
891 tie(T0& t0, T1& t1, T2& t2, T3& t3) {
|
Chris@16
|
892 typedef typename detail::tie_mapper<T0, T1, T2, T3>::type t;
|
Chris@16
|
893 return t(t0, t1, t2, t3);
|
Chris@16
|
894 }
|
Chris@16
|
895
|
Chris@16
|
896 template<class T0, class T1, class T2, class T3, class T4>
|
Chris@16
|
897 inline typename detail::tie_mapper<T0, T1, T2, T3, T4>::type
|
Chris@16
|
898 tie(T0& t0, T1& t1, T2& t2, T3& t3,
|
Chris@16
|
899 T4& t4) {
|
Chris@16
|
900 typedef typename detail::tie_mapper<T0, T1, T2, T3, T4>::type t;
|
Chris@16
|
901 return t(t0, t1, t2, t3, t4);
|
Chris@16
|
902 }
|
Chris@16
|
903
|
Chris@16
|
904 template<class T0, class T1, class T2, class T3, class T4, class T5>
|
Chris@16
|
905 inline typename detail::tie_mapper<T0, T1, T2, T3, T4, T5>::type
|
Chris@16
|
906 tie(T0& t0, T1& t1, T2& t2, T3& t3,
|
Chris@16
|
907 T4& t4, T5& t5) {
|
Chris@16
|
908 typedef typename detail::tie_mapper<T0, T1, T2, T3, T4, T5>::type t;
|
Chris@16
|
909 return t(t0, t1, t2, t3, t4, t5);
|
Chris@16
|
910 }
|
Chris@16
|
911
|
Chris@16
|
912 template<class T0, class T1, class T2, class T3, class T4, class T5, class T6>
|
Chris@16
|
913 inline typename detail::tie_mapper<T0, T1, T2, T3, T4, T5, T6>::type
|
Chris@16
|
914 tie(T0& t0, T1& t1, T2& t2, T3& t3,
|
Chris@16
|
915 T4& t4, T5& t5, T6& t6) {
|
Chris@16
|
916 typedef typename detail::tie_mapper
|
Chris@16
|
917 <T0, T1, T2, T3, T4, T5, T6>::type t;
|
Chris@16
|
918 return t(t0, t1, t2, t3, t4, t5, t6);
|
Chris@16
|
919 }
|
Chris@16
|
920
|
Chris@16
|
921 template<class T0, class T1, class T2, class T3, class T4, class T5, class T6,
|
Chris@16
|
922 class T7>
|
Chris@16
|
923 inline typename detail::tie_mapper<T0, T1, T2, T3, T4, T5, T6, T7>::type
|
Chris@16
|
924 tie(T0& t0, T1& t1, T2& t2, T3& t3,
|
Chris@16
|
925 T4& t4, T5& t5, T6& t6, T7& t7) {
|
Chris@16
|
926 typedef typename detail::tie_mapper
|
Chris@16
|
927 <T0, T1, T2, T3, T4, T5, T6, T7>::type t;
|
Chris@16
|
928 return t(t0, t1, t2, t3, t4, t5, t6, t7);
|
Chris@16
|
929 }
|
Chris@16
|
930
|
Chris@16
|
931 template<class T0, class T1, class T2, class T3, class T4, class T5, class T6,
|
Chris@16
|
932 class T7, class T8>
|
Chris@16
|
933 inline typename detail::tie_mapper
|
Chris@16
|
934 <T0, T1, T2, T3, T4, T5, T6, T7, T8>::type
|
Chris@16
|
935 tie(T0& t0, T1& t1, T2& t2, T3& t3,
|
Chris@16
|
936 T4& t4, T5& t5, T6& t6, T7& t7,
|
Chris@16
|
937 T8& t8) {
|
Chris@16
|
938 typedef typename detail::tie_mapper
|
Chris@16
|
939 <T0, T1, T2, T3, T4, T5, T6, T7, T8>::type t;
|
Chris@16
|
940 return t(t0, t1, t2, t3, t4, t5, t6, t7, t8);
|
Chris@16
|
941 }
|
Chris@16
|
942
|
Chris@16
|
943 template<class T0, class T1, class T2, class T3, class T4, class T5, class T6,
|
Chris@16
|
944 class T7, class T8, class T9>
|
Chris@16
|
945 inline typename detail::tie_mapper
|
Chris@16
|
946 <T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>::type
|
Chris@16
|
947 tie(T0& t0, T1& t1, T2& t2, T3& t3,
|
Chris@16
|
948 T4& t4, T5& t5, T6& t6, T7& t7,
|
Chris@16
|
949 T8& t8, T9& t9) {
|
Chris@16
|
950 typedef typename detail::tie_mapper
|
Chris@16
|
951 <T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>::type t;
|
Chris@16
|
952 return t(t0, t1, t2, t3, t4, t5, t6, t7, t8, t9);
|
Chris@16
|
953 }
|
Chris@16
|
954
|
Chris@16
|
955 template <class T0, class T1, class T2, class T3, class T4,
|
Chris@16
|
956 class T5, class T6, class T7, class T8, class T9>
|
Chris@16
|
957 void swap(tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>& lhs,
|
Chris@16
|
958 tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>& rhs);
|
Chris@16
|
959 inline void swap(null_type&, null_type&) {}
|
Chris@16
|
960 template<class HH>
|
Chris@16
|
961 inline void swap(cons<HH, null_type>& lhs, cons<HH, null_type>& rhs) {
|
Chris@16
|
962 ::boost::swap(lhs.head, rhs.head);
|
Chris@16
|
963 }
|
Chris@16
|
964 template<class HH, class TT>
|
Chris@16
|
965 inline void swap(cons<HH, TT>& lhs, cons<HH, TT>& rhs) {
|
Chris@16
|
966 ::boost::swap(lhs.head, rhs.head);
|
Chris@16
|
967 ::boost::tuples::swap(lhs.tail, rhs.tail);
|
Chris@16
|
968 }
|
Chris@16
|
969 template <class T0, class T1, class T2, class T3, class T4,
|
Chris@16
|
970 class T5, class T6, class T7, class T8, class T9>
|
Chris@16
|
971 inline void swap(tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>& lhs,
|
Chris@16
|
972 tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>& rhs) {
|
Chris@16
|
973 typedef tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> tuple_type;
|
Chris@16
|
974 typedef typename tuple_type::inherited base;
|
Chris@16
|
975 ::boost::tuples::swap(static_cast<base&>(lhs), static_cast<base&>(rhs));
|
Chris@16
|
976 }
|
Chris@16
|
977
|
Chris@16
|
978 } // end of namespace tuples
|
Chris@16
|
979 } // end of namespace boost
|
Chris@16
|
980
|
Chris@16
|
981
|
Chris@101
|
982 #if BOOST_GCC >= 40700
|
Chris@101
|
983 #pragma GCC diagnostic pop
|
Chris@101
|
984 #endif
|
Chris@101
|
985
|
Chris@101
|
986
|
Chris@16
|
987 #endif // BOOST_TUPLE_BASIC_HPP
|
Chris@16
|
988
|
Chris@16
|
989
|