C++ Logo

std-proposals

Advanced search

Re: [std-proposals] A draft for modern switch

From: Sebastian Wittmeier <wittmeier_at_[hidden]>
Date: Sat, 24 May 2025 09:03:17 +0200
Okay, let's assume the compiler can do performance optimizations with string comparisons, either by   A) knowing that the input value is limited (e.g. contracts and pre-conditions) or B) by testing the full string _after_ jumping or deciding, where to jump, and doing a full comparison before the jump.   And now optimizations like only reading partial strings to determine the target.     The question is, do we need switch in the programming language to express this functionality? The compiler can do those optimizations from an if else tree as well. Or from pattern matching.   Is it easier for the compiler to detect the possibility of muptu-way branching from switch?   Is the syntax nicer for the user? The features like fall-through and wild jumps were left out on purpose with pattern-matching.     I would guess, the compilers can or could do the same performance improvements with if/else and pattern matching. If you need fall-through and other shenanigans use if/else), loops or even goto. Otherwise use pattern matching. If your compiler does not optimize as well as it could, manually optimize the conditions in your code and send a feature request or patch to the implementers.       -----Ursprüngliche Nachricht----- Von:Zhihao Yuan via Std-Proposals <std-proposals_at_[hidden]> Gesendet:Sa 24.05.2025 08:14 Betreff:Re: [std-proposals] A draft for modern switch Anlage:signature.asc An:std-proposals_at_[hidden]; CC:Zhihao Yuan <zy_at_[hidden]>; On Friday, May 23rd, 2025 at 7:27 PM, Jason McKesson via Std-Proposals <std-proposals_at_[hidden]> wrote: > > I guess that depends on what you mean by "jump table". I've always > understood that term to refer to an array of pointers to various > locations in code, with the indices in that table representing > something in particular. > > [...] > > The code being jumped into is not the table. It's just code. > I apologize. "Multiway branch" seems to be the right term https://www.researchgate.net/publication/245584786_A_Superoptimizer_Analysis_of_Multiway_Branch_Code_Generation -- Zhihao Yuan, ID lichray The best way to predict the future is to invent it. _______________________________________________ -- Std-Proposals mailing list Std-Proposals_at_[hidden] https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2025-05-24 07:10:55