Which operators cannot be overloaded and why not?
Thread overview | |||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
September 13, 2021 Which operators cannot be overloaded and why not? | ||||
---|---|---|---|---|
| ||||
September 13, 2021 Re: Which operators cannot be overloaded and why not? | ||||
---|---|---|---|---|
| ||||
Posted in reply to NonNull | On Monday, 13 September 2021 at 14:12:36 UTC, NonNull wrote: >Which operators cannot be overloaded and why not? Let's start the list.
Because operators are overloaded in aggregates
See https://dlang.org/spec/operatoroverloading.html#postincrement_postdecrement_operators. This is an arbitrary limitation imho but the current way enfore that the side effect is not apllied to the expression result.
No idea why it is not supported... nobody has never complained tho ;)
Same... the result of typeid has to be a TypeInfoClass, so there's not much to do... exactness is expected
could be but I suppose that this stuff needs to be correct to keep code consistent what else ? |
September 13, 2021 Re: Which operators cannot be overloaded and why not? | ||||
---|---|---|---|---|
| ||||
Posted in reply to user1234 | On Monday, 13 September 2021 at 14:33:03 UTC, user1234 wrote: >
And many other boolean operators, unary !, binary && and || https://dlang.org/spec/operatoroverloading.html lists all the overloadable operators, and https://dlang.org/spec/expression.html has all the operators, so "which operators" is a matter of close comparison. "why not" is much harder to answer. |
September 13, 2021 Re: Which operators cannot be overloaded and why not? | ||||
---|---|---|---|---|
| ||||
Posted in reply to user1234 | On Monday, 13 September 2021 at 14:33:03 UTC, user1234 wrote: >what else ? when you have
then you can write
The |
September 13, 2021 Re: Which operators cannot be overloaded and why not? | ||||
---|---|---|---|---|
| ||||
Posted in reply to jfondren | On Monday, 13 September 2021 at 14:42:42 UTC, jfondren wrote: >On Monday, 13 September 2021 at 14:33:03 UTC, user1234 wrote: >
And many other boolean operators, unary !, binary && and || https://dlang.org/spec/operatoroverloading.html lists all the overloadable operators, and https://dlang.org/spec/expression.html has all the operators, so "which operators" is a matter of close comparison. "why not" is much harder to answer. I think the intent is for the boolean operators to be handled via |
September 13, 2021 Re: Which operators cannot be overloaded and why not? | ||||
---|---|---|---|---|
| ||||
Posted in reply to user1234 | On 9/13/21 10:47 AM, user1234 wrote: >On Monday, 13 September 2021 at 14:33:03 UTC, user1234 wrote: >what else ? when you have
then you can write
The This is because the compiler calls a different hook depending on the usage of the expression There isn't an analog for indexing overloads. A further example:
-Steve |
September 13, 2021 Re: Which operators cannot be overloaded and why not? | ||||
---|---|---|---|---|
| ||||
Posted in reply to jfondren | On Monday, 13 September 2021 at 14:42:42 UTC, jfondren wrote: >On Monday, 13 September 2021 at 14:33:03 UTC, user1234 wrote: >
And many other boolean operators, unary !, binary && and || https://dlang.org/spec/operatoroverloading.html lists all the overloadable operators, and https://dlang.org/spec/expression.html has all the operators, so "which operators" is a matter of close comparison. "why not" is much harder to answer. Oh! I have never noticed that In styx that works because, although inspired by the D way, in the sense that overloads are implemented in custom types, the selection is done using an expression template
So as long as the expression in the attribute argument looks like a valid expression the stuff is found (and the supprot code in the compiler is super simple), e.g with code in a body:
While D uses specific identifier + templates value param for strings. anyway. zorry for this off-topic. |
September 13, 2021 Re: Which operators cannot be overloaded and why not? | ||||
---|---|---|---|---|
| ||||
Posted in reply to jfondren | On Monday, 13 September 2021 at 14:42:42 UTC, jfondren wrote: >On Monday, 13 September 2021 at 14:33:03 UTC, user1234 wrote: >
And many other boolean operators, unary !, binary && and || They are all indirectly supported if
so this is a bit like the postincr case. |
September 13, 2021 Re: Which operators cannot be overloaded and why not? | ||||
---|---|---|---|---|
| ||||
Posted in reply to user1234 | On Monday, 13 September 2021 at 15:29:05 UTC, user1234 wrote: >[...] i.e "prevent the semantics to be hijacked". |
September 13, 2021 Re: Which operators cannot be overloaded and why not? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Paul Backus | On Monday, 13 September 2021 at 14:59:38 UTC, Paul Backus wrote: >On Monday, 13 September 2021 at 14:42:42 UTC, jfondren wrote: >On Monday, 13 September 2021 at 14:33:03 UTC, user1234 wrote: >
And many other boolean operators, unary !, binary && and || https://dlang.org/spec/operatoroverloading.html lists all the overloadable operators, and https://dlang.org/spec/expression.html has all the operators, so "which operators" is a matter of close comparison. "why not" is much harder to answer. I think the intent is for the boolean operators to be handled via I didn't see it was already suggested and answered the same... but yet that's exactly the case. |