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).<div><br></div><div>However what about changing the behavior of alias this as follows:</div>
<div><br></div><div>when a member/method x is private, "alias x this" behaves as if x was not declared private.</div><div><br></div><div>I think this makes sense: </div><div>* this allows protection (x is an implementation detail) so that 'this' behaves exactly as 'x'</div>
<div>* 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)</div><div><br></div><div>Then, when multiple alias this statements will become allowed in D, we would have implemented the same concept as "embedding" in GO.</div>
<div><br></div><div>Any thoughts?</div><div><br></div><div><br></div><div>here's what we would have:</div><div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
----</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">struct A(T){</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
private T x would prevent alias this from doing anything useful</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"> alias x this; </div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
}</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">void main(){</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
auto a=A!int;</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"> a++;//should do a.x++; //semantic change: even though x is private, all its methods are un-privated through alias this.</div>
<div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"> static assert(!__traits(compiles,a.x)); </div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
}</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">----</div></div><div><br></div><div><br></div><div><br><br><div class="gmail_quote">On Sat, May 18, 2013 at 1:33 AM, Dicebot <span dir="ltr"><<a href="mailto:m.strashun@gmail.com" target="_blank">m.strashun@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Will this do?<br>
<br>
--------------------<div class="im"><br>
<br>
struct A(T)<br>
{<br>
private T x;<br>
<br></div>
ref T get()<div class="im"><br>
{<br>
return x;<br>
}<br>
<br>
alias get this;<br>
}<br>
<br></div>
---------------------<br>
</blockquote></div><br></div>