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, typename... Args, std::size_t... Is>
14 constexpr auto tuple_call(Function function, const std::tuple<Args...>& tuple, meta::index_sequence<Is...>)
15 {
16  return function(std::forward<Args>(std::get<Is>(tuple))...);
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, typename... Args>
28 constexpr auto tuple_call(Function function, const std::tuple<Args...>& tuple)
29 {
30  return tuple_call(function, tuple, meta::make_index_sequence_for<Args...>{});
31 }
32 
33 template<typename Function, typename... Args>
34 constexpr auto tuple_call(const std::tuple<Args...>& tuple, Function function)
35 {
36  return tuple_call(function, tuple);
37 }
38 
39 
40 template<typename Head, typename... Tail>
41 constexpr auto tuple_tail(const std::tuple<Head, Tail...>& tuple)
42 {
43  return tuple_tail(tuple, std::index_sequence_for<Tail...>{});
44 }
45 
46 }
47 
48 #endif // SIPLASPLAS_UTILITY_TUPLE_HPP
Definition: canary_allocator.hpp:7