Debian Codegraph @

llvm-project/clang-tools-extra/docs/clang-tidy/checks/performance/implicit-conversion-in-loop.rst

raw
1 .. title:: clang-tidy - performance-implicit-conversion-in-loop
2
3 performance-implicit-conversion-in-loop
4 =======================================
5
6 This warning appears in a range-based loop with a loop variable of const ref
7 type where the type of the variable does not match the one returned by the
8 iterator. This means that an implicit conversion happens, which can for example
9 result in expensive deep copies.
10
11 Example:
12
13 .. code-block:: c++
14
15 map<int, vector<string>> my_map;
16 for (const pair<int, vector<string>>& p : my_map) {}
17 // The iterator type is in fact pair<const int, vector<string>>, which means
18 // that the compiler added a conversion, resulting in a copy of the vectors.
19
20 The easiest solution is usually to use ``const auto&`` instead of writing the
21 type manually.