// Copyright 2019 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_INTERNAL_UTILITY_H #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_INTERNAL_UTILITY_H #include "google/cloud/version.h" #include namespace google { namespace cloud { inline namespace GOOGLE_CLOUD_CPP_NS { namespace internal { // This header re-implements some of C++14's header. // Re-implementation of C++14 `std::integer_sequence`. template struct integer_sequence { // NOLINT(readability-identifier-naming) using value_type = T; static std::size_t constexpr size() noexcept { return sizeof...(I); } }; // Re-implementation of C++14 `std::index_sequence`. template using index_sequence = integer_sequence; /** * Implementation of `make_index_sequence`. * * `MakeIndexSequenceImpl` references itself accumulating the result * indices in `I`. The recursion stops when `N` reaches 0. By that time, `I` * should contain the result. * * `MakeIndexSequenceImpl::result` will return an * `integer_sequence`. * * @tparam T the type of the index in `index_sequence` * @tparam N the counter bounding type recursion; `std::integral_constant` has * to be used because specializing a template with a value of type which is * dependent on a different template parameter is not allowed. * @tparam Enable ignored, formal parameter to allow for disabling some * specializations * @tparam `I` indices accumulated so far in the recursion. */ template struct MakeIndexSequenceImpl {}; /** * Implementation of `make_index_sequence`. * * Specialization for N > 0. */ template struct MakeIndexSequenceImpl, typename std::enable_if<(N > 0), void>::type, I...> { using result = typename MakeIndexSequenceImpl, void, N - 1, I...>::result; }; /** * Implementation of `make_index_sequence`. * * Specialization for N == 0. */ template struct MakeIndexSequenceImpl, void, I...> { using result = integer_sequence; }; template using make_integer_sequence = typename MakeIndexSequenceImpl, void>::result; template using make_index_sequence = make_integer_sequence; } // namespace internal } // namespace GOOGLE_CLOUD_CPP_NS } // namespace cloud } // namespace google #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_INTERNAL_UTILITY_H