with(auto x = ...)

Idan Arye via Digitalmars-d digitalmars-d at puremagic.com
Sun Jul 26 04:04:12 PDT 2015


On Sunday, 26 July 2015 at 07:28:45 UTC, Kapps wrote:
> On Friday, 24 July 2015 at 15:01:29 UTC, Adam D. Ruppe wrote:
>> [...]
>
> The with statement is one where I think it would be interesting 
> to make it an expression.
>
> For named parameters (admittedly, I find this one a bit ugly):
> foo(with(ParameterTypeTuple!foo) {
>     abc = 2,
>     def = 3
> });
>
> Or just:
> auto args = with(ParameterTypeTuple!foo) {
>     abc = 2,
>     def = 3
> };
> foo(args);
>
>
> For initialization:
> auto a = with(new FooBar()) {
>     name = "Foo",
>     bar = 3
> };
>
> Or:
> with(new Thread(&foo) {
>     isDaemon = true
> }).start();

Sadly it'll break all the code that currently use it, since we'll 
now need to terminate it with a semicolon.


More information about the Digitalmars-d mailing list