Reputation: 439
From the D Language Reference, opIndexAssign has a signature:
type opIndexAssign(type value, size_t index0, ...);
What would be the significance of the return value, since it states that statements like:
Class[1, 3] = 5;
is equivalent to:
Class.opIndexAssign(5, 1, 3);
I don't see the use of a return value in this kind of statements, but why does the D language reference use the above overload which returns something?
The compiler seems to accept both void and non-void return types but what is the 'correct' one.
Upvotes: 1
Views: 72
Reputation: 25605
It is valid to say something like int a = Class[1] = 2;
, chaining the equality operator, this is sometimes done with arrays so the overload allows it too.
If you return a value, it allows that. If you return void, that kind of code will not compile. It isn't strictly wrong, but the convention is for an assignment to return the value that was assigned to allow such chaining.
Upvotes: 4