C++ Logo

std-proposals

Advanced search

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

From: Arthur O'Dwyer <arthur.j.odwyer_at_[hidden]>
Date: Fri, 17 Apr 2026 13:11:51 -0400
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
<https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p3372r2.html>.


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"?
(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

Received on 2026-04-17 17:12:07