Date: Wed, 15 Apr 2026 20:16:56 +0200
śr., 15 kwi 2026 o 19:39 Jonathan Wakely via Std-Proposals
<std-proposals_at_[hidden]> napisał(a):
>
>
>
> 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});
>
But will it be available at runtime? As it have memory buffer that
can't escape `constexpr`.
This could only work if we could "leak" memory from compile time to run time,
like it would be this memory block converted to some region data
section of exe, like:
```
constexpr char* foo = std::leak_from_constexpr(new char[100]{});
//converted to
static char foo_dummy[100]{};
char* foo = &foo_dummy;
```
> 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 mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
<std-proposals_at_[hidden]> napisał(a):
>
>
>
> 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});
>
But will it be available at runtime? As it have memory buffer that
can't escape `constexpr`.
This could only work if we could "leak" memory from compile time to run time,
like it would be this memory block converted to some region data
section of exe, like:
```
constexpr char* foo = std::leak_from_constexpr(new char[100]{});
//converted to
static char foo_dummy[100]{};
char* foo = &foo_dummy;
```
> 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 mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
Received on 2026-04-15 18:17:11
