tuple.qbk 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. [/==============================================================================
  2. Copyright (C) 2001-2011 Joel de Guzman
  3. Copyright (C) 2006 Dan Marsden
  4. Use, modification and distribution is subject to the Boost Software
  5. License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  6. http://www.boost.org/LICENSE_1_0.txt)
  7. ===============================================================================/]
  8. [section Tuple]
  9. The TR1 technical report describes extensions to the C++ standard library.
  10. Many of these extensions will be considered for the next
  11. iteration of the C++ standard. TR1 describes a tuple type, and
  12. support for treating `std::pair` as a type of tuple.
  13. Fusion provides full support for the __tr1__tuple__ interface, and the extended
  14. uses of `std::pair` described in the TR1 document.
  15. [section Class template tuple]
  16. Fusion's implementation of the __tr1__tuple__ is also a fusion __forward_sequence__.
  17. As such the fusion tuple type provides a lot of functionality beyond that required by TR1.
  18. Currently tuple is basically a synonym for __vector__, although this may be changed
  19. in future releases of fusion.
  20. [heading Header]
  21. #include <boost/fusion/tuple.hpp>
  22. #include <boost/fusion/include/tuple.hpp>
  23. #include <boost/fusion/tuple/tuple.hpp>
  24. #include <boost/fusion/tuple/tuple_fwd.hpp>
  25. #include <boost/fusion/include/tuple_fwd.hpp>
  26. // for creation function
  27. #include <boost/fusion/tuple/tuple_tie.hpp>
  28. #include <boost/fusion/include/tuple_tie.hpp>
  29. #include <boost/fusion/tuple/make_tuple.hpp>
  30. #include <boost/fusion/include/make_tuple.hpp>
  31. [heading Synopsis]
  32. template<
  33. typename T1 = __unspecified__,
  34. typename T2 = __unspecified__,
  35. ...
  36. typename TN = __unspecified__>
  37. class tuple;
  38. [section Construction]
  39. [heading Description]
  40. 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.
  41. [heading Specification]
  42. [variablelist Notation
  43. [[`T1 ... TN`, `U1 ... UN`][Tuple element types]]
  44. [[`P1 ... PN`] [Parameter types]]
  45. [[`Ti`, `Ui`] [The type of the `i`th element of a tuple]]
  46. [[`Pi`] [The type of the `i`th parameter]]
  47. ]
  48. tuple();
  49. [*Requirements]: Each `Ti` is default-constructible.
  50. [*Semantics]: Default initializes each element of the tuple.
  51. tuple(P1,P2,...,PN);
  52. [*Requirements]: Each `Pi` is `Ti` if `Ti` is a reference type, `const Ti&` otherwise.
  53. [*Semantics]: Copy initializes each element with the corresponding parameter.
  54. tuple(const tuple& t);
  55. [*Requirements]: Each `Ti` should be copy-constructible.
  56. [*Semantics]: Copy constructs each element of `*this` with the corresponding element of `t`.
  57. template<typename U1, typename U2, ..., typename UN>
  58. tuple(const tuple<U1, U2, ..., UN>& t);
  59. [*Requirements]: Each `Ti` shall be constructible from the corresponding `Ui`.
  60. [*Semantics]: Constructs each element of `*this` with the corresponding element of `t`.
  61. [endsect]
  62. [section Tuple creation functions]
  63. [heading Description]
  64. 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.
  65. [heading Specification]
  66. template<typename T1, typename T2, ..., typename TN>
  67. tuple<V1, V2, ..., VN>
  68. make_tuple(const T1& t1, const T2& t2, ..., const TN& tn);
  69. Where `Vi` is `X&` if the cv-unqualified type `Ti` is `reference_wrapper<X>`, otherwise `Vi` is `Ti`.
  70. [*Returns]: `tuple<V1, V2, ..., VN>(t1, t2, ..., tN)`
  71. template<typename T1, typename T2, ..., typename TN>
  72. tuple<T1&, T2&, ..., TN&>
  73. tie(T1& t1, T2& t2, ..., TN& tn);
  74. [*Returns]: tuple<T1&, T2&, ..., TN&>(t1, t2, ..., tN). When argument `ti` is `ignore`, assigning any value to the corresponding tuple element has no effect.
  75. [endsect]
  76. [section Tuple helper classes]
  77. [heading Description]
  78. The __tr1__tuple__ provides 2 helper traits, for compile time access to the tuple size, and the element types.
  79. [heading Specification]
  80. tuple_size<T>::value
  81. [*Requires]: `T` is any fusion sequence type, including `tuple`.
  82. [*Type]: __mpl_integral_constant__
  83. [*Value]: The number of elements in the sequence. Equivalent to `__result_of_size__<T>::type`.
  84. tuple_element<I, T>::type
  85. [*Requires]: `T` is any fusion sequence type, including `tuple`. `0 <= I < N` or the program is ill formed.
  86. [*Value]: The type of the `I`th element of `T`. Equivalent to `__result_of_value_at__<I,T>::type`.
  87. [endsect]
  88. [section Element access]
  89. [heading Description]
  90. The __tr1__tuple__ provides the `get` function to provide access to it's elements by zero based numeric index.
  91. [heading Specification]
  92. template<int I, T>
  93. RJ get(T& t);
  94. [*Requires]: `0 < I <= N`. The program is ill formed if `I` is out of bounds.
  95. `T` is any fusion sequence type, including `tuple`.
  96. [*Return type]: `RJ` is equivalent to `__result_of_at_c__<I,T>::type`.
  97. [*Returns]: A reference to the `I`th element of `T`.
  98. template<int I, typename T>
  99. PJ get(T const& t);
  100. [*Requires]: `0 < I <= N`. The program is ill formed if `I` is out of bounds.
  101. `T` is any fusion sequence type, including `tuple`.
  102. [*Return type]: `PJ` is equivalent to `__result_of_at_c__<I,T>::type`.
  103. [*Returns]: A const reference to the `I`th element of `T`.
  104. [endsect]
  105. [section Relational operators]
  106. [heading Description]
  107. The __tr1__tuple__ provides the standard boolean relational operators.
  108. [heading Specification]
  109. [variablelist Notation
  110. [[`T1 ... TN`, `U1 ... UN`][Tuple element types]]
  111. [[`P1 ... PN`] [Parameter types]]
  112. [[`Ti`, `Ui`] [The type of the `i`th element of a tuple]]
  113. [[`Pi`] [The type of the `i`th parameter]]
  114. ]
  115. template<typename T1, typename T2, ..., typename TN,
  116. typename U1, typename U2, ..., typename UN>
  117. bool operator==(
  118. const tuple<T1, T2, ..., TN>& lhs,
  119. const tuple<U1, U2, ..., UN>& rhs);
  120. [*Requirements]: For all `i`, `1 <= i < N`, `__tuple_get__<i>(lhs) == __tuple_get__<i>(rhs)` is a valid
  121. expression returning a type that is convertible to `bool`.
  122. [*Semantics]: Returns `true` if and only if `__tuple_get__<i>(lhs) == __tuple_get__<i>(rhs)` for all `i`.
  123. For any 2 zero length tuples `e` and `f`, `e == f` returns `true`.
  124. template<typename T1, typename T2, ..., typename TN,
  125. typename U1, typename U2, ..., typename UN>
  126. bool operator<(
  127. const tuple<T1, T2, ..., TN>& lhs,
  128. const tuple<U1, U2, ..., UN>& rhs);
  129. [*Requirements]: For all `i`, `1 <= i < N`, `__tuple_get__<i>(lhs) < __tuple_get__<i>(rhs)` is a valid
  130. expression returning a type that is convertible to `bool`.
  131. [*Semantics]: Returns the lexicographical comparison of between `lhs` and `rhs`.
  132. template<typename T1, typename T2, ..., typename TN,
  133. typename U1, typename U2, ..., typename UN>
  134. bool operator!=(
  135. const tuple<T1, T2, ..., TN>& lhs,
  136. const tuple<U1, U2, ..., UN>& rhs);
  137. [*Requirements]: For all `i`, `1 <= i < N`, `__tuple_get__<i>(lhs) == __tuple_get__<i>(rhs)` is a valid
  138. expression returning a type that is convertible to `bool`.
  139. [*Semantics]: Returns `!(lhs == rhs)`.
  140. template<typename T1, typename T2, ..., typename TN,
  141. typename U1, typename U2, ..., typename UN>
  142. bool operator<=(
  143. const tuple<T1, T2, ..., TN>& lhs,
  144. const tuple<U1, U2, ..., UN>& rhs);
  145. [*Requirements]: For all `i`, `1 <= i < N`, `__tuple_get__<i>(rhs) < __tuple_get__<i>(lhs)` is a valid
  146. expression returning a type that is convertible to `bool`.
  147. [*Semantics]: Returns `!(rhs < lhs)`
  148. template<typename T1, typename T2, ..., typename TN,
  149. typename U1, typename U2, ..., typename UN>
  150. bool operator>(
  151. const tuple<T1, T2, ..., TN>& lhs,
  152. const tuple<U1, U2, ..., UN>& rhs);
  153. [*Requirements]: For all `i`, `1 <= i < N`, `__tuple_get__<i>(rhs) < __tuple_get__<i>(lhs)` is a valid
  154. expression returning a type that is convertible to `bool`.
  155. [*Semantics]: Returns `rhs < lhs`.
  156. template<typename T1, typename T2, ..., typename TN,
  157. typename U1, typename U2, ..., typename UN>
  158. bool operator>=(
  159. const tuple<T1, T2, ..., TN>& lhs,
  160. const tuple<U1, U2, ..., UN>& rhs);
  161. [*Requirements]: For all `i`, `1 <= i < N`, `__tuple_get__<i>(lhs) < __tuple_get__<i>(rhs)` is a valid
  162. expression returning a type that is convertible to `bool`.
  163. [*Semantics]: Returns `!(lhs < rhs)`.
  164. [endsect]
  165. [endsect]
  166. [section Pairs]
  167. [heading Description]
  168. The __tr1__tuple__ interface is specified to provide uniform access to `std::pair` as if it were a 2 element tuple.
  169. [heading Specification]
  170. tuple_size<std::pair<T1, T2> >::value
  171. [*Type]: An __mpl_integral_constant__
  172. [*Value]: Returns 2, the number of elements in a pair.
  173. tuple_element<0, std::pair<T1, T2> >::type
  174. [*Type]: `T1`
  175. [*Value]: Returns the type of the first element of the pair
  176. tuple_element<1, std::pair<T1, T2> >::type
  177. [*Type]: `T2`
  178. [*Value]: Returns the type of the second element of the pair
  179. template<int I, typename T1, typename T2>
  180. P& get(std::pair<T1, T2>& pr);
  181. template<int I, typename T1, typename T2>
  182. const P& get(const std::pair<T1, T2>& pr);
  183. [*Type]: If `I == 0` `P` is `T1`, else if `I == 1` `P` is `T2` else the program is ill-formed.
  184. [*Returns: `pr.first` if `I == 0` else `pr.second`.
  185. [endsect]
  186. [endsect]