1// class template tuple -*- C++ -*-
2
3// Copyright (C) 2004, 2005 Free Software Foundation, Inc.
4//
5// This file is part of the GNU ISO C++ Library.  This library is free
6// software; you can redistribute it and/or modify it under the
7// terms of the GNU General Public License as published by the
8// Free Software Foundation; either version 2, or (at your option)
9// any later version.
10
11// This library is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14// GNU General Public License for more details.
15
16// You should have received a copy of the GNU General Public License along
17// with this library; see the file COPYING.  If not, write to the Free
18// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19// USA.
20
21// As a special exception, you may use this file as part of a free software
22// library without restriction.  Specifically, if other files instantiate
23// templates or use macros or inline functions from this file, or you compile
24// this file and link it with other files to produce an executable, this
25// file does not by itself cause the resulting executable to be covered by
26// the GNU General Public License.  This exception does not however
27// invalidate any other reasons why the executable file might be covered by
28// the GNU General Public License.
29
30/** @file
31 *  This is an internal header file, included by other library headers.
32 *  You should not attempt to use it directly.
33 */
34
35// Chris Jefferson <chris@bubblescope.net>
36
37/// @brief class tuple_size
38template<_GLIBCXX_TEMPLATE_PARAMS>
39  struct tuple_size<tuple<_GLIBCXX_TEMPLATE_ARGS> >
40  { static const int value = _GLIBCXX_NUM_ARGS; };
41
42template<_GLIBCXX_TEMPLATE_PARAMS>
43#ifdef _GLIBCXX_LAST_INCLUDE
44  class tuple
45#else
46  class tuple<_GLIBCXX_TEMPLATE_ARGS>
47#endif
48  {
49    _GLIBCXX_BIND_MEMBERS
50
51  public:
52    tuple()
53    { }
54
55#if _GLIBCXX_NUM_ARGS == 2
56    template<typename _U1, typename _U2>
57      tuple(const std::pair<_U1, _U2>& __u) :
58      _M_arg1(__u.first), _M_arg2(__u.second)
59      { }
60
61    template<typename _U1, typename _U2>
62      tuple&
63      operator=(const std::pair<_U1, _U2>& __u)
64      {
65	_M_arg1 = __u.first;
66	_M_arg2 = __u.second;
67	return *this;
68      }
69#endif
70
71#if _GLIBCXX_NUM_ARGS > 0
72    explicit tuple(_GLIBCXX_TUPLE_ADD_CREF) :
73      _GLIBCXX_BIND_MEMBERS_INIT
74    { }
75
76    template<_GLIBCXX_TEMPLATE_PARAMS_U>
77      tuple(const tuple<_GLIBCXX_TEMPLATE_ARGS_U>& __in) :
78      _GLIBCXX_TUPLE_COPY_INIT
79    { }
80
81
82    template<_GLIBCXX_TEMPLATE_PARAMS_U>
83      tuple&
84      operator=(const tuple<_GLIBCXX_TEMPLATE_ARGS_U>& __in)
85      {
86        _GLIBCXX_TUPLE_ASSIGN
87        return *this;
88      }
89
90    tuple(const tuple& __in) :
91      _GLIBCXX_TUPLE_COPY_INIT
92    { }
93
94#else
95
96    tuple(const tuple&)
97    { }
98
99#endif
100
101    tuple&
102    operator=(const tuple& __in __attribute__((__unused__)) )
103    {
104      _GLIBCXX_TUPLE_ASSIGN
105        return *this;
106    }
107
108    template<int __i, typename __Type>
109      friend class __get_helper;
110
111    template<typename, typename, typename, typename, typename,
112             typename, typename, typename, typename, typename>
113      friend class tuple;
114  };
115
116#ifndef _GLIBCXX_LAST_INCLUDE
117
118template<typename _Tp>
119    struct __get_helper<_GLIBCXX_NUM_ARGS, _Tp>
120    {
121      static typename __add_ref<typename tuple_element<_GLIBCXX_NUM_ARGS,
122                                                       _Tp>::type>::type
123      get_value(_Tp& __in)
124      { return __in._GLIBCXX_CAT(_M_arg,_GLIBCXX_NUM_ARGS_PLUS_1); }
125
126      static typename __add_c_ref<typename tuple_element<_GLIBCXX_NUM_ARGS,
127                                                         _Tp>::type>::type
128      get_value(const _Tp& __in)
129      { return __in._GLIBCXX_CAT(_M_arg,_GLIBCXX_NUM_ARGS_PLUS_1); }
130    };
131
132/// @brief class tuple_element
133template<typename _T1, typename _T2, typename _T3, typename _T4,
134         typename _T5, typename _T6, typename _T7, typename _T8,
135         typename _T9, typename _T10>
136   struct tuple_element<_GLIBCXX_NUM_ARGS, tuple<_T1, _T2, _T3, _T4,
137                                                _T5, _T6, _T7, _T8, _T9,
138                                                _T10> >
139  { typedef _GLIBCXX_T_NUM_ARGS_PLUS_1 type; };
140
141#endif
142#if _GLIBCXX_NUM_ARGS == 0
143
144tuple<>
145inline make_tuple()
146{ return tuple<>(); }
147
148tuple<>
149inline tie()
150{ return tuple<>(); }
151#else
152
153template<_GLIBCXX_TEMPLATE_PARAMS>
154  typename __stripped_tuple_type<_GLIBCXX_TEMPLATE_ARGS>::__type
155  inline make_tuple(_GLIBCXX_PARAMS)
156  {
157    return typename __stripped_tuple_type<_GLIBCXX_TEMPLATE_ARGS>::
158      __type(_GLIBCXX_ARGS);
159  }
160
161template<_GLIBCXX_TEMPLATE_PARAMS>
162  tuple<_GLIBCXX_REF_TEMPLATE_ARGS>
163  inline tie(_GLIBCXX_REF_PARAMS)
164  { return make_tuple(_GLIBCXX_REF_WRAP_PARAMS); }
165#endif
166
167