----- struct S { float value = 0.0; alias value this; } float f = 250.0; // ok S s = 250.0; // ng void main() { } ----- Error: cannot implicitly convert expression (250.000) of type double to S I think the above should work.
This does give me an idea for a DIP: struct S { float value = 0.0; alias value this; // called only when a *literal* is provided this(enum double val) { } } This would enable creating custom implicit conversions when initializing a struct with a literal of some sort.
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18573 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB