Replies: 3 comments 4 replies
-
|
The documentation for overload suggests that fallback => 1 is bad, and you should just not specify fallback at all. (If I omit the So maybe the API should be to say e.g. use overload
autogenerate => ['ne'],
eq => sub ($this, $that, $) { return "orange" eq $that };if you wanted to opt in to new ways of autogenerating missing methods? And maybe you could also say e.g. use overload
autogenerate => [':v5.40', 'ne'],
...;if you wanted to explicitly say "do all the standard autogenerations plus this one". |
Beta Was this translation helpful? Give feedback.
-
|
I think it's reasonable (C++ 20 does it, for example, C# requires The only way I can see it causing backward compatibility would be if a class tested that the equal worked while not equal didn't |
Beta Was this translation helpful? Give feedback.
-
|
I think this is something that can only be answered by attempting it. I can conceive of this causing a surprising amount of fallout due to some subtlety that isn’t easy to see without being knee-deep in the details of this area. I can just as easily conceive of it causing virtually or even entirely no issues. And no issues, it seems a no-brainer. If tons of fallout, I’d call it a no-go – it doesn’t seem important enough to pay for the friction in the ecosystem. If there is some fallout but not massive, it would be a judgement call. That might be when we think about adding API surface for example. I don’t know anything about the guts that would have to be patched but it seems to me like this should not be too much effort to implement? If it wouldn’t be a huge waste of effort if we decided against it, I’d say just go for it and we’ll find out. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
The
use overloadpragma has the ability to guess how to behave for operators that you didn't explicitly define, if you provided certain other ones. For example, if you just provide acmpoperator, it can use that to provide all the other 6 string comparisons:That's useful.
I'm currently looking at the overload logic for other reasons, and I thought I recalled that it can generate an
neoperator by inverting the sense of aeqoperator, but it appears it can't:It should have also printed "Not different" here, but it didn't, because the
neoperator didn't fall back to usingeqand inverting the result. Instead it stringified the object reference and then used plainnelogic.I wonder - should it?
I ask specifically because, in the course of implementing operator overloading as part of PPC0030, it occurs to me that even if people provide overloaded implementations of
equ, they are unlikely to want to write another one forneu. It ought to be easily possible to have the overload mechanism provide one by just invoking the not-inverted one and invert the result.And of course, all the same arguments can be made for the numerical versions of these operators.
This would be especially useful because in the realm of people creating custom object types with custom overloaded operators, it's not always possible to put those objects into total orderings. There are many mathematical structures whose members can be compared for equality without being put into an order, so it would make sense for classes implementing those to provide an
eqorequwithout providingcmp. It would be useful if theneorneuoperators could then do the right thing even in the absence of thatcmp.Beta Was this translation helpful? Give feedback.
All reactions