www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Operator overloading

reply "Bruno A. Costa" <bruno codata.com.br> writes:
Hi all,

Someone has links to examples of operator overloading in D? I read the
specification, but I was not able to understand it correctly.

I noticed that D doesn't have the operator keyword. I think that this 
keyword gives more flexibility and power than the simple use of functions
(opCmp, opEquals etc). IMHO, it should be added in D.

Thanks,

Bruno.
Apr 27 2004
next sibling parent reply J C Calvarese <jcc7 cox.net> writes:
In article <c6lp1a$1k3i$1 digitaldaemon.com>, Bruno A. Costa says...
Hi all,

Someone has links to examples of operator overloading in D? I read the
specification, but I was not able to understand it correctly.
http://www.dsource.org/tutorials/index.php?show_example=43 Justin
I noticed that D doesn't have the operator keyword. I think that this 
keyword gives more flexibility and power than the simple use of functions
(opCmp, opEquals etc). IMHO, it should be added in D.

Thanks,

Bruno.
Apr 27 2004
parent reply "Bruno A. Costa" <bruno codata.com.br> writes:
J C Calvarese wrote:

 In article <c6lp1a$1k3i$1 digitaldaemon.com>, Bruno A. Costa says...

There is an opAssign function, to overload the operator '=' ?
Hi all,

Someone has links to examples of operator overloading in D? I read the
specification, but I was not able to understand it correctly.
http://www.dsource.org/tutorials/index.php?show_example=43 Justin
I noticed that D doesn't have the operator keyword. I think that this
keyword gives more flexibility and power than the simple use of functions
(opCmp, opEquals etc). IMHO, it should be added in D.

Thanks,

Bruno.
Apr 27 2004
parent Chris Lawson <cl mangler.tinfoilhat.ca> writes:
Bruno A. Costa wrote:
 J C Calvarese wrote:
 
 
In article <c6lp1a$1k3i$1 digitaldaemon.com>, Bruno A. Costa says...
There is an opAssign function, to overload the operator '=' ?
No. It was decided (rightly, I think) that the semantics of the '=' operator on classes are ambiguous, so you have to explicitly copy your class with a method. Chris
 
 
 
Hi all,

Someone has links to examples of operator overloading in D? I read the
specification, but I was not able to understand it correctly.
http://www.dsource.org/tutorials/index.php?show_example=43 Justin
I noticed that D doesn't have the operator keyword. I think that this
keyword gives more flexibility and power than the simple use of functions
(opCmp, opEquals etc). IMHO, it should be added in D.

Thanks,

Bruno.
Apr 27 2004
prev sibling parent reply FlyTox <rox271 hotmail.com> writes:
I have to confess I do not understand what was wrong with the C++ 
syntax. I find it oakward to type "opAddAssign" rather than "+=". 
Eventually the compiler calls opAddAsign when it reaches +=; what is the 
benefit of such a name discrepancy?

Sorry I may not get the point but as far as I understand, this D 
operator replacement achieves exactly the same as C++. Why changing 
things when there is no additional benefit? Just to give D an identity?

Bruno A. Costa wrote:

 Hi all,
 
 Someone has links to examples of operator overloading in D? I read the
 specification, but I was not able to understand it correctly.
 
 I noticed that D doesn't have the operator keyword. I think that this 
 keyword gives more flexibility and power than the simple use of functions
 (opCmp, opEquals etc). IMHO, it should be added in D.
 
 Thanks,
 
 Bruno.
 
 
Apr 27 2004
parent reply J Anderson <REMOVEanderson badmama.com.au> writes:
FlyTox wrote:

 I have to confess I do not understand what was wrong with the C++ 
 syntax. I find it oakward to type "opAddAssign" rather than "+=". 
 Eventually the compiler calls opAddAsign when it reaches +=; what is 
 the benefit of such a name discrepancy?

 Sorry I may not get the point but as far as I understand, this D 
 operator replacement achieves exactly the same as C++. Why changing 
 things when there is no additional benefit? Just to give D an identity?
Rather then having to write some 24 overloads, in D you only need to write 8 to archive the same thing. Something like that anyway. -- -Anderson: http://badmama.com.au/~anderson/
Apr 27 2004
parent reply "Bruno A. Costa" <bruno codata.com.br> writes:
J Anderson wrote:

 FlyTox wrote:
 
 I have to confess I do not understand what was wrong with the C++
 syntax. I find it oakward to type "opAddAssign" rather than "+=".
 Eventually the compiler calls opAddAsign when it reaches +=; what is
 the benefit of such a name discrepancy?

 Sorry I may not get the point but as far as I understand, this D
 operator replacement achieves exactly the same as C++. Why changing
 things when there is no additional benefit? Just to give D an identity?
Rather then having to write some 24 overloads, in D you only need to write 8 to archive the same thing. Something like that anyway.
As I spoke before, this has pros and cons. This facilitates the programming, but removes a little of the flexibility (and elegance, I think) of the language. But it is just my opinion, as a C++ fanatic :) Cheers, Bruno
Apr 28 2004
next sibling parent J Anderson <REMOVEanderson badmama.com.au> writes:
Bruno A. Costa wrote:

As I spoke before, this has pros and cons. This facilitates the programming,
but removes a little of the flexibility (and elegance, I think) of the
language. But it is just my opinion, as a C++ fanatic :)

Cheers,

Bruno
  
Yeah, it's just a C++ withdrawal symptom that a lot of people in the group seem to get. -- -Anderson: http://badmama.com.au/~anderson/
Apr 28 2004
prev sibling parent "Walter" <newshound digitalmars.com> writes:
"Bruno A. Costa" <bruno codata.com.br> wrote in message
news:c6o7ba$2noi$1 digitaldaemon.com...
 As I spoke before, this has pros and cons. This facilitates the
programming,
 but removes a little of the flexibility (and elegance, I think) of the
 language. But it is just my opinion, as a C++ fanatic :)
Actually, giving the operator overloading a name gives it more flexibility, greppability, and elegance. For a small example, consider ++ as a preincrement and a postincrement operator. For a more significant example, how would one do a generalized compare function that will work for <, <=, >= and > of one were restricted to using the various comparison symbols?
Apr 30 2004