aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/include/tr1/tuple
blob: 89bccc3d495066063b0dc6895a176a6867a65d6f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
// class template tuple -*- C++ -*-

// Copyright (C) 2004, 2005 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING.  If not, write to the Free
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.

// As a special exception, you may use this file as part of a free software
// library without restriction.  Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License.  This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.

/** @file
*  This is a TR1 C++ Library header.
*/

// Chris Jefferson <chris@bubblescope.net>

#ifndef _TUPLE
#define _TUPLE 1

#include <tr1/utility>
#include <tr1/ref_fwd.h>

namespace std
{
namespace tr1
{
 // An implementation specific class which is used in the tuple class
 // when the tuple is not maximum possible size.
 struct _NullClass { };

 template<typename _Tp0 = _NullClass, typename _Tp1 = _NullClass,
          typename _Tp2 = _NullClass, typename _Tp3 = _NullClass,
          typename _Tp4 = _NullClass, typename _Tp5 = _NullClass,
          typename _Tp6 = _NullClass, typename _Tp7 = _NullClass,
          typename _Tp8 = _NullClass, typename _Tp9 = _NullClass>
   class tuple;

 /// Gives the type of the ith element of a given tuple type.
 template<int __i, typename _Tp>
   struct tuple_element;

 /// Finds the size of a given tuple type.
 template<typename _Tp>
   struct tuple_size;

 // Adds a const reference to a non-reference type.
 template<typename _Tp>
   struct __add_c_ref
   { typedef const _Tp& type; };

 template<typename _Tp>
   struct __add_c_ref<_Tp&>
   { typedef _Tp& type; };

 // Adds a reference to a non-reference type.
 template<typename _Tp>
   struct __add_ref
   { typedef _Tp& type; };

 template<typename _Tp>
   struct __add_ref<_Tp&>
   { typedef _Tp& type; };

 // Class used in the implementation of get
 template<int __i, typename _Tp>
   struct __get_helper;

 // Returns a const reference to the ith element of a tuple.
 // Any const or non-const ref elements are returned with their original type.
   template<int __i, typename _Tp0, typename _Tp1, typename _Tp2, typename _Tp3,
                   typename _Tp4, typename _Tp5, typename _Tp6, typename _Tp7,
                   typename _Tp8, typename _Tp9>
   typename __add_ref<typename tuple_element<__i, tuple<_Tp0, _Tp1, _Tp2,
                                                        _Tp3, _Tp4, _Tp5,
                                                        _Tp6, _Tp7, _Tp8,
                                                        _Tp9> >::type>::type
   get(tuple<_Tp0, _Tp1, _Tp2, _Tp3, _Tp4, _Tp5, _Tp6, _Tp7, _Tp8,
             _Tp9>& __t)
   {
     return __get_helper<__i, tuple<_Tp0, _Tp1, _Tp2, _Tp3, _Tp4, _Tp5, _Tp6,
                                    _Tp7, _Tp8, _Tp9> >::get_value(__t);
   }

 template<int __i, typename _Tp0, typename _Tp1, typename _Tp2, typename _Tp3,
                   typename _Tp4, typename _Tp5, typename _Tp6, typename _Tp7,
                   typename _Tp8, typename _Tp9>
   typename __add_c_ref<typename tuple_element<__i, tuple<_Tp0, _Tp1, _Tp2,
                                                          _Tp3, _Tp4, _Tp5,
                                                          _Tp6, _Tp7, _Tp8,
                                                          _Tp9> >::type>::type
   get(const tuple<_Tp0, _Tp1, _Tp2, _Tp3, _Tp4, _Tp5, _Tp6, _Tp7, _Tp8,
                   _Tp9>& __t)
   {
     return __get_helper<__i, tuple<_Tp0, _Tp1, _Tp2, _Tp3, _Tp4, _Tp5, _Tp6,
                                    _Tp7, _Tp8, _Tp9> >::get_value(__t);
   }

