array.hpp
Created 2025-08-20T03:42:31.726Z, last edited 2025-09-07T04:55:36.116Z
6 7 8 9 10 11 | #pragma once #include <array> #include <concepts> #include <utility> |
array_of — Create an array of N values
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | template<std::size_t N, std::invocable<std::size_t> V> constexpr inline auto array_of(V &&v) { return [&]<std::size_t... Indices>( std::integer_sequence<std::size_t, Indices...>) { return std::array{v(Indices)...}; }(std::make_index_sequence<N>{}); } template<std::size_t N, std::invocable<> V> constexpr inline auto array_of(V &&v) { return array_of<N>([&](std::size_t) { return v(); }); } template<std::size_t N, std::copyable V> constexpr inline auto array_of(V const &v) { return array_of<N>([&](std::size_t) { return v; }); } |
© 2002-2026 Kirit & Tai Sælensminde. All forum posts are copyright their respective authors.
Licensed under a Creative Commons License. Non-commercial use is fine so long as you provide attribution.

