clang-tools  8.0.0svn
ContainerSizeEmptyCheck.h
Go to the documentation of this file.
1 //===--- ContainerSizeEmptyCheck.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_CONTAINERSIZEEMPTYCHECK_H
11 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_CONTAINERSIZEEMPTYCHECK_H
12 
13 #include "../ClangTidy.h"
14 
15 namespace clang {
16 namespace tidy {
17 namespace readability {
18 
19 /// Checks whether a call to the `size()` method can be replaced with a call to
20 /// `empty()`.
21 ///
22 /// The emptiness of a container should be checked using the `empty()` method
23 /// instead of the `size()` method. It is not guaranteed that `size()` is a
24 /// constant-time function, and it is generally more efficient and also shows
25 /// clearer intent to use `empty()`. Furthermore some containers may implement
26 /// the `empty()` method but not implement the `size()` method. Using `empty()`
27 /// whenever possible makes it easier to switch to another container in the
28 /// future.
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_CONTAINERSIZEEMPTYCHECK_H
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
Optional< Expected< tooling::AtomicChanges > > Result
Base class for all clang-tidy checks.
Definition: ClangTidy.h:127
Checks whether a call to the size() method can be replaced with a call to empty().
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
static constexpr llvm::StringLiteral Name
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
ContainerSizeEmptyCheck(StringRef Name, ClangTidyContext *Context)