Multiple return values...

Manu turkeyman at gmail.com
Thu Mar 15 09:30:01 PDT 2012


On 15 March 2012 17:32, Andrei Alexandrescu
<SeeWebsiteForEmail at erdani.org>wrote:

> On 3/15/12 5:14 AM, Iain Buclaw wrote:
>
>> On 15 March 2012 09:52, Derek<ddparnell at 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).


It all still feels to me like a generally ugly hack around the original
example:
  a,b = b,a;

What is the significant importance of the existing coma operator? What does
it offer that couldn't possibly be achieved any other way?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20120315/02914e38/attachment.html>


More information about the Digitalmars-d mailing list