A couple of extensions to `with` that would be worthwhile

Basile B. b2.temp at gmx.com
Wed Oct 13 13:16:36 UTC 2021


On Wednesday, 13 October 2021 at 13:05:06 UTC, Adam D Ruppe wrote:
> On Wednesday, 13 October 2021 at 11:13:32 UTC, Andrei [...]
>> with (auto xpath = extendPath(name).str) {
>>     // the only name injected here is xpath
>>     // assume str has type wstring, then xpath
>>     // also has type string
>> }
>
> What's the difference between this and `if(auto xpath = ...)` ? 
> It wouldn't be null anyway.
>
> Or between it and
>
> {
>   auto xpath = ....;
>   // stuff
> }
>
> ?

I think that the point of proposal 1 is to have something like, 
after lowering to common AST constructs:

```d
{
   {
     auto xpath = ....;
     scope (exit) destroy(xpath)
     // stuff
   }
   // destroy(xpath) really happens here
}
```


More information about the Digitalmars-d mailing list