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?
您可以使用迭代器,并且都可以使用函数std::distance()
。
if (std::distance(s.begin(), s.end()) > std::distance(v.begin(), v.end()))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.