Add Map, another name for Transform
This commit is contained in:
parent
f43eae6080
commit
9cb0811ecc
1 changed files with 8 additions and 2 deletions
|
@ -162,13 +162,19 @@ template <typename T>
|
||||||
concept TupleLike = kForceEnableTuple<std::remove_cvref_t<T>> || (requires{Get<0>(MakeTuple<T>(42));} && impl::IsSafeTuple<std::remove_cvref_t<T>>::value);
|
concept TupleLike = kForceEnableTuple<std::remove_cvref_t<T>> || (requires{Get<0>(MakeTuple<T>(42));} && impl::IsSafeTuple<std::remove_cvref_t<T>>::value);
|
||||||
|
|
||||||
|
|
||||||
template <TupleLike Tuple, typename R = Tuple>
|
template <TupleLike Tuple, typename R = Tuple, typename F>
|
||||||
inline constexpr auto Transform(Tuple&& container, auto&& f, TypeList<R> = {}) {
|
inline constexpr auto Transform(Tuple&& container, F&& f, TypeList<R> = {}) {
|
||||||
return [&]<auto... Is>(std::index_sequence<Is...>){
|
return [&]<auto... Is>(std::index_sequence<Is...>){
|
||||||
return MakeTuple<R>(f(Get<Is>(std::forward<Tuple>(container)))...);
|
return MakeTuple<R>(f(Get<Is>(std::forward<Tuple>(container)))...);
|
||||||
}(std::make_index_sequence<kTupleSize<Tuple>>());
|
}(std::make_index_sequence<kTupleSize<Tuple>>());
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <TupleLike Tuple, typename R, typename F>
|
||||||
|
inline constexpr auto Map(Tuple&& tuple, F&& f, TypeList<R> result = {}) {
|
||||||
|
return Transform(std::forward<Tuple>(tuple), std::forward<F>(f), result);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
template <TupleLike Tuple>
|
template <TupleLike Tuple>
|
||||||
inline constexpr auto Reverse(Tuple&& tuple) {
|
inline constexpr auto Reverse(Tuple&& tuple) {
|
||||||
return [&]<auto... Is>(std::index_sequence<Is...>) {
|
return [&]<auto... Is>(std::index_sequence<Is...>) {
|
||||||
|
|
Loading…
Reference in a new issue