summaryrefslogtreecommitdiff
path: root/src/bindings/eina_cxx/eina_integer_sequence.hh
diff options
context:
space:
mode:
authorFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2014-05-03 00:52:47 +0200
committerCedric Bail <cedric.bail@free.fr>2014-05-03 00:53:31 +0200
commit64c6c63725d96f03baf34b660ca71e13b29078c1 (patch)
tree88fc9c542301da5718d6e88edbae94593a5bce3f /src/bindings/eina_cxx/eina_integer_sequence.hh
parent98efcdcd63782b7189a8177fa7d007d81b0122ea (diff)
eina-cxx: add eina_integer_sequence, eina_optional and their tests.
Summary: eina::optional mimics C++14 std::optional behavior and semantics. Reviewers: felipealmeida, cedric, smohanty, woohyun, raster CC: cedric Differential Revision: https://phab.enlightenment.org/D815 Signed-off-by: Cedric Bail <cedric.bail@free.fr>
Diffstat (limited to 'src/bindings/eina_cxx/eina_integer_sequence.hh')
-rw-r--r--src/bindings/eina_cxx/eina_integer_sequence.hh41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/bindings/eina_cxx/eina_integer_sequence.hh b/src/bindings/eina_cxx/eina_integer_sequence.hh
new file mode 100644
index 0000000..4ec1762
--- /dev/null
+++ b/src/bindings/eina_cxx/eina_integer_sequence.hh
@@ -0,0 +1,41 @@
1#ifndef EINA_CXX_EINA_INTEGER_SEQUENCE_HH
2#define EINA_CXX_EINA_INTEGER_SEQUENCE_HH
3
4namespace efl { namespace eina {
5
6template <typename T, T... Ints>
7struct integer_sequence
8{
9 typedef T value_type;
10 static constexpr std::size_t size() { return sizeof...(Ints); }
11 typedef integer_sequence<T, Ints...> type;
12};
13
14template<class S1, class S2> struct concat;
15
16template<typename T, T... I1, T... I2>
17struct concat<integer_sequence<T, I1...>, integer_sequence<T, I2...> >
18 : integer_sequence<T, I1..., (sizeof...(I1)+I2)...> {};
19
20template<class S1, class S2>
21using Concat = typename concat<S1, S2>::type;
22
23template<typename T, T N> struct gen_seq;
24template<typename T, T N> using make_integer_sequence = typename gen_seq<T, N>::type;
25
26template<typename T, T N>
27struct gen_seq : Concat<make_integer_sequence<T, N/2>
28 , make_integer_sequence<T, N - N/2>>{};
29
30template<> struct gen_seq<std::size_t, 0> : integer_sequence<std::size_t>{};
31template<> struct gen_seq<std::size_t, 1> : integer_sequence<std::size_t, 0>{};
32
33template <std::size_t... I>
34using index_sequence = integer_sequence<std::size_t, I...>;
35
36template <std::size_t I>
37using make_index_sequence = make_integer_sequence<std::size_t, I>;
38
39} }
40
41#endif