1
0
forked from boostorg/mp11
Files
boost_mp11/doc/mp11/tuple.adoc

51 lines
2.2 KiB
Plaintext
Raw Normal View History

2017-06-07 00:02:25 +03:00
////
Copyright 2017 Peter Dimov
Distributed under the Boost Software License, Version 1.0.
See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt
////
2017-06-08 16:35:55 +03:00
[#tuple]
# Tuple Operations, <boost/mp11/tuple.hpp>
2017-06-08 17:19:28 +03:00
:toc:
:toc-title:
2017-06-07 00:02:25 +03:00
:idprefix:
2017-06-08 17:19:28 +03:00
## tuple_apply(f, tp)
template<class F, class Tp> constexpr /*...*/ tuple_apply(F&& f, Tp&& tp);
`tuple_apply(f, tp)` returns `std::forward<F>(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`. Same as `std::apply` in C++17.
## construct_from_tuple<T>(tp)
2017-06-08 17:42:50 +03:00
template<class T, class Tp> T construct_from_tuple(Tp&& tp);
2017-06-08 17:42:50 +03:00
`construct_from_tuple<T>(tp)` returns `T(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`. Same as `std::make_from_tuple` in {cpp}17.
The name of the function doesn't match the {cpp}17 one to avoid ambiguities when both are visible or in unqualified calls.
2017-06-08 17:42:50 +03:00
2017-06-07 00:02:25 +03:00
## tuple_for_each(tp, f)
template<class Tp, class F> constexpr F tuple_for_each(Tp&& tp, F&& f);
`tuple_for_each(tp, f)` applies the function object `f` to each element of `tp` by evaluating the
expression `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`.
Returns `std::forward<F>(f)`.
2020-05-23 19:16:07 +03:00
## tuple_transform(f, tp...)
2020-05-23 19:16:07 +03:00
template<class F, class... Tp> constexpr /*...*/ tuple_transform(F const& f, Tp&&... tp);
2020-05-23 19:16:07 +03:00
`tuple_transform(f, tp...)` accepts a function object `f` followed by one or more tuples of equal length
2020-05-23 19:16:07 +03:00
(`std::pair` is also accepted). The callable `f` must accept as many arguments as there are tuples. The
function object is called with the first elements of each tuple, then with the second element of each tuple,
and so on, by evaluating the expression `f(std::get<J>(std::forward<Tp>(tp))...)` for `J` in 0..`N-1`, where
`N` is the length of the tuples. The results are returned as a `std::tuple<T...>` with `T...` deduced from the
return values of `f`. The order in which the elements of the tuples are processed is unspecified. Calling `f`
should not have side effects.