| Boost.Hana 1.7.1 Your standard library for metaprogramming |

Synopsis of associated functions | Friends | Public Member Functions | List of all members
boost::hana::tuple< Xn > Struct Template Reference
Data types

## Description

### template<typename ... Xn>
struct boost::hana::tuple< Xn >

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.

Note
  When you use a container, remember not to make assumptions about its representation, unless the documentation gives you those guarantees. More details in the tutorial.

## Modeled concepts

`Sequence`, and all the concepts it refines

## Provided operators

For convenience, the following operators are provided:

xs == ys -> equal(xs, ys)
xs != ys -> not_equal(xs, ys)
xs < ys -> less(xs, ys)
xs <= ys -> less_equal(xs, ys)
xs > ys -> greater(xs, ys)
xs >= ys -> greater_equal(xs, ys)
xs | f -> chain(xs, f)
xs[n] -> at(xs, n)
boost::hana::equal
constexpr auto equal
Returns a Logical representing whether x is equal to y.
Definition: equal.hpp:64
boost::hana::not_equal
constexpr auto not_equal
Returns a Logical representing whether x is not equal to y.
Definition: not_equal.hpp:54
boost::hana::at
constexpr auto at
Returns the nth element of an iterable.
Definition: at.hpp:50
boost::hana::greater_equal
constexpr auto greater_equal
Returns a Logical representing whether x is greater than or equal to y.
Definition: greater_equal.hpp:38
boost::hana::less_equal
constexpr auto less_equal
Returns a Logical representing whether x is less than or equal to y.
Definition: less_equal.hpp:38
boost::hana::less
constexpr auto less
Returns a Logical representing whether x is less than y.
Definition: less.hpp:37
boost::hana::greater
constexpr auto greater
Returns a Logical representing whether x is greater than y.
Definition: greater.hpp:37

## Example

// Copyright Louis Dionne 2013-2017
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
#include <boost/hana/assert.hpp>
#include <boost/hana/equal.hpp>
#include <boost/hana/integral_constant.hpp>
#include <boost/hana/transform.hpp>
#include <boost/hana/tuple.hpp>
#include <string>
namespace hana = boost::hana;
using namespace hana::literals;
struct Fish { std::string name; };
struct Cat { std::string name; };
struct Dog { std::string name; };
int main() {
hana::tuple<Fish, Cat, Dog> animals{{"Nemo"}, {"Garfield"}, {"Snoopy"}};
animals[0_c].name = "Moby Dick"; // can modify elements in place, like std::tuple
auto names = hana::transform(animals, [](auto a) {
return a.name;
});
BOOST_HANA_RUNTIME_CHECK(names == hana::make_tuple("Moby Dick", "Garfield", "Snoopy"));
}
assert.hpp
Defines macros to perform different kinds of assertions.
equal.hpp
Defines boost::hana::equal.
BOOST_HANA_RUNTIME_CHECK
#define BOOST_HANA_RUNTIME_CHECK(...)
Equivalent to BOOST_HANA_RUNTIME_ASSERT, but not influenced by the BOOST_HANA_CONFIG_DISABLE_ASSERTIO...
Definition: assert.hpp:209
integral_constant.hpp
Defines boost::hana::integral_constant.
boost::hana
Namespace containing everything in the library.
Definition: accessors.hpp:20
transform.hpp
Defines boost::hana::transform.
tuple.hpp
Defines boost::hana::tuple.
Inheritance diagram for boost::hana::tuple< Xn >:

## 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.
constexpr auto | to_tuple = to<tuple_tag>
| Equivalent to `to<tuple_tag>`; provided for convenience.
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 friend auto | operator| (tuple< T... >, F)
| Equivalent to `hana::chain`.
template<typename X , typename Y >
constexpr friend auto | operator== (X &&x, Y &&y)
| Equivalent to `hana::equal`
template<typename X , typename Y >
constexpr friend auto | operator!= (X &&x, Y &&y)
| Equivalent to `hana::not_equal`
template<typename X , typename Y >
constexpr friend auto | operator< (X &&x, Y &&y)
| Equivalent to `hana::less`
template<typename X , typename Y >
constexpr friend auto | operator> (X &&x, Y &&y)
| Equivalent to `hana::greater`
template<typename X , typename Y >
constexpr friend auto | operator<= (X &&x, Y &&y)
| Equivalent to `hana::less_equal`
template<typename X , typename Y >
constexpr friend 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 >
constexpr decltype(auto) | operator[] (N &&n)
| Equivalent to `hana::at`

