Which operators cannot be overloaded and why not?

user1234 user1234 at 12.de
Mon Sep 13 14:33:03 UTC 2021


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.

- `new` and `delete`

Because operators are overloaded in aggregates
new was supported but not anymore, the idea is
that a an aggregate should not be tied a specific allocator.

- post incr/decr

See 
[https://dlang.org/spec/operatoroverloading.html#postincrement_postdecrement_operators](explantations). This is an arbitrary limitation imho but the current way enfore that the side effect is not apllied to the expression result.

- condition al expression ` cond ? exp : exp `

No idea why it is not supported... nobody has never complained 
tho ;)

- `typeid`

Same... the result of typeid has to be a TypeInfoClass, so 
there's not much to do... exactness is expected

- `is` (identity)

could be but I suppose that this stuff needs to be correct to 
keep code consistent

what else ?


More information about the Digitalmars-d-learn mailing list