Dune Core Modules (2.5.0)

utility.hh
1#ifndef DUNE_COMMON_STD_UTILITY_HH
2#define DUNE_COMMON_STD_UTILITY_HH
3
4#include <cstddef>
5
6#include <type_traits>
7#include <utility>
8
10
11namespace Dune
12{
13
14 namespace Std
15 {
16
17
18#if __cpp_lib_integer_sequence >= 201304
19
20 using std::integer_sequence;
21 using std::index_sequence;
22 using std::make_integer_sequence;
23 using std::make_index_sequence;
24
25#else // __cpp_lib_integer_sequence >= 201304
26
27 // integer_sequence
28 // ----------------
29
35 template< class T, T... Ints >
37 {
38 static_assert( std::is_integral< T >::value, "Template parameter T is required to be an integral type" );
39
40 public:
41
43 typedef T value_type;
44
46 static constexpr std::size_t size () { return sizeof...( Ints ); }
47 };
48
49
54 template< std::size_t... Ints >
55 using index_sequence = integer_sequence< std::size_t, Ints... >;
56
57#ifndef DOXYGEN
58
59 namespace impl {
60
61 template<typename T, T i, T n, T... indices>
62 struct _make_integer_sequence
63 : public _make_integer_sequence<T,i+1,n,indices...,i>
64 {};
65
66 template<typename T, T n, T... indices>
67 struct _make_integer_sequence<T,n,n,indices...>
68 {
69 using type = integer_sequence<T,indices...>;
70 };
71
72 }
73
74#endif // DOXYGEN
75
76 template<typename T, T n>
77 using make_integer_sequence = typename impl::_make_integer_sequence<T,0,n>::type;
78
79 template<std::size_t n>
80 using make_index_sequence = make_integer_sequence<std::size_t,n>;
81
82#endif // __cpp_lib_integer_sequence >= 201304
83
98 template<typename... T>
99 using index_sequence_for = make_index_sequence<typename Dune::SizeOf<T...>{}>;
100
101
102
103 } // namespace Std
104
105} // namespace Dune
106
107#endif // #ifndef DUNE_COMMON_STD_UTILITY_HH
an implementation of std::integer_sequence as introduced in C++14
Definition: utility.hh:37
static constexpr std::size_t size()
return number of elements in sequence
Definition: utility.hh:46
T value_type
value type
Definition: utility.hh:43
Dune namespace.
Definition: alignment.hh:11
Compute size of variadic type list.
Definition: typetraits.hh:566
Traits for type conversions and type information.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 23, 23:29, 2024)