## Associated functions

## ◆ make< tuple_tag >

template<typename ... Xn>
template<>

constexpr auto make< tuple_tag >
| related

Initial value:
= [](auto&& ...xs) {
return tuple<std::decay_t<decltype(xs)>...>{forwarded(xs)...};
}
boost::hana::tuple::tuple
constexpr tuple()
Default constructs the tuple. Only exists when all the elements of the tuple are default constructibl...

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.

## Example

// Copyright Louis Dionne 2013-2017
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
#include <boost/hana/assert.hpp>
#include <boost/hana/core/make.hpp>
#include <boost/hana/equal.hpp>
#include <boost/hana/tuple.hpp>
#include <string>
namespace hana = boost::hana;
int main() {
auto xs = hana::make<hana::tuple_tag>(1, 2, '3', std::string{"456"});
constexpr auto ys = hana::make<hana::tuple_tag>(1, '2', 3.456);
static_assert(ys == hana::make_tuple(1, '2', 3.456), "");
}
make.hpp
Defines boost::hana::make.

## ◆ tuple_t

template<typename ... Xn>
template<typename ... T>

constexpr implementation_defined tuple_t {}
| 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.

## Example

// Copyright Louis Dionne 2013-2017
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
#include <boost/hana/assert.hpp>
#include <boost/hana/core/to.hpp>
#include <boost/hana/equal.hpp>
#include <boost/hana/tuple.hpp>
#include <boost/hana/type.hpp>
namespace hana = boost::hana;
int main() {
BOOST_HANA_CONSTANT_CHECK(
hana::to_tuple(hana::tuple_t<int, char, void, int(float)>)
==
hana::make_tuple(hana::type_c<int>, hana::type_c<char>, hana::type_c<void>, hana::type_c<int(float)>)
);
}
to.hpp
Defines boost::hana::to and related utilities.
BOOST_HANA_CONSTANT_CHECK
#define BOOST_HANA_CONSTANT_CHECK(...)
Equivalent to BOOST_HANA_CONSTANT_ASSERT, but not influenced by the BOOST_HANA_CONFIG_DISABLE_ASSERTI...
Definition: assert.hpp:239
type.hpp
Defines boost::hana::type and related utilities.

## ◆ tuple_c

template<typename ... Xn>
template<typename T , T ... v>

constexpr implementation_defined tuple_c {}
| 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.

## Example

// Copyright Louis Dionne 2013-2017
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
#include <boost/hana/assert.hpp>
#include <boost/hana/core/to.hpp>
#include <boost/hana/equal.hpp>
#include <boost/hana/front.hpp>
#include <boost/hana/integral_constant.hpp>
#include <boost/hana/tuple.hpp>
namespace hana = boost::hana;
int main() {
BOOST_HANA_CONSTANT_CHECK(
hana::tuple_c<int, 0, 1, 2>
==
hana::make_tuple(hana::int_c<0>, hana::int_c<1>, hana::int_c<2>)
);
BOOST_HANA_CONSTANT_CHECK(hana::front(hana::tuple_c<int, 0, 1, 2>) == hana::int_c<0>);
}
front.hpp
Defines boost::hana::front.
boost::hana::front
constexpr auto front
Returns the first element of a non-empty iterable.
Definition: front.hpp:32

## Constructor & Destructor Documentation

## ◆ tuple() [1/2]

template<typename ... Xn>

constexpr boost::hana::tuple< Xn >::tuple | ( | Xn const &... | xn | ) |
| constexpr

Initialize each element of the tuple with the corresponding element from `xn...`. Only exists when all the elements of the tuple are copy-constructible.

Note
  Unlike the corresponding constructor for `std::tuple`, this constructor is not explicit. This allows returning a tuple from a function with the brace-initialization syntax.

## ◆ tuple() [2/2]

template<typename ... Xn>
template<typename ... Yn>

constexpr boost::hana::tuple< Xn >::tuple | ( | Yn &&... | yn | ) |
| constexpr

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.

Note
  Unlike the corresponding constructor for `std::tuple`, this constructor is not explicit. This allows returning a tuple from a function with the brace-initialization syntax.