Re: Operator overloading problem

2010-08-07 Thread div0
On 07/08/2010 16:25, Blonder wrote: Is there a difference (performance) or something else between the two solutions? I doubt it, templates are applied at compile time in the front end of the compiler so the generated code should be the same. The if style syntax allows much more comprehensive

Re: Operator overloading problem

2010-08-07 Thread Blonder
Is there a difference (performance) or something else between the two solutions?

Re: Operator overloading problem

2010-08-06 Thread Blonder
Thanks, that is the solution. > No programming language is intuitive; they all take time to learn. > D is a big win over C++ though and well worth sticking with. Yes, you are right, it takes time to learn. @Philippe Sigaud Thanks also.

Re: Operator overloading problem

2010-08-06 Thread div0
On 06/08/2010 22:24, Blonder wrote: Hello, this seems to work, but if I add the following double opBinary(string op, U) (U rhs) { static if(op == "^"&& is(U: Group)) { // do something return 42;

Re: Operator overloading problem

2010-08-06 Thread Blonder
Hello, this seems to work, but if I add the following double opBinary(string op, U) (U rhs) { static if(op == "^" && is(U: Group)) { // do something return 42; } } because I wa

Re: Operator overloading problem

2010-08-06 Thread Philippe Sigaud
On Fri, Aug 6, 2010 at 22:37, div0 wrote: > Personally, I'm with you and I would expect that the compiler should > example the function parameters after the template string parameter but it > doesn't. > Yes :o( You need to add a second template parameter for the function arguments and add a temp

Re: Operator overloading problem

2010-08-06 Thread div0
On 06/08/2010 21:37, div0 wrote: You need to add a second template parameter for the function arguments and add a template constrait like so: struct Group { int i1; Group opBinary(string op, U) (U x) if(op == "+" && is(U: int)) { // do somehting return this;

Re: Operator overloading problem

2010-08-06 Thread div0
On 06/08/2010 21:08, Blonder wrote: Hello, I am trying to understand how operator overloading works with D. I am a C++ programmer and I am reading the book of Andrei Alexandrescu and try to understand D and it's language features. My Group example don't compile, the error is: Error: template i

Re: Operator overloading problem

2010-08-06 Thread Blonder
Hello, I am trying to understand how operator overloading works with D. I am a C++ programmer and I am reading the book of Andrei Alexandrescu and try to understand D and it's language features. My Group example don't compile, the error is: Error: template instance opBinary!("+") matches more th

Re: Operator overloading problem

2010-08-06 Thread Jonathan M Davis
On Friday, August 06, 2010 12:30:38 Blonder wrote: > Hello, > > can someone help me with this? > > struct Group { > int i1; > Group opBinary(string op)(int x) { > // do somehting > return this; > } > Group opBinary(string op)(Group g) { > // do something >

Operator overloading problem

2010-08-06 Thread Blonder
Hello, can someone help me with this? struct Group { int i1; Group opBinary(string op)(int x) { // do somehting return this; } Group opBinary(string op)(Group g) { // do something return this; } } Group g, h; g.i1 = 1; h = g+g;