clang-tools 22.0.0git
clang::tidy::readability::ContainerSizeEmptyCheck Class Reference

Checks whether a call to the size()/length() method can be replaced with a call to empty(). More...

#include <ContainerSizeEmptyCheck.h>

Inheritance diagram for clang::tidy::readability::ContainerSizeEmptyCheck:
[legend]

Public Member Functions

 ContainerSizeEmptyCheck (StringRef Name, ClangTidyContext *Context)
bool isLanguageVersionSupported (const LangOptions &LangOpts) const override
void registerMatchers (ast_matchers::MatchFinder *Finder) override
void check (const ast_matchers::MatchFinder::MatchResult &Result) override
void storeOptions (ClangTidyOptions::OptionMap &Opts) override
std::optional< TraversalKind > getCheckTraversalKind () const override

Detailed Description

Checks whether a call to the size()/length() method can be replaced with a call to empty().

The emptiness of a container should be checked using the empty() method instead of the size()/length() method. It shows clearer intent to use empty(). Furthermore some containers (for example, a std::forward_list) may implement the empty() method but not implement the size() or length() method. Using empty() whenever possible makes it easier to switch to another container in the future.

Definition at line 26 of file ContainerSizeEmptyCheck.h.

Constructor & Destructor Documentation

◆ ContainerSizeEmptyCheck()

clang::tidy::readability::ContainerSizeEmptyCheck::ContainerSizeEmptyCheck ( StringRef Name,
ClangTidyContext * Context )

Definition at line 132 of file ContainerSizeEmptyCheck.cpp.

Member Function Documentation

◆ check()

void clang::tidy::readability::ContainerSizeEmptyCheck::check ( const ast_matchers::MatchFinder::MatchResult & Result)
override

◆ getCheckTraversalKind()

std::optional< TraversalKind > clang::tidy::readability::ContainerSizeEmptyCheck::getCheckTraversalKind ( ) const
inlineoverride

Definition at line 35 of file ContainerSizeEmptyCheck.h.

◆ isLanguageVersionSupported()

bool clang::tidy::readability::ContainerSizeEmptyCheck::isLanguageVersionSupported ( const LangOptions & LangOpts) const
inlineoverride

Definition at line 29 of file ContainerSizeEmptyCheck.h.

◆ registerMatchers()

void clang::tidy::readability::ContainerSizeEmptyCheck::registerMatchers ( ast_matchers::MatchFinder * Finder)
override

◆ storeOptions()

void clang::tidy::readability::ContainerSizeEmptyCheck::storeOptions ( ClangTidyOptions::OptionMap & Opts)
override

The documentation for this class was generated from the following files: