Elementa v8.0.0
Minimalistic library for any C++ application (C++11 and up)
Loading...
Searching...
No Matches
tuples.h
Go to the documentation of this file.
1
3#include "elementa/license.inc"
4#include "elementa/checks.inc"
5
6#ifndef ELEMENTA_ADTS_TUPLES_H
7#define ELEMENTA_ADTS_TUPLES_H
8
9
10#include <tuple>
11#include <utility>
12#include <type_traits>
13
14
15namespace elementa
16{
17
18namespace adts
19{
20
39/* ***************************************************************************
40
41 Template functions: for_each_tuple, for_each_rev_tuple
42
43 These are taken from
44 https://stackoverflow.com/questions/1198260/how-can-you-iterate-over-the-elements-of-an-stdtuple
45
46*******************************************************************************/
47
49
51template<std::size_t I = 0, typename FuncT, typename... Tp>
52inline
53typename std::enable_if<I == sizeof...(Tp), void>::type
54for_each_tuple(std::tuple<Tp...> &, FuncT)
55 { }
56
58
60template<std::size_t I = 0, typename FuncT, typename... Tp>
61inline
62typename std::enable_if<I < sizeof...(Tp), void>::type
63for_each_tuple(std::tuple<Tp...>& t, FuncT f)
64 { f(std::get<I>(t)); for_each_tuple<I + 1, FuncT, Tp...>(t, f); }
65
66
68
70template<std::size_t I = 0, typename FuncT, typename... Tp>
71inline
72typename std::enable_if<I == sizeof...(Tp), void>::type
73for_each_rev_tuple(std::tuple<Tp...> &, FuncT)
74 { }
75
77
79template<std::size_t I = 0, typename FuncT, typename... Tp>
80inline
81typename std::enable_if<(I < sizeof...(Tp)), void>::type
82for_each_rev_tuple(std::tuple<Tp...>& t, FuncT f)
83 { for_each_rev_tuple<I + 1, FuncT, Tp...>(t, f); f(std::get<I>(t)); }
84
85
86
87/* ***************************************************************************
88
89 Template function: is_tuple
90
91*******************************************************************************/
92
93template<typename T>
94struct is_tuple : std::false_type
95{};
96
97template<typename... Ts>
98struct is_tuple<std::tuple<Ts...>> : std::true_type
99{};
100
101 // tuples
103
104
105} // end adts namespace
106
107} // end elementa namespace
108
109
110#endif
111
std::enable_if< I==sizeof...(Tp), void >::type for_each_rev_tuple(std::tuple< Tp... > &, FuncT)
Scan in reverse order the entire tuple doing FuncT in each element.
Definition: tuples.h:73
std::enable_if< I==sizeof...(Tp), void >::type for_each_tuple(std::tuple< Tp... > &, FuncT)
Scan the entire tuple doing FuncT in each element.
Definition: tuples.h:54