Issue 173108
Summary [clang-tidy]: Check request - bugprone-unordered-equal-compare
Labels
Assignees
Reporter denzor200
    std::equal should not be used to compare the ranges formed by the iterators from [std::unordered_set](https://en.cppreference.com/w/cpp/container/unordered_set.html), [std::unordered_multiset](https://en.cppreference.com/w/cpp/container/unordered_multiset.html), [std::unordered_map](https://en.cppreference.com/w/cpp/container/unordered_map.html), or [std::unordered_multimap](https://en.cppreference.com/w/cpp/container/unordered_multimap.html) because the order in which the elements are stored in those containers may be different even if the two containers store the same elements.

When comparing entire containers or string views(since C++17) for equality, `operator==` for the corresponding type are usually preferred.
See https://en.cppreference.com/w/cpp/algorithm/equal.html for more details.

Example:
```
void bad_example() {
    std::unordered_set<int> a, b;
    // WARNING: bugprone-unordered-equal-compare
    bool wrong = std::equal(a.begin(), a.end(), b.begin());
    
    // OK - good comparison
    bool correct = (a == b);
}
```

_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to