// Copyright 2023 PingCAP, Inc. // // 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. #pragma once #include #include #include /** \brief Produces std::array of specified size, containing copies of provided object. * Copy is performed N-1 times, and the last element is being moved. * This helper allows to initialize std::array in place. */ namespace ext { namespace detail { template constexpr auto make_array_n_impl(T && value, std::index_sequence) { /// Comma is used to make N-1 copies of value return std::array, size>{(static_cast(indexes), value)..., std::forward(value)}; } } // namespace detail template constexpr auto make_array_n(std::integral_constant, T &&) { return std::array, 0>{}; } template constexpr auto make_array_n(std::integral_constant, T && value) { return detail::make_array_n_impl(std::forward(value), std::make_index_sequence{}); } template constexpr auto make_array_n(T && value) { return make_array_n(std::integral_constant{}, std::forward(value)); } } // namespace ext