Truly algebraic Variant and Nullable

9il ilyayaroshenko at gmail.com
Tue Dec 22 16:54:56 UTC 2020


On Tuesday, 22 December 2020 at 16:43:30 UTC, ag0aep6g wrote:
> On Tuesday, 22 December 2020 at 16:32:20 UTC, 9il wrote:
>> "Struct non-static methods marked with the return attribute 
>> ensure the returned reference will not outlive the struct 
>> instance."
>
> The issue isn't that the reference outlives the struct. It's 
> that the reference outlives a tag change of the tagged union.

If I am correct Dlang doesn't provide an instrument to validate 
it, isn't it?

What alternative is possible?

Returning it by value isn't acceptable at least because of 
performance reasons: the first target of the library is struts 
with a lot of Mir ref-counted fields.

>> The docs maybe not clear enough. `trustedGet` asserts type is 
>> matched, while `get` throws an exception if the type doesn't 
>> match.
>
> You can't rely on an assert for @safe (unless it's 
> `assert(false);`).

This is why it is the market as `trusted`. It is much more 
convenient than forcing users to wrap each access with @trusted 
lambda, which feels like masochism.



More information about the Digitalmars-d-announce mailing list