Dune Core Modules (2.4.2)

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
11
12namespace Dune
13{
14
15 namespace Std
16 {
17
18 // integer_sequence
19 // ----------------
20
27 template< class T, T... Ints >
29 {
30 static_assert( std::is_integral< T >::value, "Template parameter T is required to be an integral type" );
31
32 public:
33#ifndef DOXYGEN
34
35 template< class U >
36 struct rebind
37 {
38 typedef integer_sequence< U, static_cast< U >( Ints )... > type;
39 };
40
41#endif // #ifndef DOXYGEN
42
44 typedef T value_type;
45
47 static DUNE_CONSTEXPR std::size_t size () { return sizeof...( Ints ); }
48 };
49
50
51
52 // index_sequence
53 // --------------
54
60 template< std::size_t... Ints >
62 : public integer_sequence< std::size_t, Ints... >
63 {};
64
65
66
67#ifndef DOXYGEN
68
69 // make_index_sequence_impl
70 // ------------------------
71
72 template< std::size_t N >
73 class make_index_sequence_impl;
74
75 template<>
76 class make_index_sequence_impl< 0u >
77 {
78 public:
79 typedef index_sequence<> type;
80 };
81
82 template<>
83 class make_index_sequence_impl< 1u >
84 {
85 public:
86 typedef index_sequence< 0 > type;
87 };
88
89 template< std::size_t N >
90 class make_index_sequence_impl
91 {
92 static_assert( N >= 0, "Cannot produce an index sequence of negative length" );
93
94 template< std::size_t... I1, std::size_t... I2 >
95 static index_sequence< I1..., (sizeof...( I1 )+I2)... >
96 add ( index_sequence< I1... >, index_sequence< I2... > )
97 {
98 return index_sequence< I1..., (sizeof...( I1 )+I2)... >();
99 }
100
101 public:
102 typedef decltype( add( typename make_index_sequence_impl< N/2 >::type(), typename make_index_sequence_impl< N-N/2 >::type() ) ) type;
103 };
104
105#endif // #ifndef DOXYGEN
106
107
108
109 // make_index_sequence
110 // -------------------
111
119 template< std::size_t N >
120 static DUNE_CONSTEXPR inline typename make_index_sequence_impl< N >::type make_index_sequence ()
121 {
122 return typename make_index_sequence_impl< N >::type();
123 }
124
125
126
127 // make_integer_sequence
128 // ---------------------
129
138 template< class T, T N >
139 static DUNE_CONSTEXPR inline typename make_index_sequence_impl< N >::type::template rebind< T >::type
140 make_integer_sequence ()
141 {
142 return typename make_index_sequence_impl< N >::type::template rebind< T >::type();
143 }
144
145
146
147 // index_sequence_for
148 // ------------------
149
157 template< class... T >
158 static DUNE_CONSTEXPR inline typename make_index_sequence_impl< sizeof...( T ) >::type
159 index_sequence_for ()
160 {
161 return typename make_index_sequence_impl< sizeof...( T ) >::type();
162 }
163
164#if HAVE_STD_DECLVAL
165
166 using std::declval;
167
168#else
169
170 template <class T>
171 typename std::add_rvalue_reference<T>::type declval() DUNE_NOEXCEPT;
172
173#endif
174
175
176 } // namespace Std
177
178} // namespace Dune
179
180#endif // #ifndef DUNE_COMMON_STD_UTILITY_HH
a function similar to std::index_sequence to be introduced in C++14
Definition: utility.hh:63
an implementation of std::integer_sequence to be introduced in C++14
Definition: utility.hh:29
T value_type
value type
Definition: utility.hh:44
static DUNE_CONSTEXPR std::size_t size()
return number of elements in sequence
Definition: utility.hh:47
Definition of the DUNE_CONSTEXPR macro.
#define DUNE_CONSTEXPR
Set method or expression constexpr if supported by the compiler.
Definition: constexpr.hh:21
Dune namespace.
Definition: alignment.hh:10
Definition of the DUNE_NOEXCEPT macro.
#define DUNE_NOEXCEPT
Set method to noexcept if supported by the compiler.
Definition: noexcept.hh:22
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)