Casting by assigning to the right ...

Manfred Nowak svv1999 at hotmail.com
Wed Apr 15 09:56:02 UTC 2020


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?

------

struct S{
   string data;
     import std.conv: to;
   void _( ref int arg){
     arg= to!int( data) *10;
   }
   void _( real* arg){
     *arg= to!real( data) *10 +1;
   }
}
void main(){
   auto s= S( "42");

   int i;
   s  ._=  i;

   real r;
   s  ._=&  r;

     import std.stdio;
   writeln( i, ":", r); // 420:421
}


More information about the Digitalmars-d mailing list