siplasplas
A library for C++ reflection and introspection
tuple.hpp
1 #ifndef SIPLASPLAS_UTILITY_TUPLE_HPP
2 #define SIPLASPLAS_UTILITY_TUPLE_HPP
3 
4 #include <tuple>
5 #include "meta.hpp"
6 
7 namespace cpp
8 {
9 
10 namespace
11 {
12 
13 template<typename Function>
14 constexpr auto tuple_call(Function function, const std::tuple<>& tuple, meta::index_sequence<>)
15 {
16  return function();
17 }
18 
19 template<typename Head, typename... Tail, std::size_t... Is>
20 constexpr auto tuple_tail(const std::tuple<Head, Tail...>& tuple, std::index_sequence<Is...>)
21 {
22  return std::make_tuple(std::forward<std::tuple_element_t<Is+1, std::tuple<Head, Tail>>>(std::get<Is+1>(tuple))...);
23 }
24 
25 }
26 
27 template<typename Function>
28 constexpr auto tuple_call(Function function, const std::tuple<>& tuple)
29 {
30  return tuple_call(function, tuple, meta::make_index_sequence_for<>{});
31 }
32 
33 template<typename Function, typename Head, typename... Tail>
34 constexpr auto tuple_tail(Function function, const std::tuple<Head, Tail...>& tuple)
35 {
36  return tuple_tail(function, tuple, std::index_sequence_for<Head, Tail...>{});
37 }
38 
39 template<typename Function, typename... Args>
40 constexpr auto tuple_call(const std::tuple<Args...>& tuple, Function function)
41 {
42  return tuple_call(function, tuple);
43 }
44 
45 }
46 
47 #endif // SIPLASPLAS_UTILITY_TUPLE_HPP
Definition: canary_allocator.hpp:7