T.init, struct destructors and invariants - should they be called?
Stanislav Blinov
stanislav.blinov at gmail.com
Sun Nov 18 15:07:51 UTC 2018
On Sunday, 18 November 2018 at 14:47:51 UTC, FeepingCreature
wrote:
> On Sunday, 18 November 2018 at 14:38:09 UTC, Stanislav Blinov
> wrote:
>> @safe unittest {
>> Nullable!S a; // Look ma, no assert!
>> }
>
> a = S(new Object); // Look pa, assert!
...i.e. it should be:
// ...
@property @trusted
void value(T val) {
if (!_hasValue) {
import std.conv : emplace;
auto addr = () @trusted { return &_payload(); } ();
emplace(addr, val);
_hasValue = true;
} else
_payload = val;
}
// ...
since otherwise that calls opAssign. Unless you'd propose to not
call invariants for that one too :*)
More information about the Digitalmars-d
mailing list