Is there an easier way to achieve the effect of this function?
strong_ordering reverse(strong_ordering v) {
if (v > 0)
return strong_ordering::less;
else if (v < 0)
return strong_ordering::greater;
else
return v;
}
Yep:
strong_ordering reverse(strong_ordering v)
{
return 0 <=> v;
}
Which is literally specified as what you want:
Returns:
v < 0 ? strong_ordering::greater : v > 0 ? strong_ordering::less : v.
This follows the general principle that x <=> y and y <=> x are opposites, and v <=> 0 is just an identity operation for v.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With