Preliminary information: according to the recent ISO C++ Committee Trip Report, the [[ likely ]]
and [[ unlikely ]]
attributes for conditional branching will be added in C++20
and is available in the newest version of GNU GCC (you can play with it on the online compiler wandbox.org).
Question: Is the following construction
if (cond) [[ likely ]] { ... }
equivalent to the following one?
if (__builtin_expect(bool(cond), 1)) { ... }
Are there any performance difference or implementation nuances between different compilers that one should be aware of in order to use it effectively?