digitalmars.D.learn - Coexistence of static and unstatic method
- Namespace (11/11) Jun 30 2012 I have this class: http://dpaste.dzfl.pl/95990b4e
- Namespace (12/12) Jun 30 2012 I've tried different things and that here indeed compiles, but
- Jacob Carlborg (4/14) Jun 30 2012 http://d.puremagic.com/issues/show_bug.cgi?id=3345
- Namespace (1/2) Jun 30 2012 This means it doesn't work? That sucks -.-
I have this class: http://dpaste.dzfl.pl/95990b4e and would like that this call "Vector2s vec = Vector2s(42, 23);" returns a new object and that this call "vec(44, 26)" set the x and y coords from the existing object to 44 and 26. Is that possible? I try to check if the object is initialize with "if (is(this))" but it seems that this is true for static and unstatic methods. P.S.: Is the conversion with "to" accurate? Sometimes U or/and V are the same as T and then it isn't necessary to cast them. Checks "to" if that's the case, and then prevents an explicit cast?
Jun 30 2012
I've tried different things and that here indeed compiles, but does not work as it should/I want. typeof(this) opCall(U, V)(U x, V y) if (__traits(compiles, { this.x = 5; })) { writeln("unstatic opCall"); this.Set(x, y); return this; } static Vector2D!(T) opCall(U, V)(U x, V y) if (!__traits(compiles, { this.x = 5; })) { return new Vector2D!(T)(to!(T)(x), to!(T)(y)); }
Jun 30 2012
On 2012-06-30 10:56, Namespace wrote:I have this class: http://dpaste.dzfl.pl/95990b4e and would like that this call "Vector2s vec = Vector2s(42, 23);" returns a new object and that this call "vec(44, 26)" set the x and y coords from the existing object to 44 and 26. Is that possible? I try to check if the object is initialize with "if (is(this))" but it seems that this is true for static and unstatic methods. P.S.: Is the conversion with "to" accurate? Sometimes U or/and V are the same as T and then it isn't necessary to cast them. Checks "to" if that's the case, and then prevents an explicit cast?http://d.puremagic.com/issues/show_bug.cgi?id=3345 -- /Jacob Carlborg
Jun 30 2012
http://d.puremagic.com/issues/show_bug.cgi?id=3345This means it doesn't work? That sucks -.-
Jun 30 2012