-
Notifications
You must be signed in to change notification settings - Fork 0
/
for_each.hpp
24 lines (20 loc) · 753 Bytes
/
for_each.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#pragma once
namespace detail
{
template<typename Func, typename ...A, size_t ...I>
void for_each(const std::tuple<A...> &tuple, const Func &f, std::index_sequence<I...>);
template<typename Func, typename ...A>
void for_each(const std::tuple<A...> &, const Func &, std::index_sequence<>)
{}
template<typename Func, typename ...A, size_t I, size_t ...Rest>
void for_each(const std::tuple<A...> &tuple, const Func &f, std::index_sequence<I, Rest...>)
{
f(std::get<I>(tuple));
for_each(tuple, f, std::index_sequence<Rest...>());
}
}
template<typename Func, typename ...A>
void for_each(const std::tuple<A...> &tuple, const Func &f)
{
detail::for_each(tuple, f, std::index_sequence_for<A...>());
}