 // This class helps construct the various comparison operations on tuples
 template<int __check_equal_size, int __i, int __j, typename _Tp, typename _Up>
   struct __tuple_compare;

 template<int __i, int __j, typename _Tp, typename _Up>
   struct __tuple_compare<0, __i, __j, _Tp, _Up>
   {
     static bool __eq(const _Tp& __t, const _Up& __u)
     {
       return get<__i>(__t) == get<__i>(__u) &&
          __tuple_compare<0, __i+1, __j, _Tp, _Up>::__eq(__t, __u);
     }
     static bool __less(const _Tp& __t, const _Up& __u)
     {
       return (get<__i>(__t) < get<__i>(__u)) || !(get<__i>(__u) < get<__i>(__t)) &&
          __tuple_compare<0, __i+1, __j, _Tp, _Up>::__less(__t, __u);
     }
   };

 template<int __i, typename _Tp, typename _Up>
   struct __tuple_compare<0, __i, __i, _Tp, _Up>
   {
     static bool __eq(const _Tp&, const _Up&)
     { return true; }
     static bool __less(const _Tp&, const _Up&)
     { return false; }
   };

 template<typename _T1, typename _T2, typename _T3, typename _T4, typename _T5,
          typename _T6, typename _T7, typename _T8, typename _T9, typename _T10,
          typename _U1, typename _U2, typename _U3, typename _U4, typename _U5,
          typename _U6, typename _U7, typename _U8, typename _U9, typename _U10>
 bool
 operator==(const tuple<_T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, _T9, _T10>& __t,
            const tuple<_U1, _U2, _U3, _U4, _U5, _U6, _U7, _U8, _U9, _U10>& __u)
 {
   typedef tuple<_T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, _T9, _T10> _Tp;
   typedef tuple<_U1, _U2, _U3, _U4, _U5, _U6, _U7, _U8,_U9, _U10> _Up;
   return __tuple_compare<tuple_size<_Tp>::value - tuple_size<_Tp>::value, 0,
                          tuple_size<_Tp>::value, _Tp, _Up>::__eq(__t, __u);
 }

 template<typename _T1, typename _T2, typename _T3, typename _T4, typename _T5,
          typename _T6, typename _T7, typename _T8, typename _T9, typename _T10,
          typename _U1, typename _U2, typename _U3, typename _U4, typename _U5,
          typename _U6, typename _U7, typename _U8, typename _U9, typename _U10>
 bool
 operator<(const tuple<_T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, _T9, _T10>& __t,
           const tuple<_U1, _U2, _U3, _U4, _U5, _U6, _U7, _U8, _U9, _U10>& __u)
 {
   typedef tuple<_T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, _T9, _T10> _Tp;
   typedef tuple<_U1, _U2, _U3, _U4, _U5, _U6, _U7, _U8,_U9, _U10> _Up;
   return __tuple_compare<tuple_size<_Tp>::value - tuple_size<_Tp>::value, 0,
                          tuple_size<_Tp>::value, _Tp, _Up>::__less(__t, __u);
 }

 template<typename _T1, typename _T2, typename _T3, typename _T4, typename _T5,
          typename _T6, typename _T7, typename _T8, typename _T9, typename _T10,
          typename _U1, typename _U2, typename _U3, typename _U4, typename _U5,
          typename _U6, typename _U7, typename _U8, typename _U9, typename _U10>
 bool
 operator!=(const tuple<_T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, _T9, _T10>& __t,
            const tuple<_U1, _U2, _U3, _U4, _U5, _U6, _U7, _U8, _U9, _U10>& __u)
 { return !(__t == __u); }

