typecons.Option: Fix assigning nothing

This commit is contained in:
Eugen Wissner 2019-01-29 08:24:58 +01:00
parent 4566cf7857
commit 410b865df9

View File

@ -367,8 +367,15 @@ struct Option(T)
ref typeof(this) opAssign(U)(ref U that)
if (is(U == Option))
{
this.value = that;
this.isNothing_ = that.isNothing;
if (that.isNothing)
{
reset();
}
else
{
this.value = that.get;
this.isNothing_ = false;
}
return this;
}
@ -515,6 +522,15 @@ struct Option(T)
assert(OptionT(Hashable(1U)).toHash() == 1U);
}
// Can assign Option that is nothing
@nogc nothrow pure @safe unittest
{
auto option1 = Option!int(5);
Option!int option2;
option1 = option2;
assert(option1.isNothing);
}
/**
* Creates a new $(D_PSYMBOL Option).
*