Is it a good practice to use c++ likelyhood attributes in contract assertions?

1 day ago 1
ARTICLE AD BOX

Is it a good practice to use c++20's [[likely]] and [[unlikely]] with contract if statements? Are they a good choice optimization-wise?

int foo(int n) { if (n < 0) [[unlikely]] { // handle n < 0 } // impl... }

vs a regular if statement

int foo(int n) { if (n < 0) { // handle n < 0 } // impl... }
Read Entire Article