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

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Thu Oct 14 02:57:36 UTC 2021


On 10/13/21 4:41 PM, Paul Backus wrote:
> On Wednesday, 13 October 2021 at 19:18:55 UTC, Andrei Alexandrescu wrote:
>> The point is that with keeps the entire expression live, even if you 
>> only care about a part of it:
>>
>> struct S { int x; ... }
>>
>> with (auto y = S().x)
>> {
>>    ...
>> }
>>
>> In this case the S() temporary will be destroyed only at the end of 
>> with's scope.
> 
> Not a fan. It uses the same syntax as `if (auto y = S().x)` but has 
> subtly different semantics, in a way that's likely to go unnoticed in 
> common usage.

Yah, good point. Prolly it would be good to find a reasonable way to 
extend the lifetime of the temporary in a more general case.



More information about the Digitalmars-d mailing list