1 // class template tuple -*- C++ -*-
3 // Copyright (C) 2004, 2005 Free Software Foundation, Inc.
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)
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.
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,
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.
31 * This is a TR1 C++ Library header.
34 // Chris Jefferson <chris@bubblescope.net>
39 #include <tr1/utility>
40 #include <tr1/ref_fwd.h>
44 _GLIBCXX_BEGIN_NAMESPACE(tr1)
46 // An implementation specific class which is used in the tuple class
47 // when the tuple is not maximum possible size.
48 struct _NullClass { };
50 /// Gives the type of the ith element of a given tuple type.
51 template<int __i, typename _Tp>
54 /// Finds the size of a given tuple type.
55 template<typename _Tp>
58 // Adds a const reference to a non-reference type.
59 template<typename _Tp>
61 { typedef const _Tp& type; };
63 template<typename _Tp>
64 struct __add_c_ref<_Tp&>
65 { typedef _Tp& type; };
67 // Adds a reference to a non-reference type.
68 template<typename _Tp>
70 { typedef _Tp& type; };
72 template<typename _Tp>
73 struct __add_ref<_Tp&>
74 { typedef _Tp& type; };
76 // Class used in the implementation of get
77 template<int __i, typename _Tp>
80 // Returns a const reference to the ith element of a tuple.
81 // Any const or non-const ref elements are returned with their original type.
83 // This class helps construct the various comparison operations on tuples
84 template<int __check_equal_size, int __i, int __j, typename _Tp, typename _Up>
85 struct __tuple_compare;
87 // Helper which adds a reference to a type when given a reference_wrapper
88 template<typename _Tp>
89 struct __strip_reference_wrapper
94 template<typename _Tp>
95 struct __strip_reference_wrapper<reference_wrapper<_Tp> >
100 template<typename _Tp>
101 struct __strip_reference_wrapper<const reference_wrapper<_Tp> >
106 #include "tuple_defs.h"
108 template<int __i, int __j, typename _Tp, typename _Up>
109 struct __tuple_compare<0, __i, __j, _Tp, _Up>
111 static bool __eq(const _Tp& __t, const _Up& __u)
113 return get<__i>(__t) == get<__i>(__u) &&
114 __tuple_compare<0, __i+1, __j, _Tp, _Up>::__eq(__t, __u);
116 static bool __less(const _Tp& __t, const _Up& __u)
118 return (get<__i>(__t) < get<__i>(__u)) || !(get<__i>(__u) < get<__i>(__t)) &&
119 __tuple_compare<0, __i+1, __j, _Tp, _Up>::__less(__t, __u);
123 template<int __i, typename _Tp, typename _Up>
124 struct __tuple_compare<0, __i, __i, _Tp, _Up>
126 static bool __eq(const _Tp&, const _Up&)
128 static bool __less(const _Tp&, const _Up&)
132 // A class (and instance) which can be used in 'tie' when an element
133 // of a tuple is not required
134 struct swallow_assign
142 // TODO: Put this in some kind of shared file.
145 swallow_assign ignore;
146 }; // anonymous namespace
148 _GLIBCXX_END_NAMESPACE
151 #define _GLIBCXX_CAT(x,y) _GLIBCXX_CAT2(x,y)
152 #define _GLIBCXX_CAT2(x,y) x##y
153 #define _SHORT_REPEAT
154 #define _GLIBCXX_REPEAT_HEADER <tr1/tuple_iterate.h>
155 #include <tr1/repeat.h>
156 #undef _GLIBCXX_REPEAT_HEADER
159 #include <tr1/functional>