On 3/15/12 5:14 AM, Iain Buclaw wrote:
On 15 March 2012 09:52, Derek<ddparn...@bigpond.com>  wrote:
Are you saying that the generated code is something like ...

   struct __tmpS { int Fa, int Fb };
   __tempS __tmp;
   __tmp.Fa = a;
   __tmp.Fb = b;
   a = __tmp.Fb;
   b = __tmp.Fa;


In effect, yes.  Given that the call to from() is inlined. :-)

In GDC, you have a -fdump-tree-original switch that dumps a debug
representation (that just so happens to look C-like) of the AST of the
code to a file.  You could use this to unravel some of the magic going
on under the covers. ;-)

One note - the code is really ingenious, but I still prefer swap() in this case. It's more concise and does less work in the general case.

swap(a[i + k], a[j + j]);

only computes the indexing once (in source, too).


Andrei

Reply via email to