Variadic Switch

(pydong.org)

44 points | by Tsche 2 days ago

2 comments

  • david2ndaccount 1 day ago
    In D, you can just do a static foreach over a sequence to generate case labels:

    https://d.godbolt.org/z/PxWEW14K1

    • pjmlp 16 hours ago
      Unfortunely like many things D, eventually C++ gets the feature, even if not as nice to use.

      That is template for as part of the C++26 reflection work.

      https://isocpp.org/files/papers/P2996R4.html

      You will also find some well known names here,

      https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2025/p34...

      • Doxin 15 hours ago
        I feel like the main problem people have with C++ is not the lack of features, but the absolute glut of slightly bad features. That's why I prefer D over C++ in any case: it's a much smaller language. You can learn enough to be dangerous in an afternoon, and enough to be proficient in a week or two.
        • pjmlp 15 hours ago
          I on the contrary, I rather reach out to C++, even though I like D, it isn't the features, it is the ecosystem.

          Otherwise I rather stay in JVM/CLR/V8 land, when I don't need to.

          I have been around D since Andrei Alexandrescu's book was published, even he is now back in C++ at NVidia, as his main work after he kind of stepped away from his role in D development.

          And he is one of the figures on C++26 reflection papers.

  • PeterWhittaker 1 day ago
    I find the article very interesting and informative but, honestly, of all of the approaches, I find the basic switch to be the most readable and likely the most maintainable, at least for this case.
    • pjmlp 16 hours ago
      The two major problems in C++, we as a comunity suffer from, are those that still insist using it as plain old C with some improvments, and those that do some kind of post-avant guard code, only understood by anyone coding every day in C++, that have as pastime reading ISO standard and compiler reference manuals, while attending C++ conferences.

      One keeps the whole security discussion going on, while the other keeps an image that C++ is a language not worth learning.

    • glouwbug 8 hours ago
      Funny enough, the runtime switch, for all practical reasons, is probably just as fast