clang-tools
8.0.0
llvm.src
tools
clang
tools
extra
clang-tidy
readability
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.
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_CONTAINERSIZEEMPTYCHECK_H
clang::tidy::readability::ContainerSizeEmptyCheck::check
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
Definition:
ContainerSizeEmptyCheck.cpp:104
clang::tidy::ClangTidyCheck
Base class for all clang-tidy checks.
Definition:
ClangTidy.h:127
clang::tidy::readability::ContainerSizeEmptyCheck
Checks whether a call to the size() method can be replaced with a call to empty().
Definition:
ContainerSizeEmptyCheck.h:29
clang::tidy::readability::ContainerSizeEmptyCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
Definition:
ContainerSizeEmptyCheck.cpp:29
Name
static constexpr llvm::StringLiteral Name
Definition:
UppercaseLiteralSuffixCheck.cpp:28
Result
llvm::Optional< llvm::Expected< tooling::AtomicChanges > > Result
Definition:
ClangdServer.cpp:60
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition:
ChangeNamespace.cpp:18
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition:
ClangTidyDiagnosticConsumer.h:100
clang::tidy::readability::ContainerSizeEmptyCheck::ContainerSizeEmptyCheck
ContainerSizeEmptyCheck(StringRef Name, ClangTidyContext *Context)
Definition:
ContainerSizeEmptyCheck.cpp:25
Generated on Tue Feb 12 2019 09:14:55 for clang-tools by
1.8.13