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: https://compiler-explorer.com/z/bvrd3hnxa
@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