Implicit type conversion depending on assignment

Alexander Zhirov azhirov1991 at gmail.com
Thu Mar 23 14:36:11 UTC 2023


On Thursday, 23 March 2023 at 14:19:31 UTC, user1234 wrote:
> omg, let's rewrite this...

I meant something like that. But you can't do that. I wanted 
WITHOUT explicit casting.

```d
struct MyVal
{
     private string value;

     @property auto toString(T)()
     {
         return value.to!T;
     }

     alias toString this;
}

auto a = MyVal("100");
auto b = MyVal("11.2");

int myInt       = a;
float myFloat   = b;
```




More information about the Digitalmars-d-learn mailing list