Hasty Briefsbeta

Bilingual

Variadic Switch

a year ago
  • #Optimization
  • #Metaprogramming
  • #C++
  • The article discusses the challenge of generating a sequence of case labels followed by a statement in C++.
  • It explores various strategies to optimize switch statements into jump tables, including dispatch tables, macros, recursive switches, and fold tricks.
  • The article highlights the limitations of current C++ features and proposes potential improvements with C++26 expansion statements.
  • Different compiler behaviors (GCC, Clang, MSVC) are analyzed regarding jump table generation and optimization.
  • A generic visit implementation is discussed, including handling of void return types and move-only return types.
  • The article concludes with a look at how C++26 expansion statements could simplify the implementation of a generic visit function.