Skip to content

Commit 87688f9

Browse files
committed
[clang-tidy] Adjust size-empty doc because C++11 size() is constant-time
From C++11, a conforming `size()` method is guaranteed to be a constant-time function. `empty()` is not _generally_ more efficient than `size()`. It might even be implemented in terms of `size()`.
1 parent 99fd1c5 commit 87688f9

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@ namespace clang::tidy::readability {
1818
/// a call to `empty()`.
1919
///
2020
/// The emptiness of a container should be checked using the `empty()` method
21-
/// instead of the `size()` method. It is not guaranteed that `size()` is a
22-
/// constant-time function, and it is generally more efficient and also shows
23-
/// clearer intent to use `empty()`. Furthermore some containers may implement
24-
/// the `empty()` method but not implement the `size()` method. Using `empty()`
25-
/// whenever possible makes it easier to switch to another container in the
26-
/// future.
21+
/// instead of the `size()` method. It shows clearer intent to use `empty()`.
22+
/// Furthermore some containers may implement the `empty()` method but not
23+
/// implement the `size()` method. Using `empty()` whenever possible makes it
24+
/// easier to switch to another container in the future.
2725
class ContainerSizeEmptyCheck : public ClangTidyCheck {
2826
public:
2927
ContainerSizeEmptyCheck(StringRef Name, ClangTidyContext *Context);

0 commit comments

Comments
 (0)