You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[clang-tidy][readability-container-contains] Extend to any class with contains (#107521)
This check will now work out of the box with other containers that have a
`contains` method, such as `folly::F14` or Abseil containers.
It will also work with strings, which are basically just weird containers.
`std::string` and `std::string_view` will have a `contains` method starting with
C++23. `llvm::StringRef` and `folly::StringPiece` are examples of existing
implementations with a `contains` method.
Copy file name to clipboardExpand all lines: clang-tools-extra/docs/clang-tidy/checks/readability/container-contains.rst
+23-15
Original file line number
Diff line number
Diff line change
@@ -3,23 +3,31 @@
3
3
readability-container-contains
4
4
==============================
5
5
6
-
Finds usages of ``container.count()`` and ``container.find() == container.end()`` which should be replaced by a call to the ``container.contains()`` method introduced in C++20.
6
+
Finds usages of ``container.count()`` and
7
+
``container.find() == container.end()`` which should be replaced by a call to
8
+
the ``container.contains()`` method.
7
9
8
-
Whether an element is contained inside a container should be checked with ``contains`` instead of ``count``/``find`` because ``contains`` conveys the intent more clearly. Furthermore, for containers which permit multiple entries per key (``multimap``, ``multiset``, ...), ``contains`` is more efficient than ``count`` because ``count`` has to do unnecessary additional work.
10
+
Whether an element is contained inside a container should be checked with
11
+
``contains`` instead of ``count``/``find`` because ``contains`` conveys the
12
+
intent more clearly. Furthermore, for containers which permit multiple entries
13
+
per key (``multimap``, ``multiset``, ...), ``contains`` is more efficient than
14
+
``count`` because ``count`` has to do unnecessary additional work.
0 commit comments