C++ Logo

std-proposals

Advanced search

Re: [std-proposals] A draft for modern switch

From: Thiago Macieira <thiago_at_[hidden]>
Date: Tue, 27 May 2025 11:47:15 -0300
On Tuesday, 27 May 2025 10:32:13 Brasilia Standard Time Fabio Alemagna via
Std-Proposals wrote:
> Il giorno mar 27 mag 2025 alle ore 15:23 Thiago Macieira via Std-Proposals <
> std-proposals_at_[hidden]> ha scritto:
> > [...] An equality operator
> > alone won't suffice, because then the order of case labels would matter,
> > which
> > seems ill-advised to me.
>
> Why would the order matter? You're looking for an item in a unordered set.
> Of course, having other operators or even a hash function defined for the
> specific type would make it possible to optimize the search.

Because, with user types and weak ordering, two different entries in the case
list could be equivalent to the sought item. That is, we could have A equiv. B
and A equiv. C. Should the compiler require that therefore B equiv. C? Would
it need to enforce that by performing the O(n²) checks at compile time, or
would that just be declared UB or EB?

> As I've mentioned earlier, there's a library implementation of this. It can
> of course be made better, but the core functionality is there. Have a look:
> https://github.com/falemagn/uberswitch

The fact that library implementations exist should indicate a core language
construct isn't necessary.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Principal Engineer - Intel Platform & System Engineering

Received on 2025-05-27 14:47:22