 template<typename _T1, typename _T2, typename _T3, typename _T4, typename _T5,
          typename _T6, typename _T7, typename _T8, typename _T9, typename _T10,
          typename _U1, typename _U2, typename _U3, typename _U4, typename _U5,
          typename _U6, typename _U7, typename _U8, typename _U9, typename _U10>
 bool
 operator>(const tuple<_T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, _T9, _T10>& __t,
           const tuple<_U1, _U2, _U3, _U4, _U5, _U6, _U7, _U8, _U9, _U10>& __u)
 { return __u < __t; }

 template<typename _T1, typename _T2, typename _T3, typename _T4, typename _T5,
          typename _T6, typename _T7, typename _T8, typename _T9, typename _T10,
          typename _U1, typename _U2, typename _U3, typename _U4, typename _U5,
          typename _U6, typename _U7, typename _U8, typename _U9, typename _U10>
 bool
 operator<=(const tuple<_T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, _T9, _T10>& __t,
            const tuple<_U1, _U2, _U3, _U4, _U5, _U6, _U7, _U8, _U9, _U10>& __u)
 { return !(__u < __t); }

 template<typename _T1, typename _T2, typename _T3, typename _T4, typename _T5,
          typename _T6, typename _T7, typename _T8, typename _T9, typename _T10,
          typename _U1, typename _U2, typename _U3, typename _U4, typename _U5,
          typename _U6, typename _U7, typename _U8, typename _U9, typename _U10>
 bool
 operator>=(const tuple<_T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, _T9, _T10>& __t,
            const tuple<_U1, _U2, _U3, _U4, _U5, _U6, _U7, _U8, _U9, _U10>& __u)
 { return !(__t < __u); }

 // Helper which adds a reference to a type when given a reference_wrapper
 template<typename _Tp>
   struct __strip_reference_wrapper
   {
       typedef _Tp __type;
   };

 template<typename _Tp>
   struct __strip_reference_wrapper<reference_wrapper<_Tp> >
   {
     typedef _Tp& __type;
   };

 template<typename _Tp>
   struct __strip_reference_wrapper<const reference_wrapper<_Tp> >
   {
       typedef _Tp& __type;
   };

 template<typename _Tp0 = _NullClass, typename _Tp1 = _NullClass,
          typename _Tp2 = _NullClass, typename _Tp3 = _NullClass,
          typename _Tp4 = _NullClass, typename _Tp5 = _NullClass,
          typename _Tp6 = _NullClass, typename _Tp7 = _NullClass,
          typename _Tp8 = _NullClass, typename _Tp9 = _NullClass>
   struct __stripped_tuple_type
   {
     typedef tuple<typename __strip_reference_wrapper<_Tp0>::__type,
                   typename __strip_reference_wrapper<_Tp1>::__type,
                   typename __strip_reference_wrapper<_Tp2>::__type,
                   typename __strip_reference_wrapper<_Tp3>::__type,
                   typename __strip_reference_wrapper<_Tp4>::__type,
                   typename __strip_reference_wrapper<_Tp5>::__type,
                   typename __strip_reference_wrapper<_Tp6>::__type,
                   typename __strip_reference_wrapper<_Tp7>::__type,
                   typename __strip_reference_wrapper<_Tp8>::__type,
                   typename __strip_reference_wrapper<_Tp9>::__type>      __type;
   };

 // A class (and instance) which can be used in 'tie' when an element
 // of a tuple is not required
 struct swallow_assign
 {
   template<class T>
   swallow_assign&
     operator=(const T&)
     { return *this; }
 };

 // TODO: Put this in some kind of shared file.
 namespace
 {
   swallow_assign ignore;
 };

#define _GLIBCXX_CAT(x,y) _GLIBCXX_CAT2(x,y)
#define _GLIBCXX_CAT2(x,y) x##y
#define _SHORT_REPEAT
#define _GLIBCXX_REPEAT_HEADER <tr1/tuple_iterate.h>
#include <tr1/repeat.h>
#undef _GLIBCXX_REPEAT_HEADER
#undef _SHORT_REPEAT
}
}

#include <tr1/functional>

#endif