C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Switch on strings

From: Sebastian Wittmeier <wittmeier_at_[hidden]>
Date: Mon, 27 Feb 2023 08:39:32 +0100
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_at_[hidden]> Gesendet:Mo 27.02.2023 01:04 Betreff:Re: [std-proposals] Switch on strings An:std-proposals_at_[hidden]; CC:Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>; On Sun, Feb 26, 2023 at 11:06 PM Breno Guimarães <brenorg_at_[hidden]> 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_at_[hidden] https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2023-02-27 07:39:35