Guidelines for using [[likely]] / [[unlikely]] attributes in c++20

489 views Asked by At

What is the general guideline for using the [[likely]] and [[unlikely]] attributes in c++20, for the cases where we have only two possible branches of code execution? Is it advised to put [[likely]] or [[unlikely]] on just one branch of execution path or we should be putting one of it on one code branch and other one on the remaining branch. For example, should we be doing

if (condition) [[likely]]
{
}
else [[unlikely]]
{
}

or

if (condition) [[likely]]
{
}
else
{
}

when we know that the branch in if condition is more likely to get executed.

0

There are 0 answers