3 ms·
For anyone that read the code at the end of this article and was wondering what the spaceship / flying saucer operator <=> was doing in a C++ program, I found a
by nickcw 5y ago
For anyone that read the code at the end of this article and was wondering what the spaceship / flying saucer operator <=> was doing in a C++ program, I found a write up on this on stack overflow page:
https://stackoverflow.com/a/47466459/164234 https://stackoverflow.com/a/47466459/164234
According to that, this was added in C++20 and means
> There’s a new three-way comparison operator, <=>. The expression a <=> b returns an object that compares <0 if a < b, compares >0 if a > b, and compares ==0 if a and b are equal/equivalent.
I first saw this in Perl a long time ago and according to Wikipedia it is in Perl, Ruby, Apache Groovy, PHP, Eclipse Ceylon as well as C++ now.
https://en.wikipedia.org/wiki/Three-way_comparison https://en.wikipedia.org/wiki/Three-way_comparison