Re: Operators overloading in D2

2010-05-17 Thread Steven Schveighoffer
On Mon, 17 May 2010 16:38:49 -0400, Larry Luther wrote: Hi, Dan used the following method for his vector class: void opOpAssign (string op:"+=")(ref Vector3 other) {...} Why the "ref"? As I understand it, objects of class vector would already be passed as references. Larry Yes, ref

Re: Operators overloading in D2

2010-05-17 Thread Larry Luther
Hi, Dan used the following method for his vector class: void opOpAssign (string op:"+=")(ref Vector3 other) {...} Why the "ref"? As I understand it, objects of class vector would already be passed as references. Larry

Re: Operators overloading in D2 again

2010-05-03 Thread bearophile
Dan: > I'm still really sceptic, especially because they look to me inconsistent to > each > other. Yes, they seem divided in two groups, with different level of complexity, etc. This is true, and I think this is by design, opCmp and opEquals and few others are useful in many classes. While ove

Re: Operators overloading in D2 again

2010-05-03 Thread Dan
I'm still really sceptic, especially because they look to me inconsistent to each other. for example opBinary(string op:"something here")(Object other) and then ther is opCmp(Obejct other) which is not template and there is only one for all these operators < <= > >= Did I understand correctly? if

Re: Operators overloading in D2 again

2010-05-03 Thread Lars T. Kyllingstad
On Mon, 03 May 2010 14:28:20 +, Dan wrote: > it certainly helps. However I can't help myself, I still thinking that > this is the most complicated, hard read and to understand way to > overload operators. Maybe there is something I'm missing but I can't > really see the reason of all that. Othe

Re: Operators overloading in D2 again

2010-05-03 Thread Lars T. Kyllingstad
On Mon, 03 May 2010 16:46:41 +, Lars T. Kyllingstad wrote: > [...] > > Pair opBinary(string op)(Pair p) > { > auto r = this; > r.opOpAssign!op(p); Sorry, that last line should be: r.opOpAssign!(op~"=")(p); -Lars

Re: Operators overloading in D2 again

2010-05-03 Thread Pelle
On 05/03/2010 04:28 PM, Dan wrote: Hi, it certainly helps. However I can't help myself, I still thinking that this is the most complicated, hard read and to understand way to overload operators. Maybe there is something I'm missing but I can't really see the reason of all that. Other languages

Re: Operators overloading in D2 again

2010-05-03 Thread Dan
Hi, it certainly helps. However I can't help myself, I still thinking that this is the most complicated, hard read and to understand way to overload operators. Maybe there is something I'm missing but I can't really see the reason of all that. Other languages adopts a much easier approach, for e

Re: Operators overloading in D2 again

2010-05-02 Thread Robert Clipsham
On 02/05/10 07:14, Dan wrote: Hi everyone, is there anyway to do this with operators overloading? : The following code does it: class Tester { double x = 0.0; T opBinary(string op:"+", T)(T value) if(is(T : double)) { return x+value; }

Re: Operators overloading in D2 again

2010-05-01 Thread Ali Çehreli
Dan wrote: Hi everyone, is there anyway to do this with operators overloading? : class Tester { double x = 0.0; double opBinary(string op:"+")(double value) { return x+value; } Tester opBinary(string op:"+")(Tester other) {

Operators overloading in D2 again

2010-05-01 Thread Dan
Hi everyone, is there anyway to do this with operators overloading? : class Tester { double x = 0.0; double opBinary(string op:"+")(double value) { return x+value; } Tester opBinary(string op:"+")(Tester other) { T

Re: Operators overloading in D2

2010-05-01 Thread Dan
That would be great. Thanks again

Re: Operators overloading in D2

2010-04-27 Thread Steven Schveighoffer
On Mon, 26 Apr 2010 18:07:22 -0400, Dan wrote: Thanks guys, it's more clear now. Just another question: are opAdd, opNeg, opAddAssign etc going to be deprecated? The reason is very very stupid: If I use them the documentation output is much more readable :) This is an issue brought up dur

Re: Operators overloading in D2

2010-04-27 Thread bearophile
Dan: > are opAdd, opNeg, opAddAssign etc going to be deprecated? Yes, we can't keep two different ways, one is already complex enough. Bye, bearophile

Re: Operators overloading in D2

2010-04-26 Thread Dan
Thanks guys, it's more clear now. Just another question: are opAdd, opNeg, opAddAssign etc going to be deprecated? The reason is very very stupid: If I use them the documentation output is much more readable :) I know is stupid, but a good documentation is important. Thanks again, I really ho

Re: Operators overloading in D2

2010-04-24 Thread Steven Schveighoffer
On Sat, 24 Apr 2010 05:07:41 -0400, Dan wrote: So there's my questions Why D2 changed in this way the operators overloading? To avoid repeating tons of boilerplate code. For example, you can do this: void opOpAssign(string op)(ref Vector3 other) if (op == "+=" || op == "-=") { mixin("x "

Re: Operators overloading in D2

2010-04-24 Thread div0
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Dan wrote: > Hi All, > So there's my questions > Why D2 changed in this way the operators overloading? > I saw the the compiler compiles both the functions, even considering this I > assume it's not safe to use the old D1 way, > right? Because Walter

Operators overloading in D2

2010-04-24 Thread Dan
Hi All, I just downloaded D2 after a friend of mine told me about it and I was playing with it, just to get confident with the language. In order to do that I was converting a simple geometric Vector3 class I wrote in c++. this is the (relavant for this post) D code class Vector3 { flo