Implicit conversion from a base/array type

TheFlyingFiddle theflyingfiddle at
Sat Feb 1 13:23:07 PST 2014

On Saturday, 1 February 2014 at 20:26:27 UTC, alexhairyman wrote:
> Is there a way to implicitly convert *FROM* a base type? I have 
> an implicit conversion to a base type (float[2]) in a struct, 
> but now I'd like to be able to implicitly convert from a base 
> type (in this case a float[2]) to a struct.
> Is this even allowed? Is it incorrect or unsafe? I'm still 
> pretty new so there could be a major reason to not want to do 
> this. I also did a lot of searching of the site, I hope I 
> didn't miss something major, but I might have.
> example :
> struct Coord {...} // X,Y wrapper-like type, implicitly 
> converts to/from float
> void DoCoord(Coordinate c) {... do stuff...}
> void main()
> {
>   DoCoord ([0.0f, 5.0f]); // Is it possible to set this up?
> }

D currencly has no implicit casting operator overloading. It has 
been proposed before in but i am not 
sure what the state of that is as of now.

More information about the Digitalmars-d-learn mailing list