Alexander Kornienko | 4babd68 | 2015-01-15 15:46:58 +0000 | [diff] [blame^] | 1 | //===--- ContainerSizeEmpty.h - clang-tidy ----------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_CONTAINERSIZEEMPTY_H |
| 11 | #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_CONTAINERSIZEEMPTY_H |
| 12 | |
| 13 | #include "../ClangTidy.h" |
| 14 | |
| 15 | namespace clang { |
| 16 | namespace tidy { |
| 17 | namespace readability { |
| 18 | |
| 19 | /// \brief Checks whether a call to the \c size() method can be replaced with a |
| 20 | /// call to \c empty(). |
| 21 | /// |
| 22 | /// The emptiness of a container should be checked using the \c empty() method |
| 23 | /// instead of the \c size() method. It is not guaranteed that \c size() is a |
| 24 | /// constant-time function, and it is generally more efficient and also shows |
| 25 | /// clearer intent to use \c empty(). Furthermore some containers may implement |
| 26 | /// the \c empty() method but not implement the \c size() method. Using \c |
| 27 | /// empty() whenever possible makes it easier to switch to another container in |
| 28 | /// the future. |
| 29 | class ContainerSizeEmptyCheck : public ClangTidyCheck { |
| 30 | public: |
| 31 | ContainerSizeEmptyCheck(StringRef Name, ClangTidyContext *Context); |
| 32 | void registerMatchers(ast_matchers::MatchFinder *Finder) override; |
| 33 | void check(const ast_matchers::MatchFinder::MatchResult &Result) override; |
| 34 | }; |
| 35 | |
| 36 | } // namespace readability |
| 37 | } // namespace tidy |
| 38 | } // namespace clang |
| 39 | |
| 40 | #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_CONTAINERSIZEEMPTY_H |