| 1 |
.. title:: clang-tidy - performance-for-range-copy |
| 2 |
|
| 3 |
performance-for-range-copy |
| 4 |
========================== |
| 5 |
|
| 6 |
Finds C++11 for ranges where the loop variable is copied in each iteration but |
| 7 |
it would suffice to obtain it by const reference. |
| 8 |
|
| 9 |
The check is only applied to loop variables of types that are expensive to copy |
| 10 |
which means they are not trivially copyable or have a non-trivial copy |
| 11 |
constructor or destructor. |
| 12 |
|
| 13 |
To ensure that it is safe to replace the copy with a const reference the |
| 14 |
following heuristic is employed: |
| 15 |
|
| 16 |
1. The loop variable is const qualified. |
| 17 |
2. The loop variable is not const, but only const methods or operators are |
| 18 |
invoked on it, or it is used as const reference or value argument in |
| 19 |
constructors or function calls. |
| 20 |
|
| 21 |
Options |
| 22 |
------- |
| 23 |
|
| 24 |
.. option:: WarnOnAllAutoCopies |
| 25 |
|
| 26 |
When `true`, warns on any use of `auto` as the type of the range-based for |
| 27 |
loop variable. Default is `false`. |
| 28 |
|
| 29 |
.. option:: AllowedTypes |
| 30 |
|
| 31 |
A semicolon-separated list of names of types allowed to be copied in each |
| 32 |
iteration. Regular expressions are accepted, e.g. `[Rr]ef(erence)?$` matches |
| 33 |
every type with suffix `Ref`, `ref`, `Reference` and `reference`. The default |
| 34 |
is empty. If a name in the list contains the sequence `::` it is matched |
| 35 |
against the qualified typename (i.e. `namespace::Type`, otherwise it is |
| 36 |
matched against only the type name (i.e. `Type`). |