tmp/tmp5cs81ayi/{from.md → to.md}
RENAMED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
### Likelihood attributes <a id="dcl.attr.likelihood">[[dcl.attr.likelihood]]</a>
|
| 2 |
+
|
| 3 |
+
The *attribute-token*s `likely` and `unlikely` may be applied to labels
|
| 4 |
+
or statements. The *attribute-token*s `likely` and `unlikely` shall
|
| 5 |
+
appear at most once in each *attribute-list* and no
|
| 6 |
+
*attribute-argument-clause* shall be present. The *attribute-token*
|
| 7 |
+
`likely` shall not appear in an *attribute-specifier-seq* that contains
|
| 8 |
+
the *attribute-token* `unlikely`.
|
| 9 |
+
|
| 10 |
+
*Recommended practice:* The use of the `likely` attribute is intended to
|
| 11 |
+
allow implementations to optimize for the case where paths of execution
|
| 12 |
+
including it are arbitrarily more likely than any alternative path of
|
| 13 |
+
execution that does not include such an attribute on a statement or
|
| 14 |
+
label. The use of the `unlikely` attribute is intended to allow
|
| 15 |
+
implementations to optimize for the case where paths of execution
|
| 16 |
+
including it are arbitrarily more unlikely than any alternative path of
|
| 17 |
+
execution that does not include such an attribute on a statement or
|
| 18 |
+
label. A path of execution includes a label if and only if it contains a
|
| 19 |
+
jump to that label.
|
| 20 |
+
|
| 21 |
+
[*Note 1*: Excessive usage of either of these attributes is liable to
|
| 22 |
+
result in performance degradation. — *end note*]
|
| 23 |
+
|
| 24 |
+
[*Example 1*:
|
| 25 |
+
|
| 26 |
+
``` cpp
|
| 27 |
+
void g(int);
|
| 28 |
+
int f(int n) {
|
| 29 |
+
if (n > 5) [[unlikely]] { // n > 5 is considered to be arbitrarily unlikely
|
| 30 |
+
g(0);
|
| 31 |
+
return n * 2 + 1;
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
switch (n) {
|
| 35 |
+
case 1:
|
| 36 |
+
g(1);
|
| 37 |
+
[[fallthrough]];
|
| 38 |
+
|
| 39 |
+
[[likely]] case 2: // n == 2 is considered to be arbitrarily more
|
| 40 |
+
g(2); // likely than any other value of n
|
| 41 |
+
break;
|
| 42 |
+
}
|
| 43 |
+
return 3;
|
| 44 |
+
}
|
| 45 |
+
```
|
| 46 |
+
|
| 47 |
+
— *end example*]
|
| 48 |
+
|