digitalmars.D - Operator overloading
- Bruno A. Costa (8/8) Apr 27 2004 Hi all,
- J C Calvarese (3/11) Apr 27 2004 http://www.dsource.org/tutorials/index.php?show_example=43
- Bruno A. Costa (2/21) Apr 27 2004
- Chris Lawson (5/33) Apr 27 2004 No. It was decided (rightly, I think) that the semantics of the '='
- FlyTox (8/22) Apr 27 2004 I have to confess I do not understand what was wrong with the C++
- J Anderson (5/12) Apr 27 2004 Rather then having to write some 24 overloads, in D you only need to
- Bruno A. Costa (6/20) Apr 28 2004 As I spoke before, this has pros and cons. This facilitates the programm...
- J Anderson (5/11) Apr 28 2004 Yeah, it's just a C++ withdrawal symptom that a lot of people in the
- Walter (8/11) Apr 30 2004 programming,
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
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 JustinI 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
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 JustinI 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
Bruno A. Costa wrote:J C Calvarese wrote: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. ChrisIn 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 JustinI 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
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
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
J Anderson wrote:FlyTox 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, BrunoI 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.
Apr 28 2004
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, BrunoYeah, 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
"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 theprogramming,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