Truly algebraic Variant and Nullable
9il
ilyayaroshenko at gmail.com
Tue Dec 22 16:32:20 UTC 2020
On Tuesday, 22 December 2020 at 14:27:02 UTC, ag0aep6g wrote:
> On 22.12.20 04:56, 9il wrote:
>> 6. Algebraic type subsets are supported by `get`,
>> `trustedGet`, `_is`, and `this` primitives. You can operate
>> with algebraic subset as with the type of the original
>> typeset. [1]
>
> "trustedGet" - That name smells of a safety violation. And
> indeed (compile with `-release`):
> The normal `get` also violates safety by giving out references
> into the union (compile with `-preview=dip1000`):
> But that might be an issue with DIP1000. `ref_to_ptr` is a hint
> that something isn't right in that area.
The definitions are
```
auto ref get(E)() @property return inout
auto ref trustedGet(E)() @trusted @property return inout nothrow
```
Both market with `return`.
According to the spec [1, example 2]
"Struct non-static methods marked with the return attribute
ensure the returned reference will not outlive the struct
instance."
The docs maybe not clear enough. `trustedGet` asserts type is
matched, while `get` throws an exception if the type doesn't
match.
[1] https://dlang.org/spec/function.html#return-ref-parameters
More information about the Digitalmars-d-announce
mailing list