Skip to content

Commit c86e676

Browse files
committed
[Ref] mpt/base/array.hpp: Add constexpr-friendly mpt::generate_array().
git-svn-id: https://source.openmpt.org/svn/openmpt/trunk/OpenMPT@22588 56274372-70c3-4bfc-bfc3-4c3a0b034d27
1 parent e2b9bbe commit c86e676

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/mpt/base/array.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,16 @@ constexpr std::array<T, N> init_array(const Tx & x) {
7474
}
7575

7676

77+
template <typename T, std::size_t N, typename Fgen>
78+
constexpr std::array<T, N> generate_array(Fgen generator) {
79+
std::array<T, N> result{};
80+
for (std::size_t i = 0; i < N; ++i) {
81+
result[i] = generator(i);
82+
}
83+
return result;
84+
}
85+
86+
7787
} // namespace MPT_INLINE_NS
7888
} // namespace mpt
7989

0 commit comments

Comments
 (0)