digitalmars.D.learn - Implicit conversion from a base/array type
- alexhairyman (16/16) Feb 01 2014 Is there a way to implicitly convert *FROM* a base type? I have
- Martijn Pot (6/6) Feb 01 2014 I tried something similar to (check first answer):
- alexhairyman (4/11) Feb 01 2014 qxqdksfoamarwjtpjcfq:40forum.dlang.org
- TheFlyingFiddle (4/20) Feb 01 2014 D currencly has no implicit casting operator overloading. It has
- alexhairyman (2/29) Feb 01 2014 Hmmm, interesting
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? }
Feb 01 2014
I tried something similar to (check first answer): http://stackoverflow.com/questions/121162/what-does-the-explicit-keyword-in-c-mean but I can't get it to work. But then again... I'm just starting with D. It seems not to be supported: http://forum.dlang.org/thread/teddgvbtmrxumffrhojh forum.dlang.org#post-qxqdksfoamarwjtpjcfq:40forum.dlang.org
Feb 01 2014
On Sat, 01 Feb 2014 21:18:12 +0000, Martijn Pot wrote:I tried something similar to (check first answer): http://stackoverflow.com/questions/121162/what-does-the-explicit-keyword-in-c-meanbut I can't get it to work. But then again... I'm just starting with D. It seems not to be supported: http://forum.dlang.org/thread/teddgvbtmrxumffrhojh forum.dlang.org#post-qxqdksfoamarwjtpjcfq:40forum.dlang.org Thanks, a little bit more work, but thanks for the link
Feb 01 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 http://wiki.dlang.org/DIP52 but i am not sure what the state of that is as of now.
Feb 01 2014
On Sat, 01 Feb 2014 21:23:07 +0000, TheFlyingFiddle wrote:On Saturday, 1 February 2014 at 20:26:27 UTC, alexhairyman wrote:Hmmm, interestingIs 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 http://wiki.dlang.org/DIP52 but i am not sure what the state of that is as of now.
Feb 01 2014