<div class="gmail_quote">On 9 April 2012 03:21, Andrej Mitrovic <span dir="ltr"><<a href="mailto:andrej.mitrovich@gmail.com">andrej.mitrovich@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On 4/9/12, Andrei Alexandrescu <<a href="mailto:SeeWebsiteForEmail@erdani.org">SeeWebsiteForEmail@erdani.org</a>> wrote:<br>
> and pass-by-alias<br>
<br>
Speaking of alias, one killer feature would be to enable using alias<br>
for expressions. E.g.:<br>
<br>
struct Window { struct Point { int x, y; } Point point; }<br>
void test() {<br>
    Window window;<br>
    alias window.point.x x;<br>
    // use 'x' here which is really window.point.x<br>
}<br>
<br>
It makes it simpler to manipulate nested structs and their fields by<br>
reference without involving pointers or using with statements. AFAIK<br>
C++ can use references for this purpose (ala &int x =<br>
window.point.x;), but I guess this isn't very efficient unless the<br>
compiler can optimize it.<br></blockquote><div><br></div><div>I can't think of many cases where the compiler can't optimise it when used in the context you describe.</div><div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Besides myself I've also seen other people request it (I think Nick S.<br>
wanted the feature).<br>
</blockquote></div><br><div>I probably wouldn't have thought to use alias in that way, I probably would have asked to be able to use 'ref' on any declaration...</div><div>I do also get a little annoyed having to use pointers in this situation. At least they don't suffer a different dereference syntax like C, but it does seem a bit flimsy that they can be reassigned, can also be null, and I have to involve the & operator, which can often lead to parentheses spam.</div>
<div><br></div><div>(...why can't you use 'ref' in regular declarations? I frequently find myself wanting to use ref locally for this exact reason.)</div>