so in what you suggest, the exact same problem remains with 'get' being exposed instead of 'x', so the situation didn't improve...<div><br></div><div>looks like it's impossible to achieve this?<br><div>
<br></div><div><div><div><br></div><div><div class="gmail_quote">On Fri, May 17, 2013 at 4:24 PM, Simen Kjaeraas <span dir="ltr"><<a href="mailto:simen.kjaras@gmail.com" target="_blank">simen.kjaras@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Sat, 18 May 2013 01:13:00 +0200, Timothee Cour <<a href="mailto:thelastmammoth@gmail.com" target="_blank">thelastmammoth@gmail.com</a>> wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
How to have alias this with an unaccessible member (x below).<br>
Making the member private won't work as it'll disable all operations on<br>
said member.<br>
<br>
----<br>
struct A(T){<br>
T x;<br>
//private T x would prevent alias this from doing anything useful<br>
alias x this;<br>
}<br>
void main(){<br>
auto a=A!int;<br>
a++;//should do a.x++;<br>
static assert(!__traits(compiles,a.x)<u></u>); // I want this to hold<br>
<br>
}<br>
----<br>
</blockquote>
<br>
<br></div></div>
The common way to do it is with a read-only property:<br>
<br>
struct A(T) {<br>
private T x;<br>
<br>
@property<br>
T get() {<br>
return x;<br>
}<br>
<br>
alias get this;<br>
}<br>
<br>
void main(){<br>
auto a = A!int;<br>
a++; //should do a.x++;<br>
static assert(!__traits(compiles, a.x)); // This now holds!<br>
static assert(__traits(compiles, a.get)); // As does this, which may or may not be palatable. :(<br>
}<br>
<br>
This has been discussed numerous times before, but I believe the current behavior is here to stay.<span class="HOEnZb"><font color="#888888"><br>
<br>
-- <br>
Simen<br>
</font></span></blockquote></div><br></div></div></div></div>