| Boost.Hana 1.7.1 Your standard library for metaprogramming |

Variables
Sequence
Concepts

## Description

The `Sequence` concept represents generic index-based sequences.

Compared to other abstract concepts, the Sequence concept is very specific. It represents generic index-based sequences. The reason why such a specific concept is provided is because there are a lot of models that behave exactly the same while being implemented in wildly different ways. It is useful to regroup all those data types under the same umbrella for the purpose of generic programming.

In fact, models of this concept are not only similar. They are actually isomorphic, in a sense that we define below, which is a fancy way of rigorously saying that they behave exactly the same to an external observer.

## Minimal complete definition

`Iterable`, `Foldable`, and `make`

The `Sequence` concept does not provide basic methods that could be used as a minimal complete definition; instead, it borrows methods from other concepts and add laws to them. For this reason, it is necessary to specialize the `Sequence` metafunction in Hana's namespace to tell Hana that a type is indeed a `Sequence`. Explicitly specializing the `Sequence` metafunction can be seen like a seal saying "this data type satisfies the additional laws of a `Sequence`", since those can't be checked by Hana automatically.

## Laws

The laws for being a `Sequence` are simple, and their goal is to restrict the semantics that can be associated to the functions provided by other concepts. First, a `Sequence` must be a finite `Iterable` (thus a `Foldable` too). Secondly, for a `Sequence` tag `S`, `make<S>(x1, ..., xn)` must be an object of tag `S` and whose linearization is `[x1, ..., xn]`. This basically ensures that objects of tag `S` are equivalent to their linearization, and that they can be created from such a linearization (with `make`).

While it would be possible in theory to handle infinite sequences, doing so complicates the implementation of many algorithms. For simplicity, the current version of the library only handles finite sequences. However, note that this does not affect in any way the potential for having infinite `Searchable`s and `Iterable`s.

## Refined concepts

1. `Comparable` (definition provided automatically)
   Two `Sequence`s are equal if and only if they contain the same number of elements and their elements at any given index are equal.
   // 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/not_equal.hpp>
   #include <boost/hana/tuple.hpp>
   namespace hana = boost::hana;
   static_assert(hana::make_tuple(1, 2, 3) == hana::make_tuple(1, 2, 3), "");
   BOOST_HANA_CONSTANT_CHECK(hana::make_tuple(1, 2, 3) != hana::make_tuple(1, 2, 3, 4));
   int main() { }
   assert.hpp
   Defines macros to perform different kinds of assertions.
   equal.hpp
   Defines boost::hana::equal.
   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
   boost::hana
   Namespace containing everything in the library.
   Definition: accessors.hpp:20
   not_equal.hpp
   Defines boost::hana::not_equal.
   tuple.hpp
   Defines boost::hana::tuple.
2. `Orderable` (definition provided automatically)
   `Sequence`s are ordered using the traditional lexicographical ordering.
   // 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/less.hpp>
   #include <boost/hana/tuple.hpp>
   namespace hana = boost::hana;
   static_assert(hana::make_tuple(1, 2, 3) < hana::make_tuple(2, 3, 4), "");
   static_assert(hana::make_tuple(1, 2, 3) < hana::make_tuple(1, 2, 3, 4), "");
   int main() { }
   less.hpp
   Defines boost::hana::less.
3. `Functor` (definition provided automatically)
   `Sequence`s implement `transform` as the mapping of a function over each element of the sequence. This is somewhat equivalent to what `std::transform` does to ranges of iterators. Also note that mapping a function over an empty sequence returns an empty sequence and never applies the function, as would be expected.
   // 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/transform.hpp>
   #include <boost/hana/tuple.hpp>
   #include <sstream>
   #include <string>
   namespace hana = boost::hana;
   auto to_string = [](auto x) {
   std::ostringstream ss;
   ss << x;
   return ss.str();
   };
   int main() {
   BOOST_HANA_RUNTIME_CHECK(
   hana::transform(hana::make_tuple(1, '2', "345", std::string{"67"}), to_string) ==
   hana::make_tuple("1", "2", "345", "67")
   );
   }
   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
   transform.hpp
   Defines boost::hana::transform.
4. `Applicative` (definition provided automatically)
   First, `lift`ing a value into a `Sequence` is the same as creating a singleton sequence containing that value. Second, applying a sequence of functions to a sequence of values will apply each function to all the values in the sequence, and then return a list of all the results. In other words,
   ap([f1, ..., fN], [x1, ..., xM]) == [
   f1(x1), ..., f1(xM),
   ...
   fN(x1), ..., fN(xM)
   ]
   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/ap.hpp>
   #include <boost/hana/equal.hpp>
   #include <boost/hana/ext/std/tuple.hpp>
   #include <boost/hana/functional/flip.hpp>
   #include <boost/hana/lift.hpp>
   #include <boost/hana/pair.hpp>
   #include <boost/hana/tuple.hpp>
   #include <tuple>
   namespace hana = boost::hana;
   static_assert(hana::lift<hana::tuple_tag>('x') == hana::make_tuple('x'), "");
   static_assert(hana::equal(hana::lift<hana::ext::std::tuple_tag>('x'), std::make_tuple('x')), "");
   constexpr auto f = hana::make_pair;
   constexpr auto g = hana::flip(hana::make_pair);
   static_assert(
   hana::ap(hana::make_tuple(f, g), hana::make_tuple(1, 2, 3), hana::make_tuple('a', 'b'))
   ==
   hana::make_tuple(
   f(1, 'a'), f(1, 'b'), f(2, 'a'), f(2, 'b'), f(3, 'a'), f(3, 'b'),
   g(1, 'a'), g(1, 'b'), g(2, 'a'), g(2, 'b'), g(3, 'a'), g(3, 'b')
   )
   , "");
   int main() { }
   ap.hpp
   Defines boost::hana::ap.
   tuple.hpp
   Adapts std::tuple for use with Hana.
   flip.hpp
   Defines boost::hana::flip.
   boost::hana::equal
   constexpr auto equal
   Returns a Logical representing whether x is equal to y.
   Definition: equal.hpp:64
   boost::hana::flip
   constexpr auto flip
   Invoke a function with its two first arguments reversed.
   Definition: flip.hpp:31
   lift.hpp
   Defines boost::hana::lift.
   pair.hpp
   Defines boost::hana::pair.
