clang-tools  9.0.0svn
ContainerSizeEmptyCheck.h
Go to the documentation of this file.
1 //===--- ContainerSizeEmptyCheck.h - clang-tidy -----------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_CONTAINERSIZEEMPTYCHECK_H
10 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_CONTAINERSIZEEMPTYCHECK_H
11 
12 #include "../ClangTidyCheck.h"
13 
14 namespace clang {
15 namespace tidy {
16 namespace readability {
17 
18 /// Checks whether a call to the `size()` method can be replaced with a call to
19 /// `empty()`.
20 ///
21 /// The emptiness of a container should be checked using the `empty()` method
22 /// instead of the `size()` method. It is not guaranteed that `size()` is a
23 /// constant-time function, and it is generally more efficient and also shows
24 /// clearer intent to use `empty()`. Furthermore some containers may implement
25 /// the `empty()` method but not implement the `size()` method. Using `empty()`
26 /// whenever possible makes it easier to switch to another container in the
27 /// future.
29 public:
30  ContainerSizeEmptyCheck(StringRef Name, ClangTidyContext *Context);
31  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
32  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
33 };
34 
35 } // namespace readability
36 } // namespace tidy
37 } // namespace clang
38 
39 #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.
Base class for all clang-tidy checks.
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)
llvm::Optional< llvm::Expected< tooling::AtomicChanges > > Result
Definition: Rename.cpp:36