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. 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