Lely core libraries  2.3.4
utility.hpp
Go to the documentation of this file.
1 
22 #ifndef LELY_LIBC_UTILITY_HPP_
23 #define LELY_LIBC_UTILITY_HPP_
24 
25 #include <lely/features.h>
26 
27 #include <utility>
28 
29 namespace lely {
30 namespace compat {
31 
32 #if __cplusplus >= 201402L
33 
34 using ::std::index_sequence;
35 using ::std::index_sequence_for;
36 using ::std::integer_sequence;
37 using ::std::make_index_sequence;
38 using ::std::make_integer_sequence;
39 
40 #else // __cplusplus < 201402L
41 
43 template <typename T, T... Ints>
45  typedef T value_type;
46 
47  static constexpr ::std::size_t
48  size() noexcept {
49  return sizeof...(Ints);
50  }
51 };
52 
53 namespace detail {
54 
55 template <::std::size_t...>
56 struct index_tuple {};
57 
58 template <class, class>
60 
61 template <::std::size_t... I1, ::std::size_t... I2>
62 struct index_tuple_cat<index_tuple<I1...>, index_tuple<I2...>> {
63  using type = index_tuple<I1..., (I2 + sizeof...(I1))...>;
64 };
65 
66 template <::std::size_t N>
68  : index_tuple_cat<typename make_index_tuple<N / 2>::type,
69  typename make_index_tuple<N - N / 2>::type> {};
70 
71 template <>
72 struct make_index_tuple<1> {
73  typedef index_tuple<0> type;
74 };
75 
76 template <>
77 struct make_index_tuple<0> {
78  typedef index_tuple<> type;
79 };
80 
81 template <class T, T N, class = typename make_index_tuple<N>::type>
83 
84 template <typename T, T N, ::std::size_t... Ints>
85 struct make_integer_sequence<T, N, index_tuple<Ints...>> {
86  static_assert(N >= 0, "Cannot make integer sequence of negative length");
87 
88  typedef integer_sequence<T, static_cast<T>(Ints)...> type;
89 };
90 
91 } // namespace detail
92 
97 template <::std::size_t... Ints>
98 using index_sequence = integer_sequence<::std::size_t, Ints...>;
99 
104 template <typename T, T N>
105 using make_integer_sequence =
107 
112 template <::std::size_t N>
114 
119 template <typename... T>
121 
122 #endif // __cplusplus < 201402L
123 
124 } // namespace compat
125 } // namespace lely
126 
127 #endif // !LELY_LIBC_UTILITY_HPP_
lely::compat::integer_sequence
A compile-time sequence of integers.
Definition: utility.hpp:44
features.h
lely::compat::detail::index_tuple_cat
Definition: utility.hpp:59
lely::compat::index_sequence_for
make_index_sequence< sizeof...(T)> index_sequence_for
A helper alias template to convert any type parameter pack into an index sequence of the same length.
Definition: utility.hpp:120
lely::compat::detail::make_integer_sequence
Definition: utility.hpp:82
lely::compat::detail::index_tuple
Definition: utility.hpp:56
lely::compat::detail::make_index_tuple
Definition: utility.hpp:67
lely::compat::make_integer_sequence
typename detail::make_integer_sequence< T, N >::type make_integer_sequence
A helper alias template to simplify the creation of lely::compat::integer_sequence types with 0,...
Definition: utility.hpp:106
lely::compat::make_index_sequence
make_integer_sequence<::std::size_t, N > make_index_sequence
A helper alias template for make_integer_sequence for the common case where T is std::size_t.
Definition: utility.hpp:113