xref: /llvm-project/clang-tools-extra/docs/clang-tidy/checks/performance/inefficient-algorithm.rst (revision 6e566bc5523f743bc34a7e26f050f1f2b4d699a8)
1.. title:: clang-tidy - performance-inefficient-algorithm
2
3performance-inefficient-algorithm
4=================================
5
6
7Warns on inefficient use of STL algorithms on associative containers.
8
9Associative containers implement some of the algorithms as methods which
10should be preferred to the algorithms in the algorithm header. The methods
11can take advantage of the order of the elements.
12
13.. code-block:: c++
14
15  std::set<int> s;
16  auto it = std::find(s.begin(), s.end(), 43);
17
18  // becomes
19
20  auto it = s.find(43);
21
22.. code-block:: c++
23
24  std::set<int> s;
25  auto c = std::count(s.begin(), s.end(), 43);
26
27  // becomes
28
29  auto c = s.count(43);
30