How to initialize immutable variables with an expression that throws an exception to catch?
Steven Schveighoffer
schveiguy at gmail.com
Fri Apr 3 14:12:22 UTC 2020
On 4/3/20 9:14 AM, FeepingCreature wrote:
> On Friday, 3 April 2020 at 12:49:27 UTC, Steven Schveighoffer wrote:
>> Do it the old-fashioned way -- use casting ;)
>>
>> S s_val = void;
>> try
>> s_val = fun();
>> catch (Exception)
>> return;
>>
>> immutable s = s_val.assumeUnique;
>> call(s);
>>
>
> Doesn't work - `immutable struct` means S is always immutable.
totally misread your statement as making s immutable, not S.
I don't know how to solve that problem correctly.
-Steve
More information about the Digitalmars-d
mailing list