C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Switch on strings

From: William Linkmeyer <wlink10_at_[hidden]>
Date: Sun, 26 Feb 2023 20:42:53 -0500
The real solution to this is probably better metaprogramming support. It’s probably more future proof to look at this problem as “let’s find a way for the compiler to generate a program that compares these known strings” than “let’s get a switch statement to work on known strings.”

There are other control-flow constructs that might be useful in a compile-time (maybe not even metaprogramming) context.

`if` and `for` are likely the most useful.

WL

> On Feb 26, 2023, at 9:35 AM, Andrey Semashev via Std-Proposals <std-proposals_at_[hidden]> wrote:
>
> On 2/26/23 16:39, Arthur O'Dwyer via Std-Proposals wrote:
>>
>> (2) Political objection: `switch` sucks. It's a relic of C, like `goto`.
>> Its semantics are confusing (fallthrough! Duff's Device!). It is quick
>> to teach both because it is rarely used and because it is relatively
>> simple. You seem to be proposing to make it (still rarely used but)
>> relatively more complicated, thus forcing students to spend longer
>> learning it... but why should we /want/ people to spend more time on
>> `switch`? That time could be better spent elsewhere in the language.
>
> You can't be serious about "rarely used". Sure, it's not as ubiquitous
> as "if", but definitely not a rare beast.
>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2023-02-27 01:43:06