Replacing the comma operator (was: The empty statement ";" - when is it useful?)

Stewart Gordon smjg_1998 at yahoo.com
Tue Jul 28 14:46:27 PDT 2009


Jarrett Billingsley wrote:
>  Tue, Jul 28, 2009 at 2:28 PM, Arthur Lloyd<via at google.com> wrote:
>> Daniel Keep Wrote:
>>
>>> U comma(T,U)(T a, U b) { return b; }
>>>
>>> Is there any reason you couldn't use something like that?
>> Sorry, this is probably a newbie question, but.. So instead of return a, b, c; you now have to write return comma(a, comma(b, c)); ? How will that help?
>>
> 
> typeof(T[$ - 1]) comma(T...)(T args) { return args[$ - 1]; }
> 
> There.  Now you can do "comma(a, b, c)".

Still won't solve the problem Andrei rightly pointed out.  But this will:

T[$-1] comma(T...)(lazy T args) {
     foreach (a; args[0..$-1]) cast(void) a;
     return args[$-1];
}

Stewart.



More information about the Digitalmars-d mailing list