opUnaryAssign

monkyyy crazymonkyyy at gmail.com
Wed Jul 3 13:26:35 UTC 2024


On Wednesday, 3 July 2024 at 10:43:14 UTC, Quirin Schroll wrote:
> Index operators (e.g. `obj[i]`) have special overloads so that 
> they hook assignment: `obj[i] = rhs` lowers to 
> `obj.opIndexAssign(rhs, i)`. Why not back-port this to 
> dereferencing? `*obj` lowers to `obj.opUnary!"*"`, which, to be 
> assignable, must return by reference. Why not add 
> `opUnaryAssign(string op)` which can hook, in principle, `+obj 
> = rhs`, `-obj = rhs`, `~obj = rhs`, `*obj = rhs`, `++obj = 
> rhs`, and `--obj = rhs` (of which I expect only `*obj = rhs` to 
> be used regularly).

wouldnt `+obj=rhs` combined with "assignment returns" be 
ambiguous in some case?

~~idk why people use assignment returns, its incredibly backwards 
of sanity and im fuzzy on the syntax~~


More information about the dip.ideas mailing list