1 [/==============================================================================
2 Copyright (C) 2001-2011 Joel de Guzman
3 Copyright (C) 2006 Dan Marsden
5 Use, modification and distribution is subject to the Boost Software
6 License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7 http://www.boost.org/LICENSE_1_0.txt)
8 ===============================================================================/]
11 The TR1 technical report describes extensions to the C++ standard library.
12 Many of these extensions will be considered for the next
13 iteration of the C++ standard. TR1 describes a tuple type, and
14 support for treating `std::pair` as a type of tuple.
16 Fusion provides full support for the __tr1__tuple__ interface, and the extended
17 uses of `std::pair` described in the TR1 document.
19 [section Class template tuple]
20 Fusion's implementation of the __tr1__tuple__ is also a fusion __forward_sequence__.
21 As such the fusion tuple type provides a lot of functionality beyond that required by TR1.
23 Currently tuple is basically a synonym for __vector__, although this may be changed
24 in future releases of fusion.
28 #include <boost/fusion/tuple.hpp>
29 #include <boost/fusion/include/tuple.hpp>
31 #include <boost/fusion/tuple/tuple.hpp>
32 #include <boost/fusion/tuple/tuple_fwd.hpp>
33 #include <boost/fusion/include/tuple_fwd.hpp>
35 // for creation function
36 #include <boost/fusion/tuple/tuple_tie.hpp>
37 #include <boost/fusion/include/tuple_tie.hpp>
38 #include <boost/fusion/tuple/make_tuple.hpp>
39 #include <boost/fusion/include/make_tuple.hpp>
43 typename T1 = __unspecified__,
44 typename T2 = __unspecified__,
46 typename TN = __unspecified__>
49 [section Construction]
52 The __tr1__tuple__ type provides a default constructor, a constructor that takes initializers for all of its elements, a copy constructor, and a converting copy constructor. The details of the various constructors are described in this section.
54 [heading Specification]
56 [variablelist Notation
57 [[`T1 ... TN`, `U1 ... UN`][Tuple element types]]
58 [[`P1 ... PN`] [Parameter types]]
59 [[`Ti`, `Ui`] [The type of the `i`th element of a tuple]]
60 [[`Pi`] [The type of the `i`th parameter]]
65 [*Requirements]: Each `Ti` is default-constructible.
67 [*Semantics]: Default initializes each element of the tuple.
71 [*Requirements]: Each `Pi` is `Ti` if `Ti` is a reference type, `const Ti&` otherwise.
73 [*Semantics]: Copy initializes each element with the corresponding parameter.
75 tuple(const tuple& t);
77 [*Requirements]: Each `Ti` should be copy-constructible.
79 [*Semantics]: Copy constructs each element of `*this` with the corresponding element of `t`.
81 template<typename U1, typename U2, ..., typename UN>
82 tuple(const tuple<U1, U2, ..., UN>& t);
84 [*Requirements]: Each `Ti` shall be constructible from the corresponding `Ui`.
86 [*Semantics]: Constructs each element of `*this` with the corresponding element of `t`.
90 [section Tuple creation functions]
93 TR1 describes 2 utility functions for creating __tr1__tuple__. `make_tuple` builds a tuple out of it's argument list, and `tie` builds a tuple of references to it's arguments. The details of these creation functions are described in this section.
95 [heading Specification]
97 template<typename T1, typename T2, ..., typename TN>
98 tuple<V1, V2, ..., VN>
99 make_tuple(const T1& t1, const T2& t2, ..., const TN& tn);
101 Where `Vi` is `X&` if the cv-unqualified type `Ti` is `reference_wrapper<X>`, otherwise `Vi` is `Ti`.
103 [*Returns]: `tuple<V1, V2, ..., VN>(t1, t2, ..., tN)`
105 template<typename T1, typename T2, ..., typename TN>
106 tuple<T1&, T2&, ..., TN&>
107 tie(T1& t1, T2& t2, ..., TN& tn);
109 [*Returns]: tuple<T1&, T2&, ..., TN&>(t1, t2, ..., tN). When argument `ti` is `ignore`, assigning any value to the corresponding tuple element has no effect.
113 [section Tuple helper classes]
115 [heading Description]
116 The __tr1__tuple__ provides 2 helper traits, for compile time access to the tuple size, and the element types.
118 [heading Specification]
122 [*Requires]: `T` is any fusion sequence type, including `tuple`.
124 [*Type]: __mpl_integral_constant__
126 [*Value]: The number of elements in the sequence. Equivalent to `__result_of_size__<T>::type`.
128 tuple_element<I, T>::type
130 [*Requires]: `T` is any fusion sequence type, including `tuple`. `0 <= I < N` or the program is ill formed.
132 [*Value]: The type of the `I`th element of `T`. Equivalent to `__result_of_value_at__<I,T>::type`.
136 [section Element access]
138 [heading Description]
139 The __tr1__tuple__ provides the `get` function to provide access to it's elements by zero based numeric index.
141 [heading Specification]
145 [*Requires]: `0 < I <= N`. The program is ill formed if `I` is out of bounds.
146 `T` is any fusion sequence type, including `tuple`.
148 [*Return type]: `RJ` is equivalent to `__result_of_at_c__<I,T>::type`.
150 [*Returns]: A reference to the `I`th element of `T`.
152 template<int I, typename T>
155 [*Requires]: `0 < I <= N`. The program is ill formed if `I` is out of bounds.
156 `T` is any fusion sequence type, including `tuple`.
158 [*Return type]: `PJ` is equivalent to `__result_of_at_c__<I,T>::type`.
160 [*Returns]: A const reference to the `I`th element of `T`.
164 [section Relational operators]
166 [heading Description]
167 The __tr1__tuple__ provides the standard boolean relational operators.
169 [heading Specification]
171 [variablelist Notation
172 [[`T1 ... TN`, `U1 ... UN`][Tuple element types]]
173 [[`P1 ... PN`] [Parameter types]]
174 [[`Ti`, `Ui`] [The type of the `i`th element of a tuple]]
175 [[`Pi`] [The type of the `i`th parameter]]
178 template<typename T1, typename T2, ..., typename TN,
179 typename U1, typename U2, ..., typename UN>
181 const tuple<T1, T2, ..., TN>& lhs,
182 const tuple<U1, U2, ..., UN>& rhs);
184 [*Requirements]: For all `i`, `1 <= i < N`, `__tuple_get__<i>(lhs) == __tuple_get__<i>(rhs)` is a valid
185 expression returning a type that is convertible to `bool`.
187 [*Semantics]: Returns `true` if and only if `__tuple_get__<i>(lhs) == __tuple_get__<i>(rhs)` for all `i`.
188 For any 2 zero length tuples `e` and `f`, `e == f` returns `true`.
190 template<typename T1, typename T2, ..., typename TN,
191 typename U1, typename U2, ..., typename UN>
193 const tuple<T1, T2, ..., TN>& lhs,
194 const tuple<U1, U2, ..., UN>& rhs);
196 [*Requirements]: For all `i`, `1 <= i < N`, `__tuple_get__<i>(lhs) < __tuple_get__<i>(rhs)` is a valid
197 expression returning a type that is convertible to `bool`.
199 [*Semantics]: Returns the lexicographical comparison of between `lhs` and `rhs`.
201 template<typename T1, typename T2, ..., typename TN,
202 typename U1, typename U2, ..., typename UN>
204 const tuple<T1, T2, ..., TN>& lhs,
205 const tuple<U1, U2, ..., UN>& rhs);
207 [*Requirements]: For all `i`, `1 <= i < N`, `__tuple_get__<i>(lhs) == __tuple_get__<i>(rhs)` is a valid
208 expression returning a type that is convertible to `bool`.
210 [*Semantics]: Returns `!(lhs == rhs)`.
212 template<typename T1, typename T2, ..., typename TN,
213 typename U1, typename U2, ..., typename UN>
215 const tuple<T1, T2, ..., TN>& lhs,
216 const tuple<U1, U2, ..., UN>& rhs);
218 [*Requirements]: For all `i`, `1 <= i < N`, `__tuple_get__<i>(rhs) < __tuple_get__<i>(lhs)` is a valid
219 expression returning a type that is convertible to `bool`.
221 [*Semantics]: Returns `!(rhs < lhs)`
223 template<typename T1, typename T2, ..., typename TN,
224 typename U1, typename U2, ..., typename UN>
226 const tuple<T1, T2, ..., TN>& lhs,
227 const tuple<U1, U2, ..., UN>& rhs);
229 [*Requirements]: For all `i`, `1 <= i < N`, `__tuple_get__<i>(rhs) < __tuple_get__<i>(lhs)` is a valid
230 expression returning a type that is convertible to `bool`.
232 [*Semantics]: Returns `rhs < lhs`.
234 template<typename T1, typename T2, ..., typename TN,
235 typename U1, typename U2, ..., typename UN>
237 const tuple<T1, T2, ..., TN>& lhs,
238 const tuple<U1, U2, ..., UN>& rhs);
240 [*Requirements]: For all `i`, `1 <= i < N`, `__tuple_get__<i>(lhs) < __tuple_get__<i>(rhs)` is a valid
241 expression returning a type that is convertible to `bool`.
243 [*Semantics]: Returns `!(lhs < rhs)`.
251 [heading Description]
252 The __tr1__tuple__ interface is specified to provide uniform access to `std::pair` as if it were a 2 element tuple.
254 [heading Specification]
256 tuple_size<std::pair<T1, T2> >::value
258 [*Type]: An __mpl_integral_constant__
260 [*Value]: Returns 2, the number of elements in a pair.
262 tuple_element<0, std::pair<T1, T2> >::type
266 [*Value]: Returns the type of the first element of the pair
268 tuple_element<1, std::pair<T1, T2> >::type
272 [*Value]: Returns the type of the second element of the pair
274 template<int I, typename T1, typename T2>
275 P& get(std::pair<T1, T2>& pr);
277 template<int I, typename T1, typename T2>
278 const P& get(const std::pair<T1, T2>& pr);
280 [*Type]: If `I == 0` `P` is `T1`, else if `I == 1` `P` is `T2` else the program is ill-formed.
282 [*Returns: `pr.first` if `I == 0` else `pr.second`.