• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1////
2Copyright 2017 Peter Dimov
3
4Distributed under the Boost Software License, Version 1.0.
5
6See accompanying file LICENSE_1_0.txt or copy at
7http://www.boost.org/LICENSE_1_0.txt
8////
9
10[#tuple]
11# Tuple Operations, <boost/mp11/tuple.hpp>
12:toc:
13:toc-title:
14:idprefix:
15
16## tuple_apply(f, tp)
17
18    template<class F, class Tp> constexpr /*...*/ tuple_apply(F&& f, Tp&& tp);
19
20`tuple_apply(f, tp)` returns `std::forward<F>(f)(std::get<J>(std::forward<Tp>(tp))...)` for `J` in 0..`N-1`,
21where `N` is `std::tuple_size<typename std::remove_reference<Tp>::type>::value`. Same as `std::apply` in C++17.
22
23## construct_from_tuple<T>(tp)
24
25    template<class T, class Tp> T construct_from_tuple(Tp&& tp);
26
27`construct_from_tuple<T>(tp)` returns `T(std::get<J>(std::forward<Tp>(tp))...)` for `J` in 0..`N-1`,
28where `N` is `std::tuple_size<typename std::remove_reference<Tp>::type>::value`. Same as `std::make_from_tuple` in {cpp}17.
29The name of the function doesn't match the {cpp}17 one to avoid ambiguities when both are visible or in unqualified calls.
30
31## tuple_for_each(tp, f)
32
33    template<class Tp, class F> constexpr F tuple_for_each(Tp&& tp, F&& f);
34
35`tuple_for_each(tp, f)` applies the function object `f` to each element of `tp` in order by evaluating the
36expression `f(std::get<J>(std::forward<Tp>(tp)))` for `J` in 0..`N-1`, where `N` is `std::tuple_size<typename std::remove_reference<Tp>::type>::value`.
37
38Returns `std::forward<F>(f)`.
39
40## tuple_transform(f, tp...)
41
42    template<class F, class... Tp> constexpr /*...*/ tuple_transform(F const& f, Tp&&... tp);
43
44`tuple_transform(f, tp...)` accepts a function object `f` followed by one or more tuples of equal length
45(`std::tuple`, `std::pair` and `std::array` are considered tuples.)
46
47The callable `f` must accept as many arguments as there are tuples. The function object is called with the
48first elements of each tuple, with the second elements of each tuple, and so on, as if by evaluating
49the expression `f(std::get<J>(std::forward<Tp>(tp))...)` for `J` in 0..`N-1`, where `N` is the length of
50the tuples.
51
52The order in which the elements of the tuples are processed is unspecified.
53
54The results are returned as a `std::tuple<T...>` with `T...` deduced from the return values of `f` (lvalue
55references are preserved, rvalue references are returned by value.)
56