5. `Monad` (definition provided automatically)
   First, `flaten`ning a `Sequence` takes a sequence of sequences and concatenates them to get a larger sequence. In other words,
   flatten([[a1, ..., aN], ..., [z1, ..., zM]]) == [
   a1, ..., aN, ..., z1, ..., zM
   ]
   This acts like a `std::tuple_cat` function, except it receives a sequence of sequences instead of a variadic pack of sequences to flatten.
   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/equal.hpp>
   #include <boost/hana/flatten.hpp>
   #include <boost/hana/tuple.hpp>
   namespace hana = boost::hana;
   static_assert(
   hana::flatten(hana::make_tuple(
   hana::make_tuple(1, 2),
   hana::make_tuple(3, 4),
   hana::make_tuple(hana::make_tuple(5, 6))
   ))
   == hana::make_tuple(1, 2, 3, 4, hana::make_tuple(5, 6))
   , "");
   int main() { }
   flatten.hpp
   Defines boost::hana::flatten.
   Also note that the model of `Monad` for `Sequence`s can be seen as modeling nondeterminism. A nondeterministic computation can be modeled as a function which returns a sequence of possible results. In this line of thought, `chain`ing a sequence of values into such a function will return a sequence of all the possible output values, i.e. a sequence of all the values applied to all the functions in the sequences.
   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/chain.hpp>
   #include <boost/hana/equal.hpp>
   #include <boost/hana/for_each.hpp>
   #include <boost/hana/traits.hpp>
   #include <boost/hana/tuple.hpp>
   #include <boost/hana/type.hpp>
   #include <type_traits>
   #include <utility>
   namespace hana = boost::hana;
   // Using the `tuple` Monad, we generate all the possible combinations of
   // cv-qualifiers and reference qualifiers. Then, we use the `optional`
   // Monad to make sure that our generic function can be called with
   // arguments of any of those types.
   // cv_qualifiers : type -> tuple(type)
   auto cv_qualifiers = [](auto t) {
   return hana::make_tuple(
   t,
   hana::traits::add_const(t),
   hana::traits::add_volatile(t),
   hana::traits::add_volatile(hana::traits::add_const(t))
   );
   };
   // ref_qualifiers : type -> tuple(type)
   auto ref_qualifiers = [](auto t) {
   return hana::make_tuple(
   hana::traits::add_lvalue_reference(t),
   hana::traits::add_rvalue_reference(t)
   );
   };
   auto possible_args = cv_qualifiers(hana::type_c<int>) | ref_qualifiers;
   BOOST_HANA_CONSTANT_CHECK(
   possible_args == hana::make_tuple(
   hana::type_c<int&>,
   hana::type_c<int&&>,
   hana::type_c<int const&>,
   hana::type_c<int const&&>,
   hana::type_c<int volatile&>,
   hana::type_c<int volatile&&>,
   hana::type_c<int const volatile&>,
   hana::type_c<int const volatile&&>
   )
   );
   struct some_function {
   template <typename T>
   void operator()(T&&) const { }
   };
   int main() {
   hana::for_each(possible_args, [](auto t) {
   using T = typename decltype(t)::type;
   static_assert(decltype(hana::is_valid(some_function{})(std::declval<T>())){},
   "some_function should be callable with any type of argument");
   });
   }
   chain.hpp
   Defines boost::hana::chain.
   for_each.hpp
   Defines boost::hana::for_each.
   boost::hana::for_each
   constexpr auto for_each
   Perform an action on each element of a foldable, discarding the result each time.
   Definition: for_each.hpp:39
   traits.hpp
   Defines function-like equivalents to the standard <type_traits>, and also to some utilities like std:...
   type.hpp
   Defines boost::hana::type and related utilities.
6. `MonadPlus` (definition provided automatically)
   `Sequence`s are models of the `MonadPlus` concept by considering the empty sequence as the unit of `concat`, and sequence concatenation as `concat`.
   // 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/append.hpp>
   #include <boost/hana/assert.hpp>
   #include <boost/hana/concat.hpp>
   #include <boost/hana/empty.hpp>
   #include <boost/hana/equal.hpp>
   #include <boost/hana/tuple.hpp>
   #include <string>
   namespace hana = boost::hana;
   using namespace std::string_literals;
   BOOST_HANA_CONSTANT_CHECK(hana::empty<hana::tuple_tag>() == hana::make_tuple());
   static_assert(hana::append(hana::make_tuple(1, '2', 3.3), nullptr)
   == hana::make_tuple(1, '2', 3.3, nullptr), "");
   int main() {
   BOOST_HANA_RUNTIME_CHECK(
   hana::concat(hana::make_tuple(1, '2', 3.3), hana::make_tuple("abcdef"s)) ==
   hana::make_tuple(1, '2', 3.3, "abcdef"s)
   );
   }
   append.hpp
   Defines boost::hana::append.
   concat.hpp
   Defines boost::hana::concat.
   empty.hpp
   Defines boost::hana::empty.
   boost::hana::append
   constexpr auto append
   Append an element to a monadic structure.
   Definition: append.hpp:52
   boost::hana::concat
   constexpr auto concat
   Combine two monadic structures together.
   Definition: concat.hpp:47
7. `Foldable`
   The model of `Foldable` for `Sequence`s is uniquely determined by the model of `Iterable`.
   // 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/fold_left.hpp>
   #include <boost/hana/tuple.hpp>
   #include <sstream>
   namespace hana = boost::hana;
   auto to_string = [](auto x) {
   std::ostringstream ss;
   ss << x;
   return ss.str();
   };
   auto show = [](auto x, auto y) {
   return "(" + to_string(x) + " + " + to_string(y) + ")";
   };
   int main() {
   BOOST_HANA_RUNTIME_CHECK(
   hana::fold_left(hana::make_tuple(2, "3", '4'), "1", show) == "(((1 + 2) + 3) + 4)"
   );
   }
   fold_left.hpp
   Defines boost::hana::fold_left.
8. `Iterable`
   The model of `Iterable` for `Sequence`s corresponds to iteration over each element of the sequence, in order. This model is not provided automatically, and it is in fact part of the minimal complete definition for the `Sequence` concept.
   // 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/drop_front.hpp>
   #include <boost/hana/equal.hpp>
   #include <boost/hana/front.hpp>
   #include <boost/hana/is_empty.hpp>
   #include <boost/hana/tuple.hpp>
   namespace hana = boost::hana;
   static_assert(hana::front(hana::make_tuple(1, '2', 3.3)) == 1, "");
   static_assert(hana::drop_front(hana::make_tuple(1, '2', 3.3)) == hana::make_tuple('2', 3.3), "");
   BOOST_HANA_CONSTANT_CHECK(!hana::is_empty(hana::make_tuple(1, '2', 3.3)));
   BOOST_HANA_CONSTANT_CHECK(hana::is_empty(hana::make_tuple()));
   int main() { }
   drop_front.hpp
   Defines boost::hana::drop_front.
   front.hpp
   Defines boost::hana::front.
   boost::hana::is_empty
   constexpr auto is_empty
   Returns whether the iterable is empty.
   Definition: is_empty.hpp:33
   boost::hana::front
   constexpr auto front
   Returns the first element of a non-empty iterable.
   Definition: front.hpp:32
   boost::hana::drop_front
   constexpr auto drop_front
   Drop the first n elements of an iterable, and return the rest.
   Definition: drop_front.hpp:47
   is_empty.hpp
   Defines boost::hana::is_empty.
