mirror of
https://github.com/dlang/phobos.git
synced 2025-04-28 22:21:09 +03:00
Work around issue 22619 - Avoid Nullable copy ctor unless required
Copy ctors are still buggy, so unconditionally adding one for Nullable is everything but a non-breaking change (and was added in the 2.098.1 point release).
This commit is contained in:
parent
a5c467d836
commit
9db3a9afdf
1 changed files with 34 additions and 8 deletions
|
@ -2792,7 +2792,17 @@ struct Nullable(T)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this (ref return scope inout Nullable!T rhs) inout
|
static if (__traits(hasPostblit, T))
|
||||||
|
{
|
||||||
|
this(this)
|
||||||
|
{
|
||||||
|
if (!_isNull)
|
||||||
|
_value.payload.__xpostblit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else static if (__traits(hasCopyConstructor, T))
|
||||||
|
{
|
||||||
|
this(ref return scope inout Nullable!T rhs) inout
|
||||||
{
|
{
|
||||||
_isNull = rhs._isNull;
|
_isNull = rhs._isNull;
|
||||||
if (!_isNull)
|
if (!_isNull)
|
||||||
|
@ -2800,6 +2810,7 @@ struct Nullable(T)
|
||||||
else
|
else
|
||||||
_value = DontCallDestructorT.init;
|
_value = DontCallDestructorT.init;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If they are both null, then they are equal. If one is null and the other
|
* If they are both null, then they are equal. If one is null and the other
|
||||||
|
@ -9546,13 +9557,28 @@ unittest
|
||||||
{
|
{
|
||||||
int b;
|
int b;
|
||||||
@disable this(this);
|
@disable this(this);
|
||||||
this (ref return scope inout S rhs) inout
|
this(ref return scope inout S rhs) inout
|
||||||
{
|
{
|
||||||
this.b = rhs.b + 1;
|
this.b = rhs.b + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Nullable!S s1 = S(1);
|
Nullable!S s1 = S(1);
|
||||||
|
assert(s1.get().b == 2);
|
||||||
Nullable!S s2 = s1;
|
Nullable!S s2 = s1;
|
||||||
assert(s2.get().b > s1.get().b);
|
assert(s2.get().b == 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
@safe unittest
|
||||||
|
{
|
||||||
|
static struct S
|
||||||
|
{
|
||||||
|
int b;
|
||||||
|
this(this) { ++b; }
|
||||||
|
}
|
||||||
|
|
||||||
|
Nullable!S s1 = S(1);
|
||||||
|
assert(s1.get().b == 2);
|
||||||
|
Nullable!S s2 = s1;
|
||||||
|
assert(s2.get().b == 3);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue