C++ pattern matching is coming
Walter Bright
newshound2 at digitalmars.com
Sun Oct 23 19:28:37 UTC 2022
On 10/23/2022 3:43 AM, IGotD- wrote:
> Can they reuse switch? In Swift they have pattern matching but they use the
> switch keyword for their jack-of-all-trades switch statement. Problem with C++
> (and D) is that the switch statement is fallthrough by default. In order to fix
> this historical mistake they need a complete new keyword.
>
> This is something to fix in D3, remove fallthrogh by default.
Fallthrough by default was removed from D many years ago.
The awkward problem with re-using switch is that each case does not introduce a
new scope. This raises all kinds of problems when using pattern matching to
declare new variables.
A second awkward problem is that case statements can be placed inside nested scopes.
It's better to just leave switch as it is, and develop a new construct for
pattern matching that hews to modern sensibilities.
More information about the Digitalmars-d
mailing list