Namespaces
Variants
Views
Actions

C++ attributes: likely, unlikely

From cppreference.com
< cpp‎ | language‎ | attributes
Revision as of 23:13, 23 June 2018 by 183.208.8.232 (Talk)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


Allow the compiler to optimize for the case where paths of execution including that statement are more or less likely than any alternative path of execution that does not include such a statement

Syntax

[[likely]] statement (1)
[[unlikely]] statement (2)

Explanation

1) Applies to a statement to allow the compiler to optimize for the case where paths of execution including that statement are more likely than any alternative path of execution that does not include such a statement.
2) Applies to a statement to allow the compiler to optimize for the case where paths of execution including that statement are less likely than any alternative path of execution that does not include such a statement.

Example