This won't do for the same reason: now 'get' is made public so we're back to the same problem (inverting roles of x and get).

However what about changing the behavior of alias this as follows:

when a member/method x is private, "alias x this" behaves as if x was not declared private.

I think this makes sense: 
* this allows protection (x is an implementation detail) so that 'this' behaves exactly as 'x'
* also, without this change of behavior, "alias x this" would not make any sense in terms of behavior outside the class (inside behavior should just access x directly)

Then, when multiple alias this statements will become allowed in D, we would have implemented the same concept as "embedding" in GO.

Any thoughts?


here's what we would have:
----
struct A(T){
  private T x would prevent alias this from doing anything useful
  alias x this; 
}
void main(){
  auto a=A!int;
  a++;//should do a.x++; //semantic change: even though x is private, all its methods are un-privated through alias this.
  static assert(!__traits(compiles,a.x)); 
}
----




On Sat, May 18, 2013 at 1:33 AM, Dicebot <m.strashun@gmail.com> wrote:
Will this do?

--------------------


struct A(T)
{
    private T x;

    ref T get()

    {
        return x;
    }

    alias get this;
}

---------------------