hachyderm.io is one of the many independent Mastodon servers you can use to participate in the fediverse.
Hachyderm is a safe space, LGBTQIA+ and BLM, primarily comprised of tech industry professionals world wide. Note that many non-user account types have restrictions - please see our About page.

Administered by:

Server stats:

9.5K
active users

Šimon Tóth

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: compiler-explorer.com/z/ndn1n9

@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?