Initial import of binutils 2.22 on the new vendor branch
[dragonfly.git] / contrib / gcc-4.1 / libstdc++-v3 / include / tr1 / tuple
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 a TR1 C++ Library header.
32 */
33
34 // Chris Jefferson <chris@bubblescope.net>
35
36 #ifndef _TUPLE
37 #define _TUPLE 1
38
39 #include <tr1/utility>
40 #include <tr1/ref_fwd.h>
41
42 namespace std
43 {
44 namespace tr1
45 {
46  // An implementation specific class which is used in the tuple class
47  // when the tuple is not maximum possible size.
48  struct _NullClass { };
49
50  template<typename _Tp0 = _NullClass, typename _Tp1 = _NullClass,
51           typename _Tp2 = _NullClass, typename _Tp3 = _NullClass,
52           typename _Tp4 = _NullClass, typename _Tp5 = _NullClass,
53           typename _Tp6 = _NullClass, typename _Tp7 = _NullClass,
54           typename _Tp8 = _NullClass, typename _Tp9 = _NullClass>
55    class tuple;
56
57  /// Gives the type of the ith element of a given tuple type.
58  template<int __i, typename _Tp>
59    struct tuple_element;
60
61  /// Finds the size of a given tuple type.
62  template<typename _Tp>
63    struct tuple_size;
64
65  // Adds a const reference to a non-reference type.
66  template<typename _Tp>
67    struct __add_c_ref
68    { typedef const _Tp& type; };
69
70  template<typename _Tp>
71    struct __add_c_ref<_Tp&>
72    { typedef _Tp& type; };
73
74  // Adds a reference to a non-reference type.
75  template<typename _Tp>
76    struct __add_ref
77    { typedef _Tp& type; };
78
79  template<typename _Tp>
80    struct __add_ref<_Tp&>
81    { typedef _Tp& type; };
82
83  // Class used in the implementation of get
84  template<int __i, typename _Tp>
85    struct __get_helper;
86
87  // Returns a const reference to the ith element of a tuple.
88  // Any const or non-const ref elements are returned with their original type.
89    template<int __i, typename _Tp0, typename _Tp1, typename _Tp2, typename _Tp3,
90                    typename _Tp4, typename _Tp5, typename _Tp6, typename _Tp7,
91                    typename _Tp8, typename _Tp9>
92    typename __add_ref<typename tuple_element<__i, tuple<_Tp0, _Tp1, _Tp2,
93                                                         _Tp3, _Tp4, _Tp5,
94                                                         _Tp6, _Tp7, _Tp8,
95                                                         _Tp9> >::type>::type
96    get(tuple<_Tp0, _Tp1, _Tp2, _Tp3, _Tp4, _Tp5, _Tp6, _Tp7, _Tp8,
97              _Tp9>& __t)
98    {
99      return __get_helper<__i, tuple<_Tp0, _Tp1, _Tp2, _Tp3, _Tp4, _Tp5, _Tp6,
100                                     _Tp7, _Tp8, _Tp9> >::get_value(__t);
101    }
102
103  template<int __i, typename _Tp0, typename _Tp1, typename _Tp2, typename _Tp3,
104                    typename _Tp4, typename _Tp5, typename _Tp6, typename _Tp7,
105                    typename _Tp8, typename _Tp9>
106    typename __add_c_ref<typename tuple_element<__i, tuple<_Tp0, _Tp1, _Tp2,
107                                                           _Tp3, _Tp4, _Tp5,
108                                                           _Tp6, _Tp7, _Tp8,
109                                                           _Tp9> >::type>::type
110    get(const tuple<_Tp0, _Tp1, _Tp2, _Tp3, _Tp4, _Tp5, _Tp6, _Tp7, _Tp8,
111                    _Tp9>& __t)
112    {
113      return __get_helper<__i, tuple<_Tp0, _Tp1, _Tp2, _Tp3, _Tp4, _Tp5, _Tp6,
114                                     _Tp7, _Tp8, _Tp9> >::get_value(__t);
115    }
116
117  // This class helps construct the various comparison operations on tuples
118  template<int __check_equal_size, int __i, int __j, typename _Tp, typename _Up>
119    struct __tuple_compare;
120
121  template<int __i, int __j, typename _Tp, typename _Up>
122    struct __tuple_compare<0, __i, __j, _Tp, _Up>
123    {
124      static bool __eq(const _Tp& __t, const _Up& __u)
125      {
126        return get<__i>(__t) == get<__i>(__u) &&
127           __tuple_compare<0, __i+1, __j, _Tp, _Up>::__eq(__t, __u);
128      }
129      static bool __less(const _Tp& __t, const _Up& __u)
130      {
131        return (get<__i>(__t) < get<__i>(__u)) || !(get<__i>(__u) < get<__i>(__t)) &&
132           __tuple_compare<0, __i+1, __j, _Tp, _Up>::__less(__t, __u);
133      }
134    };
135
136  template<int __i, typename _Tp, typename _Up>
137    struct __tuple_compare<0, __i, __i, _Tp, _Up>
138    {
139      static bool __eq(const _Tp&, const _Up&)
140      { return true; }
141      static bool __less(const _Tp&, const _Up&)
142      { return false; }
143    };
144
145  template<typename _T1, typename _T2, typename _T3, typename _T4, typename _T5,
146           typename _T6, typename _T7, typename _T8, typename _T9, typename _T10,
147           typename _U1, typename _U2, typename _U3, typename _U4, typename _U5,
148           typename _U6, typename _U7, typename _U8, typename _U9, typename _U10>
149  bool
150  operator==(const tuple<_T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, _T9, _T10>& __t,
151             const tuple<_U1, _U2, _U3, _U4, _U5, _U6, _U7, _U8, _U9, _U10>& __u)
152  {
153    typedef tuple<_T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, _T9, _T10> _Tp;
154    typedef tuple<_U1, _U2, _U3, _U4, _U5, _U6, _U7, _U8,_U9, _U10> _Up;
155    return __tuple_compare<tuple_size<_Tp>::value - tuple_size<_Tp>::value, 0,
156                           tuple_size<_Tp>::value, _Tp, _Up>::__eq(__t, __u);
157  }
158
159  template<typename _T1, typename _T2, typename _T3, typename _T4, typename _T5,
160           typename _T6, typename _T7, typename _T8, typename _T9, typename _T10,
161           typename _U1, typename _U2, typename _U3, typename _U4, typename _U5,
162           typename _U6, typename _U7, typename _U8, typename _U9, typename _U10>
163  bool
164  operator<(const tuple<_T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, _T9, _T10>& __t,
165            const tuple<_U1, _U2, _U3, _U4, _U5, _U6, _U7, _U8, _U9, _U10>& __u)
166  {
167    typedef tuple<_T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, _T9, _T10> _Tp;
168    typedef tuple<_U1, _U2, _U3, _U4, _U5, _U6, _U7, _U8,_U9, _U10> _Up;
169    return __tuple_compare<tuple_size<_Tp>::value - tuple_size<_Tp>::value, 0,
170                           tuple_size<_Tp>::value, _Tp, _Up>::__less(__t, __u);
171  }
172
173  template<typename _T1, typename _T2, typename _T3, typename _T4, typename _T5,
174           typename _T6, typename _T7, typename _T8, typename _T9, typename _T10,
175           typename _U1, typename _U2, typename _U3, typename _U4, typename _U5,
176           typename _U6, typename _U7, typename _U8, typename _U9, typename _U10>
177  bool
178  operator!=(const tuple<_T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, _T9, _T10>& __t,
179             const tuple<_U1, _U2, _U3, _U4, _U5, _U6, _U7, _U8, _U9, _U10>& __u)
180  { return !(__t == __u); }
181
182  template<typename _T1, typename _T2, typename _T3, typename _T4, typename _T5,
183           typename _T6, typename _T7, typename _T8, typename _T9, typename _T10,
184           typename _U1, typename _U2, typename _U3, typename _U4, typename _U5,
185           typename _U6, typename _U7, typename _U8, typename _U9, typename _U10>
186  bool
187  operator>(const tuple<_T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, _T9, _T10>& __t,
188            const tuple<_U1, _U2, _U3, _U4, _U5, _U6, _U7, _U8, _U9, _U10>& __u)
189  { return __u < __t; }
190
191  template<typename _T1, typename _T2, typename _T3, typename _T4, typename _T5,
192           typename _T6, typename _T7, typename _T8, typename _T9, typename _T10,
193           typename _U1, typename _U2, typename _U3, typename _U4, typename _U5,
194           typename _U6, typename _U7, typename _U8, typename _U9, typename _U10>
195  bool
196  operator<=(const tuple<_T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, _T9, _T10>& __t,
197             const tuple<_U1, _U2, _U3, _U4, _U5, _U6, _U7, _U8, _U9, _U10>& __u)
198  { return !(__u < __t); }
199
200  template<typename _T1, typename _T2, typename _T3, typename _T4, typename _T5,
201           typename _T6, typename _T7, typename _T8, typename _T9, typename _T10,
202           typename _U1, typename _U2, typename _U3, typename _U4, typename _U5,
203           typename _U6, typename _U7, typename _U8, typename _U9, typename _U10>
204  bool
205  operator>=(const tuple<_T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, _T9, _T10>& __t,
206             const tuple<_U1, _U2, _U3, _U4, _U5, _U6, _U7, _U8, _U9, _U10>& __u)
207  { return !(__t < __u); }
208
209  // Helper which adds a reference to a type when given a reference_wrapper
210  template<typename _Tp>
211    struct __strip_reference_wrapper
212    {
213        typedef _Tp __type;
214    };
215
216  template<typename _Tp>
217    struct __strip_reference_wrapper<reference_wrapper<_Tp> >
218    {
219      typedef _Tp& __type;
220    };
221
222  template<typename _Tp>
223    struct __strip_reference_wrapper<const reference_wrapper<_Tp> >
224    {
225        typedef _Tp& __type;
226    };
227
228  template<typename _Tp0 = _NullClass, typename _Tp1 = _NullClass,
229           typename _Tp2 = _NullClass, typename _Tp3 = _NullClass,
230           typename _Tp4 = _NullClass, typename _Tp5 = _NullClass,
231           typename _Tp6 = _NullClass, typename _Tp7 = _NullClass,
232           typename _Tp8 = _NullClass, typename _Tp9 = _NullClass>
233    struct __stripped_tuple_type
234    {
235      typedef tuple<typename __strip_reference_wrapper<_Tp0>::__type,
236                    typename __strip_reference_wrapper<_Tp1>::__type,
237                    typename __strip_reference_wrapper<_Tp2>::__type,
238                    typename __strip_reference_wrapper<_Tp3>::__type,
239                    typename __strip_reference_wrapper<_Tp4>::__type,
240                    typename __strip_reference_wrapper<_Tp5>::__type,
241                    typename __strip_reference_wrapper<_Tp6>::__type,
242                    typename __strip_reference_wrapper<_Tp7>::__type,
243                    typename __strip_reference_wrapper<_Tp8>::__type,
244                    typename __strip_reference_wrapper<_Tp9>::__type>      __type;
245    };
246
247  // A class (and instance) which can be used in 'tie' when an element
248  // of a tuple is not required
249  struct swallow_assign
250  {
251    template<class T>
252    swallow_assign&
253      operator=(const T&)
254      { return *this; }
255  };
256
257  // TODO: Put this in some kind of shared file.
258  namespace
259  {
260    swallow_assign ignore;
261  };
262
263 #define _GLIBCXX_CAT(x,y) _GLIBCXX_CAT2(x,y)
264 #define _GLIBCXX_CAT2(x,y) x##y
265 #define _SHORT_REPEAT
266 #define _GLIBCXX_REPEAT_HEADER <tr1/tuple_iterate.h>
267 #include <tr1/repeat.h>
268 #undef _GLIBCXX_REPEAT_HEADER
269 #undef _SHORT_REPEAT
270 }
271 }
272
273 #include <tr1/functional>
274
275 #endif