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

The C++23 introduced the [[assume(expr)]]; attribute that can be used to introduce undefined behaviour into a program.

Instead of relying on other language-level UB, the attribute can be specified with an expression the compiler can assume is true, allowing the compiler to optimize the code aggressively.

If any assumption is violated, the program is in an invalid state.

Compiler Explorer link: compiler-explorer.com/z/bvrd3h

@simontoth isn't it equivalent to C++20 [[likely]] or [[unlikely]] ?

@lexplt No. [[likely]] and [[unlikely]] only designate that a particular branch is likely or unlikely to be taken, that doesn't prevent that/or another branch from being taken.

@simontoth oh my bad! I thought that likely and unlikely could apply to more than branches
Now that I think about it, even if they did, they aren't as aggressive as [[assume]] since it's an hint for the compiler to reorganize code and optimize the hot path