Fill std::set at compile time?
Asked Answered
B

1

5

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.

Bayly answered 10/1, 2017 at 11:45 Comment(1)
Not with guarantees. Otherwise, in some cases, a compiler could optimize it to compile time, but I doubt any does.Sacrosanct
S
11

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.

Scorpius answered 10/1, 2017 at 14:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.