www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Coexistence of static and unstatic method

reply "Namespace" <rswhite4 googlemail.com> writes:
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
next sibling parent "Namespace" <rswhite4 googlemail.com> writes:
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
prev sibling parent reply Jacob Carlborg <doob me.com> writes:
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
parent "Namespace" <rswhite4 googlemail.com> writes:
 http://d.puremagic.com/issues/show_bug.cgi?id=3345
This means it doesn't work? That sucks -.-
Jun 30 2012