Is it possible to create (possibly const
) std::set
that would be filled with elements at compile time?
I am wondering about std::set
/std::unordered_set
specifically, not a set of templated functions that would emulate behaviour of a set.
No.
std::set
and std::unordered_set
were designed as runtime containers, they use allocators and more importantly none of their constructor is marked as constexpr
(even the ones taking an std::initializer_list
), which means you can never construct one at compile time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With