Date: Wed, 15 Apr 2026 18:39:19 +0100
On Mon, 13 Apr 2026 at 21:32, Robert Baumgartner via Std-Proposals <
std-proposals_at_[hidden]> wrote:
> I want to solve the following problem: I have an enum type, potentially a
> large one like a set of actions. A subset of that enum type satisfies
> certain conditions that I want to check at runtime. That would look like
> this
>
> if(someSet.contains(x)) {
> // do something
> }
>
> std::unordered_set<T> does this job efficiently, but has to be initialized
> during run-time.
>
Does it?
Can't you do this in C++26?
constexpr std::unordered_set<E> set({x, y, z});
And if you don't want it to be constant, use constinit so that it's
guaranteed to be initialized at compile time (avoiding the static init
order fiasco) but can still be modified later.
> This is suboptimal whenever the values are known at compile time,
> especially in ultra-low latency environments, where the run-time
> initialization adds overhead that can be avoided.
>
> The currently best compile solution that I am aware of is using a
> std::array like
>
> inline static constexpr array mySet{a, b, c, …};
>
> , which is O(log(n)) run-time at best for a lookup operation, but requires
> manual sorting for optimal performance and lacks the semantics of a set.
>
> A combined std::static_unordered_set<T, N> merges both solutions in one,
> combining run-time efficiency with compile-time initialization.
>
> I'm aware of third-party solutions like frozen, and of std::flat_map (C++23)
> and constexpr std::map (C++26), which suggest the committee has appetite
> for this direction. I'd welcome pointers to any prior proposals I may have
> missed, and feedback on whether this is worth developing into a formal
> paper.
>
> Best regards,
>
> Robert Baumgartner
>
> My website: https://robba.github.io
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>
std-proposals_at_[hidden]> wrote:
> I want to solve the following problem: I have an enum type, potentially a
> large one like a set of actions. A subset of that enum type satisfies
> certain conditions that I want to check at runtime. That would look like
> this
>
> if(someSet.contains(x)) {
> // do something
> }
>
> std::unordered_set<T> does this job efficiently, but has to be initialized
> during run-time.
>
Does it?
Can't you do this in C++26?
constexpr std::unordered_set<E> set({x, y, z});
And if you don't want it to be constant, use constinit so that it's
guaranteed to be initialized at compile time (avoiding the static init
order fiasco) but can still be modified later.
> This is suboptimal whenever the values are known at compile time,
> especially in ultra-low latency environments, where the run-time
> initialization adds overhead that can be avoided.
>
> The currently best compile solution that I am aware of is using a
> std::array like
>
> inline static constexpr array mySet{a, b, c, …};
>
> , which is O(log(n)) run-time at best for a lookup operation, but requires
> manual sorting for optimal performance and lacks the semantics of a set.
>
> A combined std::static_unordered_set<T, N> merges both solutions in one,
> combining run-time efficiency with compile-time initialization.
>
> I'm aware of third-party solutions like frozen, and of std::flat_map (C++23)
> and constexpr std::map (C++26), which suggest the committee has appetite
> for this direction. I'd welcome pointers to any prior proposals I may have
> missed, and feedback on whether this is worth developing into a formal
> paper.
>
> Best regards,
>
> Robert Baumgartner
>
> My website: https://robba.github.io
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>
Received on 2026-04-15 17:39:36
