General purpose index-based heterogeneous sequence with a fixed length.
The tuple is the bread and butter for static metaprogramming. Conceptually, it is like a std::tuple
; it is a container able of holding objects of different types and whose size is fixed at compile-time. However, Hana's tuple provides much more functionality than its std
counterpart, and it is also much more efficient than all standard library implementations tested so far.
Tuples are index-based sequences. If you need an associative sequence with a key-based access, then you should consider hana::map
or hana::set
instead.
Sequence
, and all the concepts it refines
For convenience, the following operators are provided:
Synopsis of associated functions | |
template<> | |
constexpr auto | make< tuple_tag > |
Function object for creating a tuple . More... | |
constexpr auto | make_tuple = make<tuple_tag> |
Alias to make<tuple_tag> ; provided for convenience. More... | |
constexpr auto | to_tuple = to<tuple_tag> |
Equivalent to to<tuple_tag> ; provided for convenience. More... | |
template<typename... T> | |
constexpr implementation_defined | tuple_t {} |
Create a tuple specialized for holding hana::type s. More... | |
template<typename T , T... v> | |
constexpr implementation_defined | tuple_c {} |
Create a tuple specialized for holding hana::integral_constant s. More... | |
Friends | |
template<typename... T, typename F > | |
constexpr auto | operator| (tuple< T... >, F) |
Equivalent to hana::chain . | |
template<typename X , typename Y > | |
constexpr auto | operator== (X &&x, Y &&y) |
Equivalent to hana::equal | |
template<typename X , typename Y > | |
constexpr auto | operator!= (X &&x, Y &&y) |
Equivalent to hana::not_equal | |
template<typename X , typename Y > | |
constexpr auto | operator< (X &&x, Y &&y) |
Equivalent to hana::less | |
template<typename X , typename Y > | |
constexpr auto | operator> (X &&x, Y &&y) |
Equivalent to hana::greater | |
template<typename X , typename Y > | |
constexpr auto | operator<= (X &&x, Y &&y) |
Equivalent to hana::less_equal | |
template<typename X , typename Y > | |
constexpr auto | operator>= (X &&x, Y &&y) |
Equivalent to hana::greater_equal | |
Public Member Functions | |
constexpr | tuple () |
Default constructs the tuple . Only exists when all the elements of the tuple are default constructible. | |
constexpr | tuple (Xn const &...xn) |
Initialize each element of the tuple with the corresponding element from xn... . Only exists when all the elements of the tuple are copy-constructible. More... | |
template<typename... Yn> | |
constexpr | tuple (Yn &&...yn) |
Initialize each element of the tuple by perfect-forwarding the corresponding element in yn... . Only exists when all the elements of the created tuple are constructible from the corresponding perfect-forwarded value. More... | |
template<typename... Yn> | |
constexpr | tuple (tuple< Yn... > const &other) |
Copy-initialize a tuple from another tuple. Only exists when all the elements of the constructed tuple are copy-constructible from the corresponding element in the source tuple. | |
template<typename... Yn> | |
constexpr | tuple (tuple< Yn... > &&other) |
Move-initialize a tuple from another tuple. Only exists when all the elements of the constructed tuple are move-constructible from the corresponding element in the source tuple. | |
template<typename... Yn> | |
constexpr tuple & | operator= (tuple< Yn... > const &other) |
Assign a tuple to another tuple. Only exists when all the elements of the destination tuple are assignable from the corresponding element in the source tuple. | |
template<typename... Yn> | |
constexpr tuple & | operator= (tuple< Yn... > &&other) |
Move-assign a tuple to another tuple. Only exists when all the elements of the destination tuple are move-assignable from the corresponding element in the source tuple. | |
template<typename N > | |
decltype(auto) constexpr | operator[] (N &&n) |
Equivalent to hana::at | |
Function object for creating a tuple
.
Given zero or more objects xs...
, make<tuple_tag>
returns a new tuple containing those objects. The elements are held by value inside the resulting tuple, and they are hence copied or moved in. This is analogous to std::make_tuple
for creating Hana tuples.
Alias to make<tuple_tag>
; provided for convenience.
Equivalent to to<tuple_tag>
; provided for convenience.
|
related |
Create a tuple specialized for holding hana::type
s.
This is functionally equivalent to make<tuple_tag>(type_c<T>...)
, except that using tuple_t
allows the library to perform some compile-time optimizations. Also note that the type of the objects returned by tuple_t
and an equivalent call to make<tuple_tag>
may differ.
|
related |
Create a tuple specialized for holding hana::integral_constant
s.
This is functionally equivalent to make<tuple_tag>(integral_c<T, v>...)
, except that using tuple_c
allows the library to perform some compile-time optimizations. Also note that the type of the objects returned by tuple_c
and an equivalent call to make<tuple_tag>
may differ.
constexpr boost::hana::tuple< Xn >::tuple | ( | Xn const &... | xn | ) |
Initialize each element of the tuple with the corresponding element from xn...
. Only exists when all the elements of the tuple are copy-constructible.
std::tuple
, this constructor is not explicit. This allows returning a tuple from a function with the brace-initialization syntax. constexpr boost::hana::tuple< Xn >::tuple | ( | Yn &&... | yn | ) |
Initialize each element of the tuple by perfect-forwarding the corresponding element in yn...
. Only exists when all the elements of the created tuple are constructible from the corresponding perfect-forwarded value.
std::tuple
, this constructor is not explicit. This allows returning a tuple from a function with the brace-initialization syntax.