Thread overview
Signature of opAddAssign
Mar 03, 2005
Andrew Fedoniouk
Mar 03, 2005
zwang
Mar 03, 2005
Andrew Fedoniouk
Mar 03, 2005
Andrew Fedoniouk
March 03, 2005
what is the proper way from D point of view?

struct point
{
   point opAddAssign(int i) {  x += i; y += i; return make(x,y);  }
   // --or just --
   void  opAddAssign(int i) {  x += i; y += i; }
}

( I am porting this into D
http://www.terrainformatica.com/org/gool/geometry.h )

Andrew.


March 03, 2005
Andrew Fedoniouk wrote:
> what is the proper way from D point of view?
> 
> struct point
> {
>    point opAddAssign(int i) {  x += i; y += i; return make(x,y);  }
>    // --or just --
>    void  opAddAssign(int i) {  x += i; y += i; }
> }
> 
> ( I am porting this into D
> http://www.terrainformatica.com/org/gool/geometry.h )
> 
> Andrew.
> 
> 

IMO, I prefer the former which enables chained += operations.
March 03, 2005
>> struct point
>> {
>>    point opAddAssign(int i) {  x += i; y += i; return make(x,y);  }
>>    // --or just --
>>    void  opAddAssign(int i) {  x += i; y += i; }
>> }
>>
>
> IMO, I prefer the former which enables chained += operations.

Seems like my question was not clear enough....

Question is about compiler -
what code it produces on a += b ?

Compiler may suppres returning value of opAddAssign
and make value by its own. And that is the question.

As far as I understand there are no 'this' in struct methods (why?) so I cannot effectively return something like *this from methods. Am I right?

Andrew.






March 03, 2005
Disregard my previous post.
this in struct's works. Just tested it.
Perfect.


"Andrew Fedoniouk" <news@terrainformatica.com> wrote in message news:d07d6n$1st$1@digitaldaemon.com...
>>> struct point
>>> {
>>>    point opAddAssign(int i) {  x += i; y += i; return make(x,y);  }
>>>    // --or just --
>>>    void  opAddAssign(int i) {  x += i; y += i; }
>>> }
>>>
>>
>> IMO, I prefer the former which enables chained += operations.
>
> Seems like my question was not clear enough....
>
> Question is about compiler -
> what code it produces on a += b ?
>
> Compiler may suppres returning value of opAddAssign
> and make value by its own. And that is the question.
>
> As far as I understand there are no 'this' in struct methods (why?) so I cannot effectively return something like *this from methods. Am I right?
>
> Andrew.
>
>
>
>
>
>