In c++20 the new three way comparison operator <=> (spaceship operator) is introduced and it can result into four values given below :
- std::strong_ordering::less
- std::strong_ordering::equivalent
- std::strong_ordering::equal
- std::strong_ordering::greater
However when I run below code snippet it appears that both equal and equivalent are one and some thing, so I want to know what is the difference between them and in what scenario we should prefer one over another.
#include <iostream>
#include <compare>
int main()
{
std::strong_ordering res = (2<=>2);
if(res == std::strong_ordering::equivalent)
{
std::cout<<"Equivalent...."<<std::endl;
}
if(res == std::strong_ordering::equal)
{
std::cout<<"Equal"<<std::endl;
}
return 0;
}
O/P :
Equivalent....
Equal