3 ms·
No, it would be the same as evaluating (a<b)&&(a==b)&&(a>b), not std::is_nan.
by idea1434 9y ago
No, it would be the same as evaluating (a<b)&&(a==b)&&(a>b), not std::is_nan.
- slavik81 9y agoA special syntax seems unnecessary. Just drop something like this in your project: template<typename A, typename B> bool is_unordered(const A& a, const B& b) { return !(a<b||a==b||a>b); } edit: changed implementation to match name.
- idea1434 9y agoIt just makes more sense. Similar to how a<=b is equivalent to (a<b)&&(a==b). Coming up with an entirely fresh meaning for <=> involving spaceships and a conglomerated comparative threesome just seems illogical to me, given the original meanings of the component symbols of <=>.
- slavik81 9y agoThis operator already exists in Ruby, Perl and a couple other languages. It's also incredibly useful, allowing six functions to be replaced by one. Or, rather, with zero, because in 99.9% of cases you will just be able to declare the signature with '= default;' and let the compiler generate the implementation. Then you have all relational operators available for that type. It makes defining new types much, much easier. Plus, it provides a place to statically define what sort of ordering the type has, so further compile-time optimizations can be done. In contrast, <=> as is_ordered is nearly useless. It would basically only be used for floats, where !(isnan(a)||isnan(b)) is both equivalent and IMO more clear.
- verall 9y ago(a<=b) is equivalent to ((a<b)||(a==b)) ((a<b)&&(a==b)) is equivalent to (false)
- LeifCarrotson 9y agoYou mean: (a<b)||(a==b)||(a>b) Double ampersand is logical AND, you want double bars for logical OR. And still, that's equivalent to !(std::is_nan()), unless you're suggesting using the operator on other non-floating-point types which have a similar problem...