template/mixin magic for to! auto inferring type from variable

Chris Katko ckatko at gmail.com
Fri Feb 2 07:43:09 UTC 2024


Is there some way to do:
```D
string[3] data; //strings from some file input, some are ints, 
uints, etc.

auto into!(T)(T value){return to!???(value); } // ???

uint time = into!(data[1]); // We already know this is uint
int priority = into!(data[2]);
```

instead of:
```D
uint time = to!uint(data[1]); // specifying type twice
int priority = to!int(data[2])
```


More information about the Digitalmars-d-learn mailing list