// SPDX-License-Identifier: BSD-2-Clause // author: Max Kellermann #ifndef GENERATE_ARRAY_HXX #define GENERATE_ARRAY_HXX #include #include template constexpr auto _GenerateArray(F &&f, std::index_sequence) noexcept { using T = decltype(f(0)); /* double curly braces for compatibility with older compilers which are not 100% C++17 compliant (e.g. Apple xcode 9.4) */ return std::array{{f(I)...}}; } /** * Generate a `constexpr` std::array at compile time by calling the * given function for each index. * * @param N the number of elements in the array * @param F the function (called N times with the index as only parameter) */ template constexpr auto GenerateArray(F &&f) noexcept { return _GenerateArray(std::forward(f), std::make_index_sequence()); } #endif