Init statements enable fully encapsulated if, switch (C++17) and range-for loop (C++20) statements by adding an additional init section that can be used to create variables with a lifetime matching the statement block.
Compiler Explorer link: https://compiler-explorer.com/z/ndn1n9h4e
@simontoth I think it's prettier if you just use {} to create a block, if the lifetime of an object is specifically important to you. Two statements in a switch/if just look rough! :) And if you don't want the variable to exist past the switch entry, then maybe use a different approach. Why return a whole value if you only discard it right after?