clang-tools
10.0.0
clang-tools-extra
clang-tidy
readability
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.
28
class
ContainerSizeEmptyCheck
:
public
ClangTidyCheck
{
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
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:103
clang::tidy::ClangTidyCheck
Base class for all clang-tidy checks.
Definition:
ClangTidyCheck.h:47
clang::tidy::readability::ContainerSizeEmptyCheck
Checks whether a call to the size() method can be replaced with a call to empty().
Definition:
ContainerSizeEmptyCheck.h:28
clang::tidy::readability::ContainerSizeEmptyCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
Definition:
ContainerSizeEmptyCheck.cpp:28
Name
static constexpr llvm::StringLiteral Name
Definition:
UppercaseLiteralSuffixCheck.cpp:27
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition:
ApplyReplacements.h:27
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition:
ClangTidyDiagnosticConsumer.h:77
clang::tidy::readability::ContainerSizeEmptyCheck::ContainerSizeEmptyCheck
ContainerSizeEmptyCheck(StringRef Name, ClangTidyContext *Context)
Definition:
ContainerSizeEmptyCheck.cpp:24
Generated on Mon Mar 23 2020 19:20:48 for clang-tools by
1.8.13