logoalt Hacker News

TuxSHyesterday at 10:45 PM0 repliesview on HN

The point of the article and of define_static_array is to convert stuff like constexpr std::vector to constexpr std::array.

New (and delete) can be used in constexpr functions, however memory "allocated" like that cannot leave the constexpr "sandbox" so to speak, therefore std::vector cannot be generated at compile-time, but std::array may.

If you are working with fixed-size data like LUTs, just use std::array [1]

[1] Make sure not to use std::to_array when embedding 200KB+ files, as it's a mere constexpr function and not a language construct and will exceed constexpr limits; either specify the size or use a C-style array in this case