Casting by assigning to the right ...

Paul Backus snarwin at gmail.com
Wed Apr 15 14:42:11 UTC 2020


On Wednesday, 15 April 2020 at 09:56:02 UTC, Manfred Nowak wrote:
> On Wednesday, 15 April 2020 at 07:44:23 UTC, aliak wrote:
>> [...] it feels weird.
>
> Yes. But `._=' is legal Dlang.
>
> In C one would have to annotate the possibility of writing to a 
> parameter by using `&' to get the address of the variable.
>
> Would the legal Dlang phrase `._=&' make the intention more 
> clear?

If you want to communicate the meaning of your code to other D 
programmers, the clearest way to do it is to use language 
features whose meaning they already know and understand:

lhs = cast(typeof(lhs)) rhs;

If that's unacceptable, the next clearest way is to use words:

lhs.castAssign(rhs);

If you insist on inventing a new symbol, no one will understand 
it without being taught. That's how symbols work. Just like you 
didn't know what + and × meant until you learned them in school, 
no one reading your code will know what `._=` means until they 
learn it by reading your documentation.


More information about the Digitalmars-d mailing list