brintos

brintos / llvm-project-archived public Read only

0
0
Text · 785 B · 14e4d31 Raw
22 lines · plain
1.. title:: clang-tidy - performance-implicit-conversion-in-loop2 3performance-implicit-conversion-in-loop4=======================================5 6This warning appears in a range-based loop with a loop variable of const ref7type where the type of the variable does not match the one returned by the8iterator. This means that an implicit conversion happens, which can for example9result in expensive deep copies.10 11Example: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 means18  // that the compiler added a conversion, resulting in a copy of the vectors.19 20The easiest solution is usually to use ``const auto&`` instead of writing the21type manually.22