On 11/01/18 11:13, Jonathan Wakely wrote: > t all cleaOn 11 January 2018 at 10:05, David Brown wrote: >> Maybe it is easier to say "gcc supports <=> in C++2a, and as an >> extension also supports it in C and C++ of any standard" ? I don't >> believe there is any way for it to conflict with existing valid code, so >> it would do no harm as a gcc extension like that - and C users can then >> use it too. > > It's not very useful in C because you need the comparison category > types, which are classes defined in <compare> (see > http://en.cppreference.com/w/cpp/header/compare) > > C doesn't have those types, and can't define anything close. >
Surely you can get very close by simply returning an int, value -1, 0 or 1? That is what other languages (like PHP) do for their <=> operator. There are complications - such as for floating point when you have NaNs. But I think you could have a very successful operator if you defined "a <=> b" to be the same as "(a > b) - (a < b)". Whether it would be particularly /useful/ or not is another matter. I was thinking mainly in terms of saving effort when making C++2a support - rather than having to making the new operator conditional on a particular version of the standards, it could be accepted in any version. > And it's non-conforming to declare those types in pre-C++2a, because > the names could be used by user programs. > > Potentially the types could be defined with reserved names like > __strong_ordering, and then make std::strong_ordering a typedef for > that, but there are also changes to the language spec that go with the > new operator, and enabling those pre-C++2a could change the meaning of > valid code. > > So it's not ar it does no harm. >