Warning, /sdk/clazy/docs/checks/README-container-anti-pattern.md is written in an unsupported language. File is not indexed.

0001 # container-anti-pattern
0002 
0003 Finds when temporary containers are being created needlessly.
0004 These cases are usually easy to fix by using iterators, avoiding memory allocations.
0005 
0006 Matches code like:
0007 
0008     {QMap, QHash, QSet}.values().*
0009     {QMap, QHash}.keys().*
0010     {QVector, QSet}.toList().*
0011     QList::toVector().*
0012     QSet::intersect(other).isEmpty()
0013     for (auto i : {QHash, QMap}.values()) {}
0014     foreach (auto i, {QHash, QMap}.values()) {}
0015 
0016 #### Example
0017 
0018     set.toList()[0]; // use set.constFirst() instead
0019     hash.values().size(); // Use hash.size() instead
0020     hash.keys().contains(); // Use hash.contains() instead
0021     hash.values().contains(); // Use std::find(hash.cbegin(), hash.cend(), myValue) instead
0022     map.values(k).foo ; // Use QMap::equal_range(k) instead
0023     for (auto i : hash.values()) {} // Iterate the hash directly instead: for (auto i : hash) {}
0024     QSet::intersect(other).isEmpty() // Use QSet::intersects() instead, avoiding memory allocations and iterations, since Qt 5.6