fix doc example typo
[boost.git] / boost / tuple / detail / tuple_basic.hpp
blob348fd80894edd5d05ea602a0a9aa0e9f09f89920
1 // tuple_basic.hpp -----------------------------------------------------
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)
9 // For more information, see http://www.boost.org
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.
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 // -----------------------------------------------------------------
32 #ifndef BOOST_TUPLE_BASIC_HPP
33 #define BOOST_TUPLE_BASIC_HPP
36 #include <utility> // needed for the assignment from pair to tuple
38 #include "boost/type_traits/cv_traits.hpp"
39 #include "boost/type_traits/function_traits.hpp"
41 #include "boost/detail/workaround.hpp" // needed for BOOST_WORKAROUND
43 namespace boost {
44 namespace tuples {
46 // -- null_type --------------------------------------------------------
47 struct null_type {};
49 // a helper function to provide a const null_type type temporary
50 namespace detail {
51 inline const null_type cnull() { return null_type(); }
54 // -- if construct ------------------------------------------------
55 // Proposed by Krzysztof Czarnecki and Ulrich Eisenecker
57 template <bool If, class Then, class Else> struct IF { typedef Then RET; };
59 template <class Then, class Else> struct IF<false, Then, Else> {
60 typedef Else RET;
63 } // end detail
65 // - cons forward declaration -----------------------------------------------
66 template <class HT, class TT> struct cons;
69 // - tuple forward declaration -----------------------------------------------
70 template <
71 class T0 = null_type, class T1 = null_type, class T2 = null_type,
72 class T3 = null_type, class T4 = null_type, class T5 = null_type,
73 class T6 = null_type, class T7 = null_type, class T8 = null_type,
74 class T9 = null_type>
75 class tuple;
77 // tuple_length forward declaration
78 template<class T> struct length;
82 namespace detail {
84 // -- generate error template, referencing to non-existing members of this
85 // template is used to produce compilation errors intentionally
86 template<class T>
87 class generate_error;
89 // - cons getters --------------------------------------------------------
90 // called: get_class<N>::get<RETURN_TYPE>(aTuple)
92 template< int N >
93 struct get_class {
94 template<class RET, class HT, class TT >
95 inline static RET get(const cons<HT, TT>& t)
97 #if BOOST_WORKAROUND(__IBMCPP__,==600)
98 // vacpp 6.0 is not very consistent regarding the member template keyword
99 // Here it generates an error when the template keyword is used.
100 return get_class<N-1>::get<RET>(t.tail);
101 #else
102 return get_class<N-1>::BOOST_NESTED_TEMPLATE get<RET>(t.tail);
103 #endif
105 template<class RET, class HT, class TT >
106 inline static RET get(cons<HT, TT>& t)
108 #if BOOST_WORKAROUND(__IBMCPP__,==600)
109 return get_class<N-1>::get<RET>(t.tail);
110 #else
111 return get_class<N-1>::BOOST_NESTED_TEMPLATE get<RET>(t.tail);
112 #endif
116 template<>
117 struct get_class<0> {
118 template<class RET, class HT, class TT>
119 inline static RET get(const cons<HT, TT>& t)
121 return t.head;
123 template<class RET, class HT, class TT>
124 inline static RET get(cons<HT, TT>& t)
126 return t.head;
130 } // end of namespace detail
133 // -cons type accessors ----------------------------------------
134 // typename tuples::element<N,T>::type gets the type of the
135 // Nth element ot T, first element is at index 0
136 // -------------------------------------------------------
138 #ifndef BOOST_NO_CV_SPECIALIZATIONS
140 template<int N, class T>
141 struct element
143 private:
144 typedef typename T::tail_type Next;
145 public:
146 typedef typename element<N-1, Next>::type type;
148 template<class T>
149 struct element<0,T>
151 typedef typename T::head_type type;
154 template<int N, class T>
155 struct element<N, const T>
157 private:
158 typedef typename T::tail_type Next;
159 typedef typename element<N-1, Next>::type unqualified_type;
160 public:
161 #if BOOST_WORKAROUND(__BORLANDC__,<0x600)
162 typedef const unqualified_type type;
163 #else
164 typedef typename boost::add_const<unqualified_type>::type type;
165 #endif
168 template<class T>
169 struct element<0,const T>
171 #if BOOST_WORKAROUND(__BORLANDC__,<0x600)
172 typedef const typename T::head_type type;
173 #else
174 typedef typename boost::add_const<typename T::head_type>::type type;
175 #endif
178 #else // def BOOST_NO_CV_SPECIALIZATIONS
180 namespace detail {
182 template<int N, class T, bool IsConst>
183 struct element_impl
185 private:
186 typedef typename T::tail_type Next;
187 public:
188 typedef typename element_impl<N-1, Next, IsConst>::type type;
191 template<int N, class T>
192 struct element_impl<N, T, true /* IsConst */>
194 private:
195 typedef typename T::tail_type Next;
196 public:
197 typedef const typename element_impl<N-1, Next, true>::type type;
200 template<class T>
201 struct element_impl<0, T, false /* IsConst */>
203 typedef typename T::head_type type;
206 template<class T>
207 struct element_impl<0, T, true /* IsConst */>
209 typedef const typename T::head_type type;
212 } // end of namespace detail
215 template<int N, class T>
216 struct element:
217 public detail::element_impl<N, T, ::boost::is_const<T>::value>
221 #endif
224 // -get function templates -----------------------------------------------
225 // Usage: get<N>(aTuple)
227 // -- some traits classes for get functions
229 // access traits lifted from detail namespace to be part of the interface,
230 // (Joel de Guzman's suggestion). Rationale: get functions are part of the
231 // interface, so should the way to express their return types be.
233 template <class T> struct access_traits {
234 typedef const T& const_type;
235 typedef T& non_const_type;
237 typedef const typename boost::remove_cv<T>::type& parameter_type;
239 // used as the tuple constructors parameter types
240 // Rationale: non-reference tuple element types can be cv-qualified.
241 // It should be possible to initialize such types with temporaries,
242 // and when binding temporaries to references, the reference must
243 // be non-volatile and const. 8.5.3. (5)
246 template <class T> struct access_traits<T&> {
248 typedef T& const_type;
249 typedef T& non_const_type;
251 typedef T& parameter_type;
254 // get function for non-const cons-lists, returns a reference to the element
256 template<int N, class HT, class TT>
257 inline typename access_traits<
258 typename element<N, cons<HT, TT> >::type
259 >::non_const_type
260 get(cons<HT, TT>& c BOOST_APPEND_EXPLICIT_TEMPLATE_NON_TYPE(int, N)) {
261 #if BOOST_WORKAROUND(__IBMCPP__,==600 )
262 return detail::get_class<N>::
263 #else
264 return detail::get_class<N>::BOOST_NESTED_TEMPLATE
265 #endif
266 get<
267 typename access_traits<
268 typename element<N, cons<HT, TT> >::type
269 >::non_const_type,
270 HT,TT
271 >(c);
274 // get function for const cons-lists, returns a const reference to
275 // the element. If the element is a reference, returns the reference
276 // as such (that is, can return a non-const reference)
277 template<int N, class HT, class TT>
278 inline typename access_traits<
279 typename element<N, cons<HT, TT> >::type
280 >::const_type
281 get(const cons<HT, TT>& c BOOST_APPEND_EXPLICIT_TEMPLATE_NON_TYPE(int, N)) {
282 #if BOOST_WORKAROUND(__IBMCPP__,==600)
283 return detail::get_class<N>::
284 #else
285 return detail::get_class<N>::BOOST_NESTED_TEMPLATE
286 #endif
287 get<
288 typename access_traits<
289 typename element<N, cons<HT, TT> >::type
290 >::const_type,
291 HT,TT
292 >(c);
295 // -- the cons template --------------------------------------------------
296 namespace detail {
298 // These helper templates wrap void types and plain function types.
299 // The reationale is to allow one to write tuple types with those types
300 // as elements, even though it is not possible to instantiate such object.
301 // E.g: typedef tuple<void> some_type; // ok
302 // but: some_type x; // fails
304 template <class T> class non_storeable_type {
305 non_storeable_type();
308 template <class T> struct wrap_non_storeable_type {
309 typedef typename IF<
310 ::boost::is_function<T>::value, non_storeable_type<T>, T
311 >::RET type;
313 template <> struct wrap_non_storeable_type<void> {
314 typedef non_storeable_type<void> type;
317 } // detail
319 template <class HT, class TT>
320 struct cons {
322 typedef HT head_type;
323 typedef TT tail_type;
325 typedef typename
326 detail::wrap_non_storeable_type<head_type>::type stored_head_type;
328 stored_head_type head;
329 tail_type tail;
331 typename access_traits<stored_head_type>::non_const_type
332 get_head() { return head; }
334 typename access_traits<tail_type>::non_const_type
335 get_tail() { return tail; }
337 typename access_traits<stored_head_type>::const_type
338 get_head() const { return head; }
340 typename access_traits<tail_type>::const_type
341 get_tail() const { return tail; }
343 cons() : head(), tail() {}
344 // cons() : head(detail::default_arg<HT>::f()), tail() {}
346 // the argument for head is not strictly needed, but it prevents
347 // array type elements. This is good, since array type elements
348 // cannot be supported properly in any case (no assignment,
349 // copy works only if the tails are exactly the same type, ...)
351 cons(typename access_traits<stored_head_type>::parameter_type h,
352 const tail_type& t)
353 : head (h), tail(t) {}
355 template <class T1, class T2, class T3, class T4, class T5,
356 class T6, class T7, class T8, class T9, class T10>
357 cons( T1& t1, T2& t2, T3& t3, T4& t4, T5& t5,
358 T6& t6, T7& t7, T8& t8, T9& t9, T10& t10 )
359 : head (t1),
360 tail (t2, t3, t4, t5, t6, t7, t8, t9, t10, detail::cnull())
363 template <class T2, class T3, class T4, class T5,
364 class T6, class T7, class T8, class T9, class T10>
365 cons( const null_type& /*t1*/, T2& t2, T3& t3, T4& t4, T5& t5,
366 T6& t6, T7& t7, T8& t8, T9& t9, T10& t10 )
367 : head (),
368 tail (t2, t3, t4, t5, t6, t7, t8, t9, t10, detail::cnull())
372 template <class HT2, class TT2>
373 cons( const cons<HT2, TT2>& u ) : head(u.head), tail(u.tail) {}
375 template <class HT2, class TT2>
376 cons& operator=( const cons<HT2, TT2>& u ) {
377 head=u.head; tail=u.tail; return *this;
380 // must define assignment operator explicitly, implicit version is
381 // illformed if HT is a reference (12.8. (12))
382 cons& operator=(const cons& u) {
383 head = u.head; tail = u.tail; return *this;
386 template <class T1, class T2>
387 cons& operator=( const std::pair<T1, T2>& u ) {
388 BOOST_STATIC_ASSERT(length<cons>::value == 2); // check length = 2
389 head = u.first; tail.head = u.second; return *this;
392 // get member functions (non-const and const)
393 template <int N>
394 typename access_traits<
395 typename element<N, cons<HT, TT> >::type
396 >::non_const_type
397 get() {
398 return boost::tuples::get<N>(*this); // delegate to non-member get
401 template <int N>
402 typename access_traits<
403 typename element<N, cons<HT, TT> >::type
404 >::const_type
405 get() const {
406 return boost::tuples::get<N>(*this); // delegate to non-member get
410 template <class HT>
411 struct cons<HT, null_type> {
413 typedef HT head_type;
414 typedef null_type tail_type;
415 typedef cons<HT, null_type> self_type;
417 typedef typename
418 detail::wrap_non_storeable_type<head_type>::type stored_head_type;
419 stored_head_type head;
421 typename access_traits<stored_head_type>::non_const_type
422 get_head() { return head; }
424 null_type get_tail() { return null_type(); }
426 typename access_traits<stored_head_type>::const_type
427 get_head() const { return head; }
429 const null_type get_tail() const { return null_type(); }
431 // cons() : head(detail::default_arg<HT>::f()) {}
432 cons() : head() {}
434 cons(typename access_traits<stored_head_type>::parameter_type h,
435 const null_type& = null_type())
436 : head (h) {}
438 template<class T1>
439 cons(T1& t1, const null_type&, const null_type&, const null_type&,
440 const null_type&, const null_type&, const null_type&,
441 const null_type&, const null_type&, const null_type&)
442 : head (t1) {}
444 cons(const null_type&,
445 const null_type&, const null_type&, const null_type&,
446 const null_type&, const null_type&, const null_type&,
447 const null_type&, const null_type&, const null_type&)
448 : head () {}
450 template <class HT2>
451 cons( const cons<HT2, null_type>& u ) : head(u.head) {}
453 template <class HT2>
454 cons& operator=(const cons<HT2, null_type>& u )
455 { head = u.head; return *this; }
457 // must define assignment operator explicitely, implicit version
458 // is illformed if HT is a reference
459 cons& operator=(const cons& u) { head = u.head; return *this; }
461 template <int N>
462 typename access_traits<
463 typename element<N, self_type>::type
464 >::non_const_type
465 get(BOOST_EXPLICIT_TEMPLATE_NON_TYPE(int, N)) {
466 return boost::tuples::get<N>(*this);
469 template <int N>
470 typename access_traits<
471 typename element<N, self_type>::type
472 >::const_type
473 get(BOOST_EXPLICIT_TEMPLATE_NON_TYPE(int, N)) const {
474 return boost::tuples::get<N>(*this);
479 // templates for finding out the length of the tuple -------------------
481 template<class T>
482 struct length {
483 BOOST_STATIC_CONSTANT(int, value = 1 + length<typename T::tail_type>::value);
486 template<>
487 struct length<tuple<> > {
488 BOOST_STATIC_CONSTANT(int, value = 0);
491 template<>
492 struct length<tuple<> const> {
493 BOOST_STATIC_CONSTANT(int, value = 0);
496 template<>
497 struct length<null_type> {
498 BOOST_STATIC_CONSTANT(int, value = 0);
501 template<>
502 struct length<null_type const> {
503 BOOST_STATIC_CONSTANT(int, value = 0);
506 namespace detail {
508 // Tuple to cons mapper --------------------------------------------------
509 template <class T0, class T1, class T2, class T3, class T4,
510 class T5, class T6, class T7, class T8, class T9>
511 struct map_tuple_to_cons
513 typedef cons<T0,
514 typename map_tuple_to_cons<T1, T2, T3, T4, T5,
515 T6, T7, T8, T9, null_type>::type
516 > type;
519 // The empty tuple is a null_type
520 template <>
521 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>
523 typedef null_type type;
526 } // end detail
528 // -------------------------------------------------------------------
529 // -- tuple ------------------------------------------------------
530 template <class T0, class T1, class T2, class T3, class T4,
531 class T5, class T6, class T7, class T8, class T9>
533 class tuple :
534 public detail::map_tuple_to_cons<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>::type
536 public:
537 typedef typename
538 detail::map_tuple_to_cons<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>::type inherited;
539 typedef typename inherited::head_type head_type;
540 typedef typename inherited::tail_type tail_type;
543 // access_traits<T>::parameter_type takes non-reference types as const T&
544 tuple() {}
546 tuple(typename access_traits<T0>::parameter_type t0)
547 : inherited(t0, detail::cnull(), detail::cnull(), detail::cnull(),
548 detail::cnull(), detail::cnull(), detail::cnull(),
549 detail::cnull(), detail::cnull(), detail::cnull()) {}
551 tuple(typename access_traits<T0>::parameter_type t0,
552 typename access_traits<T1>::parameter_type t1)
553 : inherited(t0, t1, detail::cnull(), detail::cnull(),
554 detail::cnull(), detail::cnull(), detail::cnull(),
555 detail::cnull(), detail::cnull(), detail::cnull()) {}
557 tuple(typename access_traits<T0>::parameter_type t0,
558 typename access_traits<T1>::parameter_type t1,
559 typename access_traits<T2>::parameter_type t2)
560 : inherited(t0, t1, t2, detail::cnull(), detail::cnull(),
561 detail::cnull(), detail::cnull(), detail::cnull(),
562 detail::cnull(), detail::cnull()) {}
564 tuple(typename access_traits<T0>::parameter_type t0,
565 typename access_traits<T1>::parameter_type t1,
566 typename access_traits<T2>::parameter_type t2,
567 typename access_traits<T3>::parameter_type t3)
568 : inherited(t0, t1, t2, t3, detail::cnull(), detail::cnull(),
569 detail::cnull(), detail::cnull(), detail::cnull(),
570 detail::cnull()) {}
572 tuple(typename access_traits<T0>::parameter_type t0,
573 typename access_traits<T1>::parameter_type t1,
574 typename access_traits<T2>::parameter_type t2,
575 typename access_traits<T3>::parameter_type t3,
576 typename access_traits<T4>::parameter_type t4)
577 : inherited(t0, t1, t2, t3, t4, detail::cnull(), detail::cnull(),
578 detail::cnull(), detail::cnull(), detail::cnull()) {}
580 tuple(typename access_traits<T0>::parameter_type t0,
581 typename access_traits<T1>::parameter_type t1,
582 typename access_traits<T2>::parameter_type t2,
583 typename access_traits<T3>::parameter_type t3,
584 typename access_traits<T4>::parameter_type t4,
585 typename access_traits<T5>::parameter_type t5)
586 : inherited(t0, t1, t2, t3, t4, t5, detail::cnull(), detail::cnull(),
587 detail::cnull(), detail::cnull()) {}
589 tuple(typename access_traits<T0>::parameter_type t0,
590 typename access_traits<T1>::parameter_type t1,
591 typename access_traits<T2>::parameter_type t2,
592 typename access_traits<T3>::parameter_type t3,
593 typename access_traits<T4>::parameter_type t4,
594 typename access_traits<T5>::parameter_type t5,
595 typename access_traits<T6>::parameter_type t6)
596 : inherited(t0, t1, t2, t3, t4, t5, t6, detail::cnull(),
597 detail::cnull(), detail::cnull()) {}
599 tuple(typename access_traits<T0>::parameter_type t0,
600 typename access_traits<T1>::parameter_type t1,
601 typename access_traits<T2>::parameter_type t2,
602 typename access_traits<T3>::parameter_type t3,
603 typename access_traits<T4>::parameter_type t4,
604 typename access_traits<T5>::parameter_type t5,
605 typename access_traits<T6>::parameter_type t6,
606 typename access_traits<T7>::parameter_type t7)
607 : inherited(t0, t1, t2, t3, t4, t5, t6, t7, detail::cnull(),
608 detail::cnull()) {}
610 tuple(typename access_traits<T0>::parameter_type t0,
611 typename access_traits<T1>::parameter_type t1,
612 typename access_traits<T2>::parameter_type t2,
613 typename access_traits<T3>::parameter_type t3,
614 typename access_traits<T4>::parameter_type t4,
615 typename access_traits<T5>::parameter_type t5,
616 typename access_traits<T6>::parameter_type t6,
617 typename access_traits<T7>::parameter_type t7,
618 typename access_traits<T8>::parameter_type t8)
619 : inherited(t0, t1, t2, t3, t4, t5, t6, t7, t8, detail::cnull()) {}
621 tuple(typename access_traits<T0>::parameter_type t0,
622 typename access_traits<T1>::parameter_type t1,
623 typename access_traits<T2>::parameter_type t2,
624 typename access_traits<T3>::parameter_type t3,
625 typename access_traits<T4>::parameter_type t4,
626 typename access_traits<T5>::parameter_type t5,
627 typename access_traits<T6>::parameter_type t6,
628 typename access_traits<T7>::parameter_type t7,
629 typename access_traits<T8>::parameter_type t8,
630 typename access_traits<T9>::parameter_type t9)
631 : inherited(t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) {}
634 template<class U1, class U2>
635 tuple(const cons<U1, U2>& p) : inherited(p) {}
637 template <class U1, class U2>
638 tuple& operator=(const cons<U1, U2>& k) {
639 inherited::operator=(k);
640 return *this;
643 template <class U1, class U2>
644 tuple& operator=(const std::pair<U1, U2>& k) {
645 BOOST_STATIC_ASSERT(length<tuple>::value == 2);// check_length = 2
646 this->head = k.first;
647 this->tail.head = k.second;
648 return *this;
653 // The empty tuple
654 template <>
655 class tuple<null_type, null_type, null_type, null_type, null_type, null_type, null_type, null_type, null_type, null_type> :
656 public null_type
658 public:
659 typedef null_type inherited;
663 // Swallows any assignment (by Doug Gregor)
664 namespace detail {
666 struct swallow_assign {
668 template<typename T>
669 swallow_assign const& operator=(const T&) const {
670 return *this;
674 } // namespace detail
676 // "ignore" allows tuple positions to be ignored when using "tie".
677 detail::swallow_assign const ignore = detail::swallow_assign();
679 // ---------------------------------------------------------------------------
680 // The call_traits for make_tuple
681 // Honours the reference_wrapper class.
683 // Must be instantiated with plain or const plain types (not with references)
685 // from template<class T> foo(const T& t) : make_tuple_traits<const T>::type
686 // from template<class T> foo(T& t) : make_tuple_traits<T>::type
688 // Conversions:
689 // T -> T,
690 // references -> compile_time_error
691 // reference_wrapper<T> -> T&
692 // const reference_wrapper<T> -> T&
693 // array -> const ref array
696 template<class T>
697 struct make_tuple_traits {
698 typedef T type;
700 // commented away, see below (JJ)
701 // typedef typename IF<
702 // boost::is_function<T>::value,
703 // T&,
704 // T>::RET type;
708 // The is_function test was there originally for plain function types,
709 // which can't be stored as such (we must either store them as references or
710 // pointers). Such a type could be formed if make_tuple was called with a
711 // reference to a function.
712 // But this would mean that a const qualified function type was formed in
713 // the make_tuple function and hence make_tuple can't take a function
714 // reference as a parameter, and thus T can't be a function type.
715 // So is_function test was removed.
716 // (14.8.3. says that type deduction fails if a cv-qualified function type
717 // is created. (It only applies for the case of explicitly specifying template
718 // args, though?)) (JJ)
720 template<class T>
721 struct make_tuple_traits<T&> {
722 typedef typename
723 detail::generate_error<T&>::
724 do_not_use_with_reference_type error;
727 // Arrays can't be stored as plain types; convert them to references.
728 // All arrays are converted to const. This is because make_tuple takes its
729 // parameters as const T& and thus the knowledge of the potential
730 // non-constness of actual argument is lost.
731 template<class T, int n> struct make_tuple_traits <T[n]> {
732 typedef const T (&type)[n];
735 template<class T, int n>
736 struct make_tuple_traits<const T[n]> {
737 typedef const T (&type)[n];
740 template<class T, int n> struct make_tuple_traits<volatile T[n]> {
741 typedef const volatile T (&type)[n];
744 template<class T, int n>
745 struct make_tuple_traits<const volatile T[n]> {
746 typedef const volatile T (&type)[n];
749 template<class T>
750 struct make_tuple_traits<reference_wrapper<T> >{
751 typedef T& type;
754 template<class T>
755 struct make_tuple_traits<const reference_wrapper<T> >{
756 typedef T& type;
762 namespace detail {
764 // a helper traits to make the make_tuple functions shorter (Vesa Karvonen's
765 // suggestion)
766 template <
767 class T0 = null_type, class T1 = null_type, class T2 = null_type,
768 class T3 = null_type, class T4 = null_type, class T5 = null_type,
769 class T6 = null_type, class T7 = null_type, class T8 = null_type,
770 class T9 = null_type
772 struct make_tuple_mapper {
773 typedef
774 tuple<typename make_tuple_traits<T0>::type,
775 typename make_tuple_traits<T1>::type,
776 typename make_tuple_traits<T2>::type,
777 typename make_tuple_traits<T3>::type,
778 typename make_tuple_traits<T4>::type,
779 typename make_tuple_traits<T5>::type,
780 typename make_tuple_traits<T6>::type,
781 typename make_tuple_traits<T7>::type,
782 typename make_tuple_traits<T8>::type,
783 typename make_tuple_traits<T9>::type> type;
786 } // end detail
788 // -make_tuple function templates -----------------------------------
789 inline tuple<> make_tuple() {
790 return tuple<>();
793 template<class T0>
794 inline typename detail::make_tuple_mapper<T0>::type
795 make_tuple(const T0& t0) {
796 typedef typename detail::make_tuple_mapper<T0>::type t;
797 return t(t0);
800 template<class T0, class T1>
801 inline typename detail::make_tuple_mapper<T0, T1>::type
802 make_tuple(const T0& t0, const T1& t1) {
803 typedef typename detail::make_tuple_mapper<T0, T1>::type t;
804 return t(t0, t1);
807 template<class T0, class T1, class T2>
808 inline typename detail::make_tuple_mapper<T0, T1, T2>::type
809 make_tuple(const T0& t0, const T1& t1, const T2& t2) {
810 typedef typename detail::make_tuple_mapper<T0, T1, T2>::type t;
811 return t(t0, t1, t2);
814 template<class T0, class T1, class T2, class T3>
815 inline typename detail::make_tuple_mapper<T0, T1, T2, T3>::type
816 make_tuple(const T0& t0, const T1& t1, const T2& t2, const T3& t3) {
817 typedef typename detail::make_tuple_mapper<T0, T1, T2, T3>::type t;
818 return t(t0, t1, t2, t3);
821 template<class T0, class T1, class T2, class T3, class T4>
822 inline typename detail::make_tuple_mapper<T0, T1, T2, T3, T4>::type
823 make_tuple(const T0& t0, const T1& t1, const T2& t2, const T3& t3,
824 const T4& t4) {
825 typedef typename detail::make_tuple_mapper<T0, T1, T2, T3, T4>::type t;
826 return t(t0, t1, t2, t3, t4);
829 template<class T0, class T1, class T2, class T3, class T4, class T5>
830 inline typename detail::make_tuple_mapper<T0, T1, T2, T3, T4, T5>::type
831 make_tuple(const T0& t0, const T1& t1, const T2& t2, const T3& t3,
832 const T4& t4, const T5& t5) {
833 typedef typename detail::make_tuple_mapper<T0, T1, T2, T3, T4, T5>::type t;
834 return t(t0, t1, t2, t3, t4, t5);
837 template<class T0, class T1, class T2, class T3, class T4, class T5, class T6>
838 inline typename detail::make_tuple_mapper<T0, T1, T2, T3, T4, T5, T6>::type
839 make_tuple(const T0& t0, const T1& t1, const T2& t2, const T3& t3,
840 const T4& t4, const T5& t5, const T6& t6) {
841 typedef typename detail::make_tuple_mapper
842 <T0, T1, T2, T3, T4, T5, T6>::type t;
843 return t(t0, t1, t2, t3, t4, t5, t6);
846 template<class T0, class T1, class T2, class T3, class T4, class T5, class T6,
847 class T7>
848 inline typename detail::make_tuple_mapper<T0, T1, T2, T3, T4, T5, T6, T7>::type
849 make_tuple(const T0& t0, const T1& t1, const T2& t2, const T3& t3,
850 const T4& t4, const T5& t5, const T6& t6, const T7& t7) {
851 typedef typename detail::make_tuple_mapper
852 <T0, T1, T2, T3, T4, T5, T6, T7>::type t;
853 return t(t0, t1, t2, t3, t4, t5, t6, t7);
856 template<class T0, class T1, class T2, class T3, class T4, class T5, class T6,
857 class T7, class T8>
858 inline typename detail::make_tuple_mapper
859 <T0, T1, T2, T3, T4, T5, T6, T7, T8>::type
860 make_tuple(const T0& t0, const T1& t1, const T2& t2, const T3& t3,
861 const T4& t4, const T5& t5, const T6& t6, const T7& t7,
862 const T8& t8) {
863 typedef typename detail::make_tuple_mapper
864 <T0, T1, T2, T3, T4, T5, T6, T7, T8>::type t;
865 return t(t0, t1, t2, t3, t4, t5, t6, t7, t8);
868 template<class T0, class T1, class T2, class T3, class T4, class T5, class T6,
869 class T7, class T8, class T9>
870 inline typename detail::make_tuple_mapper
871 <T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>::type
872 make_tuple(const T0& t0, const T1& t1, const T2& t2, const T3& t3,
873 const T4& t4, const T5& t5, const T6& t6, const T7& t7,
874 const T8& t8, const T9& t9) {
875 typedef typename detail::make_tuple_mapper
876 <T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>::type t;
877 return t(t0, t1, t2, t3, t4, t5, t6, t7, t8, t9);
882 // Tie function templates -------------------------------------------------
883 template<class T1>
884 inline tuple<T1&> tie(T1& t1) {
885 return tuple<T1&> (t1);
888 template<class T1, class T2>
889 inline tuple<T1&, T2&> tie(T1& t1, T2& t2) {
890 return tuple<T1&, T2&> (t1, t2);
893 template<class T1, class T2, class T3>
894 inline tuple<T1&, T2&, T3&> tie(T1& t1, T2& t2, T3& t3) {
895 return tuple<T1&, T2&, T3&> (t1, t2, t3);
898 template<class T1, class T2, class T3, class T4>
899 inline tuple<T1&, T2&, T3&, T4&> tie(T1& t1, T2& t2, T3& t3, T4& t4) {
900 return tuple<T1&, T2&, T3&, T4&> (t1, t2, t3, t4);
903 template<class T1, class T2, class T3, class T4, class T5>
904 inline tuple<T1&, T2&, T3&, T4&, T5&>
905 tie(T1& t1, T2& t2, T3& t3, T4& t4, T5& t5) {
906 return tuple<T1&, T2&, T3&, T4&, T5&> (t1, t2, t3, t4, t5);
909 template<class T1, class T2, class T3, class T4, class T5, class T6>
910 inline tuple<T1&, T2&, T3&, T4&, T5&, T6&>
911 tie(T1& t1, T2& t2, T3& t3, T4& t4, T5& t5, T6& t6) {
912 return tuple<T1&, T2&, T3&, T4&, T5&, T6&> (t1, t2, t3, t4, t5, t6);
915 template<class T1, class T2, class T3, class T4, class T5, class T6, class T7>
916 inline tuple<T1&, T2&, T3&, T4&, T5&, T6&, T7&>
917 tie(T1& t1, T2& t2, T3& t3, T4& t4, T5& t5, T6& t6, T7& t7) {
918 return tuple<T1&, T2&, T3&, T4&, T5&, T6&, T7&> (t1, t2, t3, t4, t5, t6, t7);
921 template<class T1, class T2, class T3, class T4, class T5, class T6, class T7,
922 class T8>
923 inline tuple<T1&, T2&, T3&, T4&, T5&, T6&, T7&, T8&>
924 tie(T1& t1, T2& t2, T3& t3, T4& t4, T5& t5, T6& t6, T7& t7, T8& t8) {
925 return tuple<T1&, T2&, T3&, T4&, T5&, T6&, T7&, T8&>
926 (t1, t2, t3, t4, t5, t6, t7, t8);
929 template<class T1, class T2, class T3, class T4, class T5, class T6, class T7,
930 class T8, class T9>
931 inline tuple<T1&, T2&, T3&, T4&, T5&, T6&, T7&, T8&, T9&>
932 tie(T1& t1, T2& t2, T3& t3, T4& t4, T5& t5, T6& t6, T7& t7, T8& t8,
933 T9& t9) {
934 return tuple<T1&, T2&, T3&, T4&, T5&, T6&, T7&, T8&, T9&>
935 (t1, t2, t3, t4, t5, t6, t7, t8, t9);
938 template<class T1, class T2, class T3, class T4, class T5, class T6, class T7,
939 class T8, class T9, class T10>
940 inline tuple<T1&, T2&, T3&, T4&, T5&, T6&, T7&, T8&, T9&, T10&>
941 tie(T1& t1, T2& t2, T3& t3, T4& t4, T5& t5, T6& t6, T7& t7, T8& t8,
942 T9& t9, T10& t10) {
943 return tuple<T1&, T2&, T3&, T4&, T5&, T6&, T7&, T8&, T9&, T10&>
944 (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10);
947 } // end of namespace tuples
948 } // end of namespace boost
951 #endif // BOOST_TUPLE_BASIC_HPP