with(auto x = ...)

Adam D. Ruppe via Digitalmars-d digitalmars-d at puremagic.com
Fri Jul 24 08:01:28 PDT 2015


On Friday, 24 July 2015 at 14:48:30 UTC, Marc Schütz wrote:
> But I fail to see the relation to named parameters?

You can make your parameters into a struct or tuple and fill them 
in with normal assignment. The with(auto) thing will conveniently 
limit the scope of the temporary argument object and give a bit 
of syntax sugar for it:

with(auto args = ParameterTypeTuple!foo) {
    argname = cool;
    argname2 = whatever;
    foo(args);
}


.....ironically, given the other thread about statements as 
expressions where i said 'meh', this is actually a decent case 
for them too, to get the return value of foo out of that scope 
while still allowing auto.

But that's a separate issue, the main point here is just that you 
can use it to prepare the arguments with a bit of sugar.


More information about the Digitalmars-d mailing list