1 // Copyright 2020 The Pigweed Authors 2 // 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 5 // the License at 6 // 7 // https://www.apache.org/licenses/LICENSE-2.0 8 // 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 13 // the License. 14 #pragma once 15 16 #include <utility> 17 18 #include "pw_polyfill/standard_library/namespace.h" 19 20 #ifndef __cpp_lib_integer_sequence 21 #define __cpp_lib_integer_sequence 201304L 22 23 _PW_POLYFILL_BEGIN_NAMESPACE_STD 24 25 template <typename T, T... sequence> 26 struct integer_sequence { sizeinteger_sequence27 static constexpr size_t size() noexcept { return sizeof...(sequence); } 28 }; 29 30 namespace impl { 31 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...> {}; 36 37 template <typename T, T... sequence> 38 struct MakeSequence<0, T, sequence...> : std::integer_sequence<T, sequence...> { 39 }; 40 41 } // namespace impl 42 43 template <size_t... sequence> 44 using index_sequence = integer_sequence<size_t, sequence...>; 45 46 template <typename T, T count> 47 using make_integer_sequence = impl::MakeSequence<count, T>; 48 49 template <size_t count> 50 using make_index_sequence = make_integer_sequence<size_t, count>; 51 52 template <typename... T> 53 using index_sequence_for = make_index_sequence<sizeof...(T)>; 54 55 _PW_POLYFILL_END_NAMESPACE_STD 56 57 #endif // __cpp_lib_integer_sequence 58