dmd command line scripting experiments and observations

Witold Baryluk witold.baryluk at gmail.com
Mon Dec 25 16:02:33 UTC 2023


On Monday, 25 December 2023 at 15:50:52 UTC, Sergey wrote:
> On Monday, 25 December 2023 at 12:45:50 UTC, Witold Baryluk 
> wrote:
>> post), but about language design, and make D useful in wider 
>> area of applications.
>
> I didn’t take the post yeah.
> Why not use templates type to support not only double but any T?


It just doesn't work.


```
struct DT {
// ...
}

auto c = 0;   // or 0.0, doesn't matter

c = DT("1");
```


c will infer to be `int`, or `double`. There is no way to 
convince D compiler to make it call some operator to do a 
conversion.  There is no `opAssignRight`.

I do not see how templates help.


As a hack, I can do:

```
c := 0;
c = DT("1")
```


And instead of converting `varname := ` to `auto varname = `, do 
`DT varname = `. Then I could probably do something about it.

But I think sometimes you want to force a type, or have an empty 
and default initialized variable like "string c;". Otherwise it 
looks not like D, and very hacky in general.




More information about the Digitalmars-d mailing list