9. `Searchable` (definition provided automatically)
   Searching through a `Sequence` is equivalent to just searching through a list of the values it contains. The keys and the values on which the search is performed are both the elements of the sequence.
   // 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/contains.hpp>
   #include <boost/hana/core/is_a.hpp>
   #include <boost/hana/equal.hpp>
   #include <boost/hana/find_if.hpp>
   #include <boost/hana/optional.hpp>
   #include <boost/hana/tuple.hpp>
   #include <string>
   namespace hana = boost::hana;
   using namespace std::string_literals;
   int main() {
   BOOST_HANA_RUNTIME_CHECK(
   hana::find_if(hana::make_tuple(1, '2', 3.3, "abc"s), hana::is_a<std::string>) == hana::just("abc"s)
   );
   BOOST_HANA_RUNTIME_CHECK(
   "abc"s ^hana::in^ hana::make_tuple(1, '2', 3.3, "abc"s)
   );
   }
   contains.hpp
   Defines boost::hana::contains and boost::hana::in.
   is_a.hpp
   Defines boost::hana::is_a and boost::hana::is_an.
   find_if.hpp
   Defines boost::hana::find_if.
   boost::hana::in
   constexpr auto in
   Return whether the key occurs in the structure.
   Definition: contains.hpp:70
   boost::hana::find_if
   constexpr auto find_if
   Finds the value associated to the first key satisfying a predicate.
   Definition: find_if.hpp:41
   optional.hpp
   Defines boost::hana::optional.

## Concrete models

`hana::tuple`

## Variables
constexpr auto | boost::hana::drop_back
| Drop the last `n` elements of a finite sequence, and return the rest. More...
constexpr insert_t | boost::hana::insert {}
| Insert a value at a given index in a sequence. More...
constexpr auto | boost::hana::insert_range
| Insert several values at a given index in a sequence. More...
constexpr auto | boost::hana::intersperse
| Insert a value between each pair of elements in a finite sequence. More...
constexpr auto | boost::hana::permutations
| Return a sequence of all the permutations of the given sequence. More...
constexpr auto | boost::hana::remove_at
| Remove the element at a given index from a sequence. More...
template<std::size_t n>
constexpr auto | boost::hana::remove_at_c
| Equivalent to `remove_at`; provided for convenience. More...
constexpr auto | boost::hana::remove_range
| Remove the elements inside a given range of indices from a sequence. More...
template<std::size_t from, std::size_t to>
constexpr auto | boost::hana::remove_range_c
| Equivalent to `remove_range`; provided for convenience. More...
constexpr auto | boost::hana::reverse
| Reverse a sequence. More...
constexpr auto | boost::hana::scan_left
| Fold a Sequence to the left and return a list containing the successive reduction states. More...
constexpr auto | boost::hana::scan_right
| Fold a Sequence to the right and return a list containing the successive reduction states. More...
constexpr auto | boost::hana::slice
| Extract the elements of a `Sequence` at the given indices. More...
template<std::size_t from, std::size_t to>
constexpr auto | boost::hana::slice_c
| Shorthand to `slice` a contiguous range of elements. More...
constexpr auto | boost::hana::take_back
| Returns the last `n` elements of a sequence, or the whole sequence if the sequence has less than `n` elements. More...
template<std::size_t n>
constexpr auto | boost::hana::take_back_c
| Equivalent to `take_back`; provided for convenience. More...
constexpr auto | boost::hana::take_front
| Returns the first `n` elements of a sequence, or the whole sequence if the sequence has less than `n` elements. More...
template<std::size_t n>
constexpr auto | boost::hana::take_front_c
| Equivalent to `take_front`; provided for convenience. More...
constexpr auto | boost::hana::take_while
| Take elements from a sequence while the `predicate` is satisfied. More...
constexpr auto | boost::hana::zip
| Zip one sequence or more. More...
constexpr auto | boost::hana::zip_shortest
| Zip one sequence or more. More...
constexpr auto | boost::hana::zip_shortest_with
| Zip one sequence or more with a given function. More...
constexpr auto | boost::hana::zip_with
| Zip one sequence or more with a given function. More...

## Variable Documentation

## ◆ drop_back

constexpr auto boost::hana::drop_back
| constexpr

`#include <boost/hana/fwd/drop_back.hpp>`

Initial value:
= [](auto&& xs[, auto const& n]) {
return tag-dispatched;
}

Drop the last `n` elements of a finite sequence, and return the rest.

Given a finite `Sequence` `xs` with a linearization of `[x1, ..., xm]` and a non-negative `IntegralConstant` `n`, `drop_back(xs, n)` is a sequence with the same tag as `xs` whose linearization is `[x1, ..., xm-n]`. If `n` is not given, it defaults to an `IntegralConstant` with a value equal to `1`.

In case `length(xs) <= n`, `drop_back` will simply drop the whole sequence without failing, thus returning an empty sequence.

Parameters

  xs | The sequence from which elements are dropped.
  n | A non-negative `IntegralConstant` representing the number of elements to be dropped from the end of the sequence. If `n` is not given, it defaults to an `IntegralConstant` with a value equal to `1`.

## 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/drop_back.hpp>
#include <boost/hana/equal.hpp>
#include <boost/hana/integral_constant.hpp>
#include <boost/hana/tuple.hpp>
namespace hana = boost::hana;
constexpr auto xs = hana::make_tuple(0, '1', 2.0);
static_assert(hana::drop_back(xs, hana::size_c<0>) == xs, "");
static_assert(hana::drop_back(xs, hana::size_c<1>) == hana::make_tuple(0, '1'), "");
static_assert(hana::drop_back(xs, hana::size_c<2>) == hana::make_tuple(0), "");
BOOST_HANA_CONSTANT_CHECK(hana::drop_back(xs, hana::size_c<3>) == hana::make_tuple());
BOOST_HANA_CONSTANT_CHECK(hana::drop_back(xs, hana::size_c<4>) == hana::make_tuple());
static_assert(hana::drop_back(xs) == hana::make_tuple(0, '1'), "");
int main() { }
drop_back.hpp
Defines boost::hana::drop_back.
boost::hana::drop_back
constexpr auto drop_back
Drop the last n elements of a finite sequence, and return the rest.
Definition: drop_back.hpp:44
integral_constant.hpp
Defines boost::hana::integral_constant.

## ◆ insert

constexpr auto boost::hana::insert {}
| related

`#include <boost/hana/fwd/insert.hpp>`

Insert a value at a given index in a sequence.

Given a sequence, an index and an element to insert, `insert` inserts the element at the given index.

Parameters

  xs | The sequence in which a value should be inserted.
  n | The index at which an element should be inserted. This must be a non-negative `Constant` of an integral type, and it must also be true that `n < length(xs)` if `xs` is a finite sequence.
  element | The element to insert in the sequence.

## 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/insert.hpp>
#include <boost/hana/integral_constant.hpp>
#include <boost/hana/tuple.hpp>
#include <string>
namespace hana = boost::hana;
using namespace hana::literals;
using namespace std::literals;
int main() {
auto xs = hana::make_tuple("Hello"s, "world!"s);
BOOST_HANA_RUNTIME_CHECK(
hana::insert(xs, 1_c, " "s) == hana::make_tuple("Hello"s, " "s, "world!"s)
);
}
boost::hana::insert
constexpr insert_t insert
Insert a value at a given index in a sequence.
Definition: insert.hpp:29
insert.hpp
Defines boost::hana::insert.

## ◆ insert_range

constexpr auto boost::hana::insert_range
| constexpr

`#include <boost/hana/fwd/insert_range.hpp>`

Initial value:
= [](auto&& xs, auto&& n, auto&& elements) {
return tag-dispatched;
}

Insert several values at a given index in a sequence.

