Opened 6 years ago

Closed 6 years ago

#849 closed defect (fixed)

clang-tidy: readability-container-size-empty size() == 0 can be replaced with empty()

Reported by: goatbar Owned by: geos-devel@…
Priority: minor Milestone: 3.8.0
Component: Default Version: main
Severity: Unassigned Keywords: clangtidy size empty readability-container-size-empty
Cc:

Description

https://clang.llvm.org/extra/clang-tidy/checks/readability-container-size-empty.html

There are at least 9 of these

e.g.

std::size_t
CoordinateArraySequence::getDimension() const
{
    if( dimension != 0 )
        return dimension;

    if( vect->size() == 0 )
        return 3;

    if( ISNAN((*vect)[0].z) )
        dimension = 2;
    else
        dimension = 3;

    return dimension;
}

Could be

std::size_t
CoordinateArraySequence::getDimension() const
{
    if( dimension != 0 )
        return dimension;

    if( vect->empty() )  // <<-- fix here
        return 3;

    if( ISNAN((*vect)[0].z) )
        dimension = 2;
    else
        dimension = 3;

    return dimension;
}

Change History (4)

comment:1 by goatbar, 6 years ago

Summary: clang-tidy: readability-container-size-empty site() == 0 can be replaced with empty()clang-tidy: readability-container-size-empty size() == 0 can be replaced with empty()

comment:2 by robe, 6 years ago

Milestone: 3.6.33.8.0

comment:3 by goatbar, 6 years ago

See #860 for another case:

double
ElevationMatrixCell::getAvg() const
{
        return  zvals.size() ?  // <-- here
                ztot / static_cast<double>(zvals.size()) :
                DoubleNotANumber;
}

comment:4 by cvvergara <vicky@…>, 6 years ago

Resolution: fixed
Status: newclosed

In 55d8d35/git:

Closes #849, Using empty() instead of comparing size() vs 0

Note: See TracTickets for help on using tickets.