Quantcast
Channel: User HolyBlackCat - Stack Overflow
Viewing all articles
Browse latest Browse all 1287

Answer by HolyBlackCat for c++20 vector comparison weird behaviour

$
0
0

C++20 replaces the individual <,<=,>,>= operators of std::vector (and of many other standard classes) with a single <=>.

Internally it tries to use <=> to compare the elements, and falls back to the old operators if the type doesn't overload <=>.

Since you have a non-explicit operator bool, applying <=> converts both operands to bool and compares those. The fix is to make operator boolexplicit (which is a good idea in general) (so that <=> fails and vector falls back to the old operators), and/or replace <,<=,>,>= with <=> (which is also a good idea in general).


Viewing all articles
Browse latest Browse all 1287

Trending Articles