std::span.size() vs array/vector size

686 Views Asked by At

We are playing around with std::span() (using the gsl implementation for now) at work. Recently we discovered that comparing a std::span.size() to a vector.size() was giving a -Wsign-compare error:

if( span.size() > vector.size() ) // comparison between signed and unsigned integer expressions [-Wsign-compare]

I don't think we want to cast at every one of these comparisons. Our coding guidelines treat these warnings as errors. Curious if anyone has any ideas or suggestions?

1

There are 1 best solutions below

0
On

You could use iterators and have both use the function std::distance().

if (std::distance(s.begin(), s.end()) > std::distance(v.begin(), v.end()))