DIP66 v1.1 (Multiple) alias this.

Joseph Rushton Wakeling via Digitalmars-d digitalmars-d at puremagic.com
Sat Dec 20 15:14:31 PST 2014


On 02/11/14 15:55, IgorStepanov via Digitalmars-d wrote:
> http://wiki.dlang.org/DIP66
>
> I've applied some changes to it, however there are still some unresolved questions.

The current DIP doesn't address protection attributes.  I recognize this might 
be somewhat orthogonal, but it'd be nice to build it into the DIP if possible, 
just to be explicit about what is expected for how alias this should work.

According to TDPL the following should work:

     struct Foo
     {
         private T internal_;         // member variable is private

         public alias internal_ this; // .. but can be interacted with
                                      // via the public alias
     }

It seems to me an important factor, because it means that classes and structs 
can use subtyping without revealing the implementation details.  As things are, 
you wind up having to do something like,

     struct Integer
     {
         private int i_;

         public ref int getInteger() @property
         {
             return i_;
         }

         alias getInteger this;
     }

... which personally I find a bit of an unpleasant violation of the idea of a 
private implementation.

See also: https://issues.dlang.org/show_bug.cgi?id=10996


More information about the Digitalmars-d mailing list