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

source code of boost/libs/tuple/include/boost/tuple/detail/tuple_basic.hpp