1 // Copyright 2020 The Pigweed Authors
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of
7 // https://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations under
18 #include "pw_polyfill/standard_library/namespace.h"
20 #ifndef __cpp_lib_integer_sequence
21 #define __cpp_lib_integer_sequence 201304L
23 _PW_POLYFILL_BEGIN_NAMESPACE_STD
25 template <typename T, T... sequence>
26 struct integer_sequence {
27 static constexpr size_t size() noexcept { return sizeof...(sequence); }
32 // In the absence of a compiler builtin for this, have MakeSequence expand
33 // recursively to enumerate all indices up to count.
34 template <size_t count, typename T, T... sequence>
35 struct MakeSequence : MakeSequence<count - 1, T, count - 1, sequence...> {};
37 template <typename T, T... sequence>
38 struct MakeSequence<0, T, sequence...> : std::integer_sequence<T, sequence...> {
43 template <size_t... sequence>
44 using index_sequence = integer_sequence<size_t, sequence...>;
46 template <typename T, T count>
47 using make_integer_sequence = impl::MakeSequence<count, T>;
49 template <size_t count>
50 using make_index_sequence = make_integer_sequence<size_t, count>;
52 template <typename... T>
53 using index_sequence_for = make_index_sequence<sizeof...(T)>;
55 _PW_POLYFILL_END_NAMESPACE_STD
57 #endif // __cpp_lib_integer_sequence