Thread overview
Operator overloading
Apr 27, 2004
Bruno A. Costa
Apr 27, 2004
J C Calvarese
Apr 27, 2004
Bruno A. Costa
Apr 27, 2004
Chris Lawson
Apr 27, 2004
FlyTox
Apr 28, 2004
J Anderson
Apr 28, 2004
Bruno A. Costa
Apr 28, 2004
J Anderson
Apr 30, 2004
Walter
April 27, 2004
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.


April 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

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.


April 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
> 
> 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.

April 27, 2004
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.
> 
> 
April 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.
> 
> 

April 28, 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/
April 28, 2004
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
April 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,
>
>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/
April 30, 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 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?