C++ Logo


Advanced search

Re: [std-proposals] Switch on strings

From: Bo Persson <bo_at_[hidden]>
Date: Sun, 26 Feb 2023 13:16:22 +0100
On 2023-02-26 at 11:56, Francesco Pretto via Std-Proposals wrote:
> Hello,
> is there any proposal in the works for switch on strings? With all the
> constexpr constructors and equality operators in place, what's missing
> to finally have such construct in modern C++?

With integers, if they have consecutive values, you can optimize the
switch by using an array of jump-targets and index it with the case-values.

Strings cannot be used as an array index, so it would still be the same
as a set of if-else statements. So no performance gain. Then why bother?

Received on 2023-02-26 12:16:30