Comment #0 by andrej.mitrovich — 2013-04-29T03:30:47Z
-----
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.
Comment #1 by andrej.mitrovich — 2013-04-29T03:32:28Z
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.
Comment #2 by robert.schadek — 2024-12-13T18:06:31Z