On 11/01/18 12:32, Jonathan Wakely wrote: > On 11 January 2018 at 11:28, David Brown wrote: >> 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. > > It seems like the wrong trade-off. We have dozens of features that > depend on the standards mode, we know how to do that. > > Simply slamming a new language feature in all modes (*and* in a > different language with a different front-end!) to save a small amount > of effort doesn't seem like a good idea to me. Especially if it then > doesn't even work the same pre-C++2a, as know we need to test it in > additional ways. >
Fair enough. I was merely thinking it might make the development a little easier by avoiding more feature testing in the front ends. And gcc has a history of making some features of one language or standard available in others as gcc extensions. (Sometimes I find these useful in my coding - though I can't think off-hand for a use of <=> in my own programs.) But I see pre-C++2a would be a problem here. You can't make it match the C++2a version, because you don't have the types available - and you wouldn't want to make it have different types that are incompatible with the C++2a version. It would be fine with a -1, 0, 1 int result in C - but not in pre-C++2a.