Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fill std::set at compile time?

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.

like image 715
syntagma Avatar asked Jan 05 '23 18:01

syntagma


1 Answers

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.

like image 155
Drax Avatar answered Jan 08 '23 07:01

Drax