Or

 

(3) Depending on the possible values of the string variable use a fast hashing that has no collisions.
 

 

For strings you probably want to compare not only for equalness, but at least

 * case insensitive

 * ignoring white sace

 * starts with prefix

 * Unicode aware (different Unicode variants that lead to the same result)

 * or even full blown regular expressions.

 

Should all those be also included into switch?

 

Then the advanced switch is more like a replacement for chained if else cascades.

 

Best,

Sebastian

 

-----Ursprüngliche Nachricht-----
Von: Frederick Virchanza Gotham via Std-Proposals <std-proposals@lists.isocpp.org>
Gesendet: Mo 27.02.2023 01:04
Betreff: Re: [std-proposals] Switch on strings
An: std-proposals@lists.isocpp.org;
CC: Frederick Virchanza Gotham <cauldwell.thomas@gmail.com>;
On Sun, Feb 26, 2023 at 11:06 PM Breno Guimarães <brenorg@gmail.com> wrote:
>
> Oops: https://godbolt.org/z/r8Mvaaevf


The solution to collisions is one of the following:

(1) Use a better hash algorithm that won't collide
(2) After the hash matches, use the equality operator to be sure

But if you're going to use the equality operator at all then you could
get rid of the hashing altogether -- unless you want to keep it in
there for speed.
--
Std-Proposals mailing list
Std-Proposals@lists.isocpp.org
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals