Writing "templated switch" was the first time I consciously used logical operator short-circuiting. The result is (almost) identical to normal switch: https://godbolt.org/z/zbKfbfPhs
Compiler Explorer - C++
std::size_t i{}; int x{}; template <std::size_t I> extern auto foo() -> int; void bar() { constexpr auto templated_switch = []<std::size_t... I>(std::size_t idx, std::index_sequence<I...>) { (void)((idx == I && (x = foo<I>(), true)) || ...); }; templated_switch(i, std::make_index_sequence<4>{}); } void baz() { switch (i) { case 0: x = foo<0>(); break; case 1: x = foo<1>(); break; case 2: x = foo<2>(); break; case 3: x = foo<3>(); break; } }
