@@ -14,7 +14,7 @@ decltype(auto) for_each_impl(P&& t, Function&& f, std::index_sequence<Is...>) {
1414
1515template <typename P, typename Function, std::size_t ... Is>
1616constexpr
17- decltype (auto ) for_each_impl(P& t, Function&& f, std::index_sequence<Is...>) {
17+ decltype (auto ) for_each_impl(const P& t, Function&& f, std::index_sequence<Is...>) {
1818 return std::make_tuple (f (std::get<Is>(t))...); }
1919
2020template <typename ... T, typename Function>
@@ -27,6 +27,26 @@ constexpr
2727decltype (auto ) for_each(std::tuple<T...>& t, Function&& f) {
2828 return for_each_impl (t, f, std::index_sequence_for<T...>{}); }
2929
30+ template <typename P, typename Function, std::size_t ... Is>
31+ constexpr
32+ decltype (auto ) forward_each_impl(P&& t, Function&& f, std::index_sequence<Is...>) {
33+ return std::forward_as_tuple (f (std::get<Is>(t))...); }
34+
35+ template <typename P, typename Function, std::size_t ... Is>
36+ constexpr
37+ decltype (auto ) forward_each_impl(const P& t, Function&& f, std::index_sequence<Is...>) {
38+ return std::forward_as_tuple (f (std::get<Is>(t))...); }
39+
40+ template <typename ... T, typename Function>
41+ constexpr
42+ decltype (auto ) forward_each(const std::tuple<T...>& t, Function&& f) {
43+ return forward_each_impl (t, f, std::index_sequence_for<T...>{}); }
44+
45+ template <typename ... T, typename Function>
46+ constexpr
47+ decltype (auto ) forward_each(std::tuple<T...>& t, Function&& f) {
48+ return forward_each_impl (t, f, std::index_sequence_for<T...>{}); }
49+
3050} // namespace detail
3151
3252
@@ -40,3 +60,45 @@ template <typename... Ts, typename F>
4060constexpr
4161decltype (auto ) for_each_in_tuple(std::tuple<Ts...> &t, F f) {
4262 return detail::for_each (t, f); }
63+
64+ template <typename ... Ts, typename F>
65+ constexpr
66+ decltype (auto ) forward_each_in_tuple(const std::tuple<Ts...> &t, F f) {
67+ return detail::forward_each (t, f); }
68+
69+
70+ template <typename ... Ts, typename F>
71+ constexpr
72+ decltype (auto ) forward_each_in_tuple(std::tuple<Ts...> &t, F f) {
73+ return detail::forward_each (t, f); }
74+
75+
76+ // subset functor
77+ template <typename T>
78+ struct get_template_arg {
79+ using arg = T;
80+ };
81+
82+ template <typename T, T N>
83+ struct get_template_arg <std::integral_constant<T, N>> {
84+ const static T arg = N;
85+ };
86+
87+
88+ template <template <typename ...> typename general_template, typename ... Ts>
89+ struct GeneralSubsetFunctor {
90+ std::tuple<Ts...>& tpl;
91+
92+ constexpr GeneralSubsetFunctor (std::tuple<Ts...>& tpl) noexcept
93+ : tpl(tpl) {}
94+
95+ template <typename ... Args>
96+ auto & operator ()(std::tuple<Args...>) const {
97+ return std::get<general_template<Args...>>(tpl);
98+ }
99+ };
100+
101+ template <template <typename ...> typename general_template, typename ... Ts>
102+ auto make_general_sybset_functor (std::tuple<Ts...>& tpl) {
103+ return GeneralSubsetFunctor<general_template, Ts...>(tpl);
104+ }
0 commit comments