C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Proposal interest: constexpr std::static_unordered_set<T, N>

From: Marcin Jaczewski <marcinjaczewski86_at_[hidden]>
Date: Fri, 17 Apr 2026 20:11:07 +0200
pt., 17 kwi 2026 o 19:12 Arthur O'Dwyer via Std-Proposals
<std-proposals_at_[hidden]> napisał(a):
>
> On Fri, Apr 17, 2026 at 12:20 PM Robert Baumgartner via Std-Proposals <std-proposals_at_[hidden]> wrote:
>>
>>
>> > Can't you do this in C++26?
>> > constexpr std::unordered_set<E> set({x, y, z});
>>
>> As of the current status of C++26 both std::unordered_set and std::unordered_map do not support constexpr.
>
>
> Yes they do. This was done in https://github.com/cplusplus/draft/pull/7709/changes to satisfy P3372.
>
>
> I just played around a little bit with the idea of generating a "flat map view" at compile time — i.e., a const view over two static-storage arrays, populated at compile-time using C++26 `define_static_array`.
> It kinda works, but not as well as I expected it would.
> https://godbolt.org/z/5ev4sWqh1
> There's no problem with my variable `frozen`, but
> (A) There is a problem with `frozen2`. Apparently `define_static_array` cannot be used to create constexpr arrays of pointers to string literals; presumably having something to do with the fact that those pointers would point to "potentially non-unique objects"?

```
constexpr auto frozen2 = freeze(std::flat_map<int,const char*>{
    {1,std::define_static_string("")},
    {2,std::define_static_string("abc")},
    {3,std::define_static_string("def")},
    {4,std::define_static_string("ghi")},
    {5,std::define_static_string("jkl")},
    {6,std::define_static_string("mno")},
    {7,std::define_static_string("pqrs")},
    {8,std::define_static_string("tuv")},
    {9,std::define_static_string("wxyz")},
    {0,std::define_static_string("oper")},
});
```

This looks to work. Could we need to simply call it for every "remote"
memory explicitly.



> (B) There is a problem with `frozen3`. Apparently `define_static_array` cannot be used to create constexpr arrays of non-structural types, even when those types are perfectly constexpr-friendly otherwise.
>
> I'd like to understand better if these are bugs in the reference implementation; or, intentional but my FlatMapView could work around them somehow; or, intentional but someone already has a plan to improve `define_static_array` for C++29-ish; or, immutable/necessary (mis)features of `define_static_array`.
>
> –Arthur
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2026-04-17 18:11:22