Topic: proposal: self-methods


Author: danielgutson@hotmail.com (danielgutson@hotmail.com)
Date: Wed, 22 Jan 2003 21:21:55 +0000 (UTC)
Raw View
[addendum]

danielgutson@hotmail.com (danielgutson@hotmail.com) wrote in message news:<23478c42.0301210802.4a8efc92@posting.google.com>...
> Newsgroupers:
>   I'd like to propose a simplification for writing 'reflexive
> methods', such as operator +=.
>
> Usually,
>
> class C
> {
> ...
>    C& operator += (const C& other)
>    {
>       ...
>       return *this;
>    }
>  ...
> };
>
> I'm proposing a simplification (just notational) in which 'this' and

Sorry about this: it may be not just notational.
An open issue:
what about inheritance? I suggest that self-methods (virtual) should
still be self-methods in the derived classes. This is a concept and
also a readability improvement (when you only see the interface).

 Daniel.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: danielgutson@hotmail.com (danielgutson@hotmail.com)
Date: Tue, 21 Jan 2003 19:19:42 +0000 (UTC)
Raw View
Newsgroupers:
  I'd like to propose a simplification for writing 'reflexive
methods', such as operator +=.

Usually,

class C
{
...
   C& operator += (const C& other)
   {
      ...
      return *this;
   }
...
};

I'm proposing a simplification (just notational) in which 'this' and
'this&' are return type keywords, meaning that 'return' should have no
parameter, and is optional. The method would become:

this& operator += (const C& other)
{
   ...
   return;   //optional
}

So, my proposal states:
    - 'this' is available as a return type, pointer
    - 'this&' is available as a return type, reference
    - in the above cases, 'return' becomes optional inside the
'self-methods', and, when present, should not receive a parameter
(because this or *this is assumed, respectively).

Wouldn't this additionally simplify compiler optimization hints?

Listening feedbacks!

  Daniel.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]