Given a sequence, an index and any `Foldable` containing elements to insert, `insert_range` inserts the elements in the `Foldable` at the given index of the sequence.

Parameters

  xs | The sequence in which values should be inserted.
  n | The index at which elements should be inserted. This must be a non-negative `Constant` of an integral type, and it must also be true that `n < length(xs)` if `xs` is a finite sequence.
  elements | A `Foldable` containing elements to insert in the sequence.

## 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/insert_range.hpp>
#include <boost/hana/integral_constant.hpp>
#include <boost/hana/tuple.hpp>
#include <string>
namespace hana = boost::hana;
using namespace hana::literals;
using namespace std::literals;
int main() {
auto xs = hana::make_tuple("Hello"s, "world!"s);
BOOST_HANA_RUNTIME_CHECK(
hana::insert_range(xs, 1_c, hana::make_tuple(1, 2, 3)) == hana::make_tuple("Hello"s, 1, 2, 3, "world!"s)
);
}
boost::hana::insert_range
constexpr auto insert_range
Insert several values at a given index in a sequence.
Definition: insert_range.hpp:41
insert_range.hpp
Defines boost::hana::insert_range.

## ◆ intersperse

constexpr auto boost::hana::intersperse
| constexpr

`#include <boost/hana/fwd/intersperse.hpp>`

Initial value:
= [](auto&& xs, auto&& z) {
return tag-dispatched;
}

Insert a value between each pair of elements in a finite sequence.

Given a finite `Sequence` `xs` with a linearization of `[x1, x2, ..., xn]`, `intersperse(xs, z)` is a new sequence with a linearization of `[x1, z, x2, z, x3, ..., xn-1, z, xn]`. In other words, it inserts the `z` element between every pair of elements of the original sequence. If the sequence is empty or has a single element, `intersperse` returns the sequence as-is. In all cases, the sequence must be finite.

Parameters

  xs | The sequence in which a value is interspersed.
  z | The value to be inserted between every pair of elements of the sequence.

## 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/intersperse.hpp>
#include <boost/hana/tuple.hpp>
namespace hana = boost::hana;
static_assert(hana::intersperse(hana::make_tuple(1, '2', 3.3), 'x') == hana::make_tuple(1, 'x', '2', 'x', 3.3), "");
BOOST_HANA_CONSTANT_CHECK(hana::intersperse(hana::make_tuple(), 'x') == hana::make_tuple());
int main() { }
boost::hana::intersperse
constexpr auto intersperse
Insert a value between each pair of elements in a finite sequence.
Definition: intersperse.hpp:41
intersperse.hpp
Defines boost::hana::intersperse.

## ◆ permutations

constexpr auto boost::hana::permutations
| constexpr

`#include <boost/hana/fwd/permutations.hpp>`

Initial value:
= [](auto&& xs) {
return tag-dispatched;
}

Return a sequence of all the permutations of the given sequence.

Specifically, `permutations(xs)` is a sequence whose elements are permutations of the original sequence `xs`. The permutations are not guaranteed to be in any specific order. Also note that the number of permutations grows very rapidly as the length of the original sequence increases. The growth rate is `O(length(xs)!)`; with a sequence `xs` of length only 8, `permutations(xs)` contains over 40 000 elements!

## 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/all_of.hpp>
#include <boost/hana/assert.hpp>
#include <boost/hana/config.hpp>
#include <boost/hana/contains.hpp>
#include <boost/hana/functional/curry.hpp>
#include <boost/hana/permutations.hpp>
#include <boost/hana/tuple.hpp>
namespace hana = boost::hana;
BOOST_HANA_CONSTEXPR_LAMBDA auto is_permutation_of = hana::curry<2>([](auto xs, auto perm) {
return hana::contains(hana::permutations(xs), perm);
});
int main() {
BOOST_HANA_CONSTEXPR_CHECK(
hana::all_of(
hana::make_tuple(
hana::make_tuple('1', 2, 3.0),
hana::make_tuple('1', 3.0, 2),
hana::make_tuple(2, '1', 3.0),
hana::make_tuple(2, 3.0, '1'),
hana::make_tuple(3.0, '1', 2),
hana::make_tuple(3.0, 2, '1')
),
is_permutation_of(hana::make_tuple('1', 2, 3.0))
)
);
}
all_of.hpp
Defines boost::hana::all_of.
config.hpp
Defines configuration macros used throughout the library.
curry.hpp
Defines boost::hana::curry.
boost::hana::contains
constexpr auto contains
Returns whether the key occurs in the structure.
Definition: contains.hpp:42
boost::hana::all_of
constexpr auto all_of
Returns whether all the keys of the structure satisfy the predicate.
Definition: all_of.hpp:38
boost::hana::permutations
constexpr auto permutations
Return a sequence of all the permutations of the given sequence.
Definition: permutations.hpp:34
BOOST_HANA_CONSTEXPR_CHECK
#define BOOST_HANA_CONSTEXPR_CHECK(...)
Equivalent to BOOST_HANA_CONSTEXPR_ASSERT, but not influenced by the BOOST_HANA_CONFIG_DISABLE_ASSERT...
Definition: assert.hpp:300
permutations.hpp
Defines boost::hana::permutations.

## ◆ remove_at

constexpr auto boost::hana::remove_at
| constexpr

`#include <boost/hana/fwd/remove_at.hpp>`

Initial value:
= [](auto&& xs, auto const& n) {
return tag-dispatched;
}

Remove the element at a given index from a sequence.

`remove_at` returns a new sequence identical to the original, except that the element at the given index is removed. Specifically, `remove_at([x0, ..., xn-1, xn, xn+1, ..., xm], n)` is a new sequence equivalent to `[x0, ..., xn-1, xn+1, ..., xm]`.

Note
  The behavior is undefined if the index is out of the bounds of the sequence.

Parameters

  xs | A sequence from which an element is to be removed.
  n | An non-negative `IntegralConstant` representing the index of the element to be removed from the sequence. The behavior is undefined if that index is not in the bounds of the sequence.

## 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/equal.hpp>
#include <boost/hana/integral_constant.hpp>
#include <boost/hana/remove_at.hpp>
#include <boost/hana/tuple.hpp>
namespace hana = boost::hana;
constexpr auto xs = hana::make_tuple(0, '1', 2.2, 3u);
static_assert(hana::remove_at(xs, hana::size_c<2>) == hana::make_tuple(0, '1', 3u), "");
int main() { }
boost::hana::remove_at
constexpr auto remove_at
Remove the element at a given index from a sequence.
Definition: remove_at.hpp:46
remove_at.hpp
Defines boost::hana::remove_at and boost::hana::remove_at_c.

## ◆ remove_at_c

template<std::size_t n>

constexpr auto boost::hana::remove_at_c
| constexpr

`#include <boost/hana/fwd/remove_at.hpp>`

Initial value:
= [](auto&& xs) {
return hana::remove_at(forwarded(xs), hana::size_c<n>);
}

Equivalent to `remove_at`; provided for convenience.

## 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/equal.hpp>
#include <boost/hana/remove_at.hpp>
#include <boost/hana/tuple.hpp>
namespace hana = boost::hana;
constexpr auto xs = hana::make_tuple(0, '1', 2.2, 3u);
static_assert(hana::remove_at_c<2>(xs) == hana::make_tuple(0, '1', 3u), "");
int main() { }

## ◆ remove_range

constexpr auto boost::hana::remove_range
| constexpr

`#include <boost/hana/fwd/remove_range.hpp>`

Initial value:
= [](auto&& xs, auto const& from, auto const& to) {
return tag-dispatched;
}
boost::hana::to
constexpr auto to
Converts an object from one data type to another.
Definition: to.hpp:97

Remove the elements inside a given range of indices from a sequence.

`remove_range` returns a new sequence identical to the original, except that elements at indices in the provided range are removed. Specifically, `remove_range([x0, ..., xn], from, to)` is a new sequence equivalent to `[x0, ..., x_from-1, x_to, ..., xn]`.

Note
  The behavior is undefined if the range contains any index out of the bounds of the sequence.

Parameters

  xs | A sequence from which elements are removed.
  [from,to) | An half-open interval of `IntegralConstant`s representing the indices of the elements to be removed from the sequence. The `IntegralConstant`s in the half-open interval must be non-negative and in the bounds of the sequence. The half-open interval must also be valid, meaning that `from <= to`.

## 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/equal.hpp>
#include <boost/hana/integral_constant.hpp>
#include <boost/hana/remove_range.hpp>
#include <boost/hana/tuple.hpp>
namespace hana = boost::hana;
constexpr auto xs = hana::make_tuple(0, '1', 2.2, 3u, 4, 5.5);
static_assert(hana::remove_range(xs, hana::size_c<2>, hana::size_c<4>) == hana::make_tuple(0, '1', 4, 5.5), "");
int main() { }
boost::hana::remove_range
constexpr auto remove_range
Remove the elements inside a given range of indices from a sequence.
Definition: remove_range.hpp:49
remove_range.hpp
Defines boost::hana::remove_range and boost::hana::remove_range_c.

## ◆ remove_range_c

template<std::size_t from, std::size_t to>

constexpr auto boost::hana::remove_range_c
| constexpr

`#include <boost/hana/fwd/remove_range.hpp>`

Initial value:
= [](auto&& xs) {
return hana::remove_range(forwarded(xs), hana::size_c<from>, hana::size_c<to>);
}

Equivalent to `remove_range`; provided for convenience.

## 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/equal.hpp>
#include <boost/hana/remove_range.hpp>
#include <boost/hana/tuple.hpp>
namespace hana = boost::hana;
constexpr auto xs = hana::make_tuple(0, '1', 2.2, 3u, 4, 5.5);
static_assert(hana::remove_range_c<2, 4>(xs) == hana::make_tuple(0, '1', 4, 5.5), "");
int main() { }

## ◆ reverse

constexpr auto boost::hana::reverse
| constexpr

`#include <boost/hana/fwd/reverse.hpp>`

Initial value:
= [](auto&& xs) {
return tag-dispatched;
}

Reverse a sequence.

Specifically, `reverse(xs)` is a new sequence containing the same elements as `xs`, except in reverse order.

Parameters

  xs | The sequence to reverse.

## 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/equal.hpp>
#include <boost/hana/reverse.hpp>
#include <boost/hana/tuple.hpp>
namespace hana = boost::hana;
static_assert(hana::reverse(hana::make_tuple(1, '2', 3.3)) == hana::make_tuple(3.3, '2', 1), "");
int main() { }
boost::hana::reverse
constexpr auto reverse
Reverse a sequence.
Definition: reverse.hpp:33
reverse.hpp
Defines boost::hana::reverse.

## ◆ scan_left

constexpr auto boost::hana::scan_left
| constexpr

`#include <boost/hana/fwd/scan_left.hpp>`

Initial value:
= [](auto&& xs[, auto&& state], auto const& f) {
return tag-dispatched;
}

Fold a Sequence to the left and return a list containing the successive reduction states.

Like `fold_left`, `scan_left` reduces a sequence to a single value using a binary operation. However, unlike `fold_left`, it builds up a sequence of the intermediary results computed along the way and returns that instead of only the final reduction state. Like `fold_left`, `scan_left` can be used with or without an initial reduction state.

When the sequence is empty, two things may arise. If an initial state was provided, a singleton list containing that state is returned. Otherwise, if no initial state was provided, an empty list is returned. In particular, unlike for `fold_left`, using `scan_left` on an empty sequence without an initial state is not an error.

More specifically, `scan_left([x1, ..., xn], state, f)` is a sequence whose `i`th element is equivalent to `fold_left([x1, ..., xi], state, f)`. The no-state variant is handled in an analogous way. For illustration, consider this left fold on a short sequence:

fold_left([x1, x2, x3], state, f) == f(f(f(state, x1), x2), x3)

The analogous sequence generated with `scan_left` will be

scan_left([x1, x2, x3], state, f) == [
state,
f(state, x1),
f(f(state, x1), x2),
f(f(f(state, x1), x2), x3)
]
boost::hana::scan_left
constexpr auto scan_left
Fold a Sequence to the left and return a list containing the successive reduction states.
Definition: scan_left.hpp:86

Similarly, consider this left fold (without an initial state) on a short sequence:

fold_left([x1, x2, x3, x4], f) == f(f(f(x1, x2), x3), x4)

The analogous sequence generated with `scan_left` will be

scan_left([x1, x2, x3, x4], f) == [
x1,
f(x1, x2),
f(f(x1, x2), x3),
f(f(f(x1, x2), x3), x4)
]

Parameters

  xs | The sequence to scan from the left.
  state | The (optional) initial reduction state.
  f | A binary function called as `f(state, x)`, where `state` is the result accumulated so far and `x` is an element in the sequence. If no initial state is provided, `f` is called as `f(x1, x2)`, where `x1` and `x2` are both elements of the sequence.

## 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/scan_left.hpp>
#include <boost/hana/tuple.hpp>
#include <sstream>
namespace hana = boost::hana;
auto to_string = [](auto x) {
std::ostringstream ss;
ss << x;
return ss.str();
};
auto f = [](auto state, auto element) {
return "f(" + to_string(state) + ", " + to_string(element) + ")";
};
int main() {
// with initial state
BOOST_HANA_RUNTIME_CHECK(hana::scan_left(hana::make_tuple(2, "3", '4'), 1, f) == hana::make_tuple(
1,
"f(1, 2)",
"f(f(1, 2), 3)",
"f(f(f(1, 2), 3), 4)"
));
// without initial state
BOOST_HANA_RUNTIME_CHECK(hana::scan_left(hana::make_tuple(1, "2", '3'), f) == hana::make_tuple(
1,
"f(1, 2)",
"f(f(1, 2), 3)"
));
}
scan_left.hpp
Defines boost::hana::scan_left.

## ◆ scan_right

constexpr auto boost::hana::scan_right
| constexpr

`#include <boost/hana/fwd/scan_right.hpp>`

Initial value:
= [](auto&& xs[, auto&& state], auto const& f) {
return tag-dispatched;
}

Fold a Sequence to the right and return a list containing the successive reduction states.

Like `fold_right`, `scan_right` reduces a sequence to a single value using a binary operation. However, unlike `fold_right`, it builds up a sequence of the intermediary results computed along the way and returns that instead of only the final reduction state. Like `fold_right`, `scan_right` can be used with or without an initial reduction state.

When the sequence is empty, two things may arise. If an initial state was provided, a singleton list containing that state is returned. Otherwise, if no initial state was provided, an empty list is returned. In particular, unlike for `fold_right`, using `scan_right` on an empty sequence without an initial state is not an error.

More specifically, `scan_right([x1, ..., xn], state, f)` is a sequence whose `i`th element is equivalent to `fold_right([x1, ..., xi], state, f)`. The no-state variant is handled in an analogous way. For illustration, consider this right fold on a short sequence:

fold_right([x1, x2, x3], state, f) == f(x1, f(x2, f(x3, state)))

The analogous sequence generated with `scan_right` will be

scan_right([x1, x2, x3], state, f) == [
f(x1, f(x2, f(x3, state))),
f(x2, f(x3, state)),
f(x3, state),
state
]
boost::hana::scan_right
constexpr auto scan_right
Fold a Sequence to the right and return a list containing the successive reduction states.
Definition: scan_right.hpp:86

Similarly, consider this right fold (without an initial state) on a short sequence:

fold_right([x1, x2, x3, x4], f) == f(x1, f(x2, f(x3, x4)))

The analogous sequence generated with `scan_right` will be

scan_right([x1, x2, x3, x4], f) == [
f(x1, f(x2, f(x3, x4))),
f(x2, f(x3, x4)),
f(x3, x4),
x4
]

Parameters

  xs | The sequence to scan from the right.
  state | The (optional) initial reduction state.
  f | A binary function called as `f(x, state)`, where `state` is the result accumulated so far and `x` is an element in the sequence. When no initial state is provided, `f` is called as `f(x1, x2)`, where `x1` and `x2` are elements of the sequence.

## 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/scan_right.hpp>
#include <boost/hana/tuple.hpp>
#include <sstream>
namespace hana = boost::hana;
auto to_string = [](auto x) {
std::ostringstream ss;
ss << x;
return ss.str();
};
auto f = [](auto element, auto state) {
return "f(" + to_string(element) + ", " + to_string(state) + ")";
};
int main() {
// with initial state
BOOST_HANA_RUNTIME_CHECK(hana::scan_right(hana::make_tuple(1, "2", '3'), 4, f) == hana::make_tuple(
"f(1, f(2, f(3, 4)))",
"f(2, f(3, 4))",
"f(3, 4)",
4
));
// without initial state
BOOST_HANA_RUNTIME_CHECK(hana::scan_right(hana::make_tuple(1, "2", '3'), f) == hana::make_tuple(
"f(1, f(2, 3))",
"f(2, 3)",
'3'
));
}
scan_right.hpp
Defines boost::hana::scan_right.

## ◆ slice

constexpr auto boost::hana::slice
| constexpr

`#include <boost/hana/fwd/slice.hpp>`

Initial value:
= [](auto&& xs, auto&& indices) {
return tag-dispatched;
}

Extract the elements of a `Sequence` at the given indices.

Given an arbitrary sequence of `indices`, `slice` returns a new sequence of the elements of the original sequence that appear at those indices. In other words,

slice([x1, ..., xn], [i1, ..., ik]) == [x_i1, ..., x_ik]
boost::hana::slice
constexpr auto slice
Extract the elements of a Sequence at the given indices.
Definition: slice.hpp:53

The indices do not have to be ordered or contiguous in any particular way, but they must not be out of the bounds of the sequence. It is also possible to specify the same index multiple times, in which case the element at this index will be repeatedly included in the resulting sequence.

Parameters

  xs | The sequence from which a subsequence is extracted.
  indices | A compile-time `Foldable` containing non-negative `IntegralConstant`s representing the indices. The indices are 0-based, and they must all be in bounds of the `xs` sequence. Note that any `Foldable` will really do (no need for an `Iterable`, for example); the linearization of the `indices` is used to determine the order of the elements included in the slice.

## 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/filter.hpp>
#include <boost/hana/integral_constant.hpp>
#include <boost/hana/length.hpp>
#include <boost/hana/mod.hpp>
#include <boost/hana/range.hpp>
#include <boost/hana/slice.hpp>
#include <boost/hana/tuple.hpp>
#include <boost/hana/type.hpp>
namespace hana = boost::hana;
using namespace hana::literals;
// Slice a contiguous range
constexpr auto xs = hana::make_tuple(0, '1', 2.2, 3_c, hana::type_c<float>);
static_assert(
hana::slice(xs, hana::tuple_c<std::size_t, 1, 2, 3>) ==
hana::make_tuple('1', 2.2, 3_c)
, "");
// A more complex example with a non-contiguous range
constexpr auto letters = hana::to_tuple(hana::range_c<char, 'a', 'z'>);
constexpr auto indices = hana::to_tuple(hana::make_range(hana::size_c<0>, hana::length(letters)));
auto even_indices = hana::filter(indices, [](auto n) {
return n % hana::size_c<2> == hana::size_c<0>;
});
BOOST_HANA_CONSTANT_CHECK(
hana::slice(letters, even_indices) == hana::tuple_c<char,
'a', 'c', 'e', 'g', 'i', 'k', 'm', 'o', 'q', 's', 'u', 'w', 'y'
>
);
int main() { }
to.hpp
Defines boost::hana::to and related utilities.
filter.hpp
Defines boost::hana::filter.
boost::hana::length
constexpr auto length
Return the number of elements in a foldable structure.
Definition: length.hpp:34
boost::hana::filter
constexpr auto filter
Filter a monadic structure using a custom predicate.
Definition: filter.hpp:65
length.hpp
Defines boost::hana::length.
mod.hpp
Defines boost::hana::mod.
range.hpp
Defines boost::hana::range.
slice.hpp
Defines boost::hana::slice and boost::hana::slice_c.

## ◆ slice_c

template<std::size_t from, std::size_t to>

constexpr auto boost::hana::slice_c
| constexpr

`#include <boost/hana/fwd/slice.hpp>`

Initial value:
= [](auto&& xs) {
return hana::slice(forwarded(xs), hana::range_c<std::size_t, from, to>);
}

Shorthand to `slice` a contiguous range of elements.

`slice_c` is simply a shorthand to slice a contiguous range of elements. In particular, `slice_c<from, to>(xs)` is equivalent to `slice(xs, range_c<std::size_t, from, to>)`, which simply slices all the elements of `xs` contained in the half-open interval delimited by `[from, to)`. Like for `slice`, the indices used with `slice_c` are 0-based and they must be in the bounds of the sequence being sliced.

Template Parameters

  from | The index of the first element in the slice.
  to | One-past the index of the last element in the slice. It must hold that `from <= to`.

## 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/equal.hpp>
#include <boost/hana/slice.hpp>
#include <boost/hana/tuple.hpp>
#include <boost/hana/type.hpp>
namespace hana = boost::hana;
static_assert(
hana::slice_c<1, 3>(hana::make_tuple(1, '2', 3.3, hana::type_c<float>))
==
hana::make_tuple('2', 3.3)
, "");
int main() { }

## ◆ take_back

constexpr auto boost::hana::take_back
| constexpr

`#include <boost/hana/fwd/take_back.hpp>`

Initial value:
= [](auto&& xs, auto const& n) {
return tag-dispatched;
}

Returns the last `n` elements of a sequence, or the whole sequence if the sequence has less than `n` elements.

Given a `Sequence` `xs` and an `IntegralConstant` `n`, `take_back(xs, n)` is a new sequence containing the last `n` elements of `xs`, in the same order. If `length(xs) <= n`, the whole sequence is returned and no error is triggered.

Parameters

  xs | The sequence to take the elements from.
  n | A non-negative `IntegralConstant` representing the number of elements to keep in the resulting sequence.

## 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/take_back.hpp>
#include <boost/hana/tuple.hpp>
namespace hana = boost::hana;
BOOST_HANA_CONSTANT_CHECK(hana::take_back(hana::make_tuple(1, '2', 3.3), hana::size_c<0>) == hana::make_tuple());
static_assert(hana::take_back(hana::make_tuple(1, '2', 3.3), hana::size_c<1>) == hana::make_tuple(3.3), "");
static_assert(hana::take_back(hana::make_tuple(1, '2', 3.3), hana::size_c<2>) == hana::make_tuple('2', 3.3), "");
static_assert(hana::take_back(hana::make_tuple(1, '2', 3.3), hana::size_c<3>) == hana::make_tuple(1, '2', 3.3), "");
static_assert(hana::take_back(hana::make_tuple(1, '2', 3.3), hana::size_c<4>) == hana::make_tuple(1, '2', 3.3), "");
int main() { }
boost::hana::take_back
constexpr auto take_back
Returns the last n elements of a sequence, or the whole sequence if the sequence has less than n elem...
Definition: take_back.hpp:42
take_back.hpp
Defines boost::hana::take_back.

## ◆ take_back_c

template<std::size_t n>

constexpr auto boost::hana::take_back_c
| constexpr

`#include <boost/hana/fwd/take_back.hpp>`

Initial value:
= [](auto&& xs) {
return hana::take_back(forwarded(xs), hana::size_c<n>);
}

Equivalent to `take_back`; provided for convenience.

## 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/equal.hpp>
#include <boost/hana/take_back.hpp>
#include <boost/hana/tuple.hpp>
namespace hana = boost::hana;
static_assert(hana::take_back_c<2>(hana::make_tuple(1, '2', 3.3)) == hana::make_tuple('2', 3.3), "");
int main() { }

## ◆ take_front

constexpr auto boost::hana::take_front
| constexpr

`#include <boost/hana/fwd/take_front.hpp>`

Initial value:
= [](auto&& xs, auto const& n) {
return tag-dispatched;
}

Returns the first `n` elements of a sequence, or the whole sequence if the sequence has less than `n` elements.

Given a `Sequence` `xs` and an `IntegralConstant` `n`, `take_front(xs, n)` is a new sequence containing the first `n` elements of `xs`, in the same order. If `length(xs) <= n`, the whole sequence is returned and no error is triggered.

Parameters

  xs | The sequence to take the elements from.
  n | A non-negative `IntegralConstant` representing the number of elements to keep in the resulting sequence.

## 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/take_front.hpp>
#include <boost/hana/tuple.hpp>
namespace hana = boost::hana;
BOOST_HANA_CONSTANT_CHECK(hana::take_front(hana::make_tuple(1, '2', 3.3), hana::size_c<0>) == hana::make_tuple());
static_assert(hana::take_front(hana::make_tuple(1, '2', 3.3), hana::size_c<1>) == hana::make_tuple(1), "");
static_assert(hana::take_front(hana::make_tuple(1, '2', 3.3), hana::size_c<2>) == hana::make_tuple(1, '2'), "");
static_assert(hana::take_front(hana::make_tuple(1, '2', 3.3), hana::size_c<3>) == hana::make_tuple(1, '2', 3.3), "");
static_assert(hana::take_front(hana::make_tuple(1, '2', 3.3), hana::size_c<4>) == hana::make_tuple(1, '2', 3.3), "");
int main() { }
boost::hana::take_front
constexpr auto take_front
Returns the first n elements of a sequence, or the whole sequence if the sequence has less than n ele...
Definition: take_front.hpp:42
take_front.hpp
Defines boost::hana::take_front and boost::hana::take_front_c.

## ◆ take_front_c

template<std::size_t n>

constexpr auto boost::hana::take_front_c
| constexpr

`#include <boost/hana/fwd/take_front.hpp>`

Initial value:
= [](auto&& xs) {
return hana::take_front(forwarded(xs), hana::size_c<n>);
}

Equivalent to `take_front`; provided for convenience.

## 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/equal.hpp>
#include <boost/hana/take_front.hpp>
#include <boost/hana/tuple.hpp>
namespace hana = boost::hana;
static_assert(hana::take_front_c<2>(hana::make_tuple(1, '2', 3.3)) == hana::make_tuple(1, '2'), "");
int main() { }

## ◆ take_while

constexpr auto boost::hana::take_while
| constexpr

`#include <boost/hana/fwd/take_while.hpp>`

Initial value:
= [](auto&& xs, auto&& predicate) {
return tag-dispatched;
}

Take elements from a sequence while the `predicate` is satisfied.

Specifically, `take_while` returns a new sequence containing the longest prefix of `xs` in which all the elements satisfy the given predicate.

Parameters

  xs | The sequence to take elements from.
  predicate | A function called as `predicate(x)`, where `x` is an element of the sequence, and returning a `Logical` representing whether `x` should be included in the resulting sequence. In the current version of the library, `predicate` has to return a `Constant Logical`.

## 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/less.hpp>
#include <boost/hana/take_while.hpp>
#include <boost/hana/tuple.hpp>
namespace hana = boost::hana;
using namespace hana::literals;
BOOST_HANA_CONSTANT_CHECK(
hana::take_while(hana::tuple_c<int, 0, 1, 2, 3>, hana::less.than(2_c))
==
hana::tuple_c<int, 0, 1>
);
int main() { }
boost::hana::less
constexpr auto less
Returns a Logical representing whether x is less than y.
Definition: less.hpp:37
boost::hana::take_while
constexpr auto take_while
Take elements from a sequence while the predicate is satisfied.
Definition: take_while.hpp:40
take_while.hpp
Defines boost::hana::take_while.

## ◆ zip

constexpr auto boost::hana::zip
| constexpr

`#include <boost/hana/fwd/zip.hpp>`

Initial value:
= [](auto&& x1, ..., auto&& xn) {
return tag-dispatched;
}

Zip one sequence or more.

Given `n` sequences `s1, ..., sn`, `zip` produces a sequence whose `i`-th element is a tuple of `(s1[i], ..., sn[i])`, where `sk[i]` denotes the `i`-th element of the `k`-th sequence. In other words, `zip` produces a sequence of the form

[
make_tuple(s1[0], ..., sn[0]),
make_tuple(s1[1], ..., sn[1]),
...
make_tuple(s1[M], ..., sn[M])
]

where `M` is the length of the sequences, which are all assumed to have the same length. Assuming the sequences to all have the same size allows the library to perform some optimizations. To zip sequences that may have different lengths, `zip_shortest` should be used instead. Also note that it is an error to provide no sequence at all, i.e. `zip` expects at least one sequence.

## 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/equal.hpp>
#include <boost/hana/tuple.hpp>
#include <boost/hana/zip.hpp>
namespace hana = boost::hana;
static_assert(
hana::zip(hana::make_tuple(1, 'a'), hana::make_tuple(2, 3.3))
==
hana::make_tuple(hana::make_tuple(1, 2), hana::make_tuple('a', 3.3))
, "");
int main() { }
boost::hana::zip
constexpr auto zip
Zip one sequence or more.
Definition: zip.hpp:45
zip.hpp
Defines boost::hana::zip.

## ◆ zip_shortest

constexpr auto boost::hana::zip_shortest
| constexpr

`#include <boost/hana/fwd/zip_shortest.hpp>`

Initial value:
= [](auto&& x1, ..., auto&& xn) {
return tag-dispatched;
}

Zip one sequence or more.

Given `n` sequences `s1, ..., sn`, `zip_shortest` produces a sequence whose `i`-th element is a tuple of `(s1[i], ..., sn[i])`, where `sk[i]` denotes the `i`-th element of the `k`-th sequence. In other words, `zip_shortest` produces a sequence of the form

[
make_tuple(s1[0], ..., sn[0]),
make_tuple(s1[1], ..., sn[1]),
...
make_tuple(s1[M], ..., sn[M])
]

where `M` is the length of the shortest sequence. Hence, the returned sequence stops when the shortest input sequence is exhausted. If you know that all the sequences you are about to zip have the same length, you should use `zip` instead, since it can be more optimized. Also note that it is an error to provide no sequence at all, i.e. `zip_shortest` expects at least one sequence.

## 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/equal.hpp>
#include <boost/hana/tuple.hpp>
#include <boost/hana/zip_shortest.hpp>
namespace hana = boost::hana;
static_assert(
hana::zip_shortest(hana::make_tuple(1, 'a'), hana::make_tuple(2, 3.3), hana::make_tuple(3, 'c', "ignored"))
==
hana::make_tuple(hana::make_tuple(1, 2, 3), hana::make_tuple('a', 3.3, 'c'))
, "");
int main() { }
boost::hana::zip_shortest
constexpr auto zip_shortest
Zip one sequence or more.
Definition: zip_shortest.hpp:45
zip_shortest.hpp
Defines boost::hana::zip_shortest.

## ◆ zip_shortest_with

constexpr auto boost::hana::zip_shortest_with
| constexpr

`#include <boost/hana/fwd/zip_shortest_with.hpp>`

Initial value:
= [](auto&& f, auto&& x1, ..., auto&& xn) {
return tag-dispatched;
}

Zip one sequence or more with a given function.

Given a `n`-ary function `f` and `n` sequences `s1, ..., sn`, `zip_shortest_with` produces a sequence whose `i`-th element is `f(s1[i], ..., sn[i])`, where `sk[i]` denotes the `i`-th element of the `k`-th sequence. In other words, `zip_shortest_with` produces a sequence of the form

[
f(s1[0], ..., sn[0]),
f(s1[1], ..., sn[1]),
...
f(s1[M], ..., sn[M])
]

where `M` is the length of the shortest sequence. Hence, the returned sequence stops when the shortest input sequence is exhausted. If you know that all the sequences you are about to zip have the same length, you should use `zip_with` instead, since it can be more optimized. Also note that it is an error to provide no sequence at all, i.e. `zip_shortest_with` expects at least one sequence.

## 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/equal.hpp>
#include <boost/hana/mult.hpp>
#include <boost/hana/tuple.hpp>
#include <boost/hana/zip_shortest_with.hpp>
namespace hana = boost::hana;
static_assert(
hana::zip_shortest_with(hana::mult, hana::make_tuple(1, 2, 3, 4), hana::make_tuple(5, 6, 7, 8, "ignored"))
==
hana::make_tuple(5, 12, 21, 32)
, "");
int main() { }
boost::hana::mult
constexpr auto mult
Associative operation of a Ring.
Definition: mult.hpp:47
boost::hana::zip_shortest_with
constexpr auto zip_shortest_with
Zip one sequence or more with a given function.
Definition: zip_shortest_with.hpp:46
mult.hpp
Defines boost::hana::mult.
zip_shortest_with.hpp
Defines boost::hana::zip_shortest_with.

## ◆ zip_with

constexpr auto boost::hana::zip_with
| constexpr

`#include <boost/hana/fwd/zip_with.hpp>`

Initial value:
= [](auto&& f, auto&& x1, ..., auto&& xn) {
return tag-dispatched;
}

Zip one sequence or more with a given function.

Given a `n`-ary function `f` and `n` sequences `s1, ..., sn`, `zip_with` produces a sequence whose `i`-th element is `f(s1[i], ..., sn[i])`, where `sk[i]` denotes the `i`-th element of the `k`-th sequence. In other words, `zip_with` produces a sequence of the form

[
f(s1[0], ..., sn[0]),
f(s1[1], ..., sn[1]),
...
f(s1[M], ..., sn[M])
]

where `M` is the length of the sequences, which are all assumed to have the same length. Assuming the sequences to all have the same size allows the library to perform some optimizations. To zip sequences that may have different lengths, `zip_shortest_with` should be used instead. Also note that it is an error to provide no sequence at all, i.e. `zip_with` expects at least one sequence.

## 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/equal.hpp>
#include <boost/hana/ext/std/tuple.hpp>
#include <boost/hana/mult.hpp>
#include <boost/hana/transform.hpp>
#include <boost/hana/tuple.hpp>
#include <boost/hana/type.hpp>
#include <boost/hana/unpack.hpp>
#include <boost/hana/zip_with.hpp>
#include <tuple>
#include <type_traits>
#include <utility>
namespace hana = boost::hana;
// Basic usage:
static_assert(
hana::zip_with(hana::mult, hana::make_tuple(1, 2, 3, 4), hana::make_tuple(5, 6, 7, 8))
==
hana::make_tuple(5, 12, 21, 32)
, "");
// Example of computing a tuple of all the common types of several tuples:
template<typename... Ts>
using common_tuple_t = typename decltype(
hana::unpack(
hana::zip_with(
hana::metafunction<std::common_type>,
hana::transform(std::declval<Ts>(), hana::decltype_)...
),
hana::template_<std::tuple>
)
)::type;
static_assert(std::is_same<
common_tuple_t<
std::tuple<bool, int, unsigned>,
std::tuple<char, long, long>,
std::tuple<int, long long, double>
>,
std::tuple<int, long long, double>
>::value, "");
int main() { }
boost::hana::value
constexpr auto value
Return the compile-time value associated to a constant.
Definition: value.hpp:54
boost::hana::unpack
constexpr auto unpack
Invoke a function with the elements of a Foldable as arguments.
Definition: unpack.hpp:79
boost::hana::zip_with
constexpr auto zip_with
Zip one sequence or more with a given function.
Definition: zip_with.hpp:46
std::tuple
Adapter for std::tuples.
Definition: tuple.hpp:49
unpack.hpp
Defines boost::hana::unpack.
zip_with.hpp
Defines boost::hana::zip_with.