mirror of
https://github.com/dlang/phobos.git
synced 2025-05-07 11:37:24 +03:00
Fix for issue 4942
This commit is contained in:
parent
4196a49db4
commit
3d865b35b6
2 changed files with 42 additions and 2 deletions
|
@ -2003,7 +2003,7 @@ Complexity: $(BIGOH log(n)).
|
|||
static if (is(T == struct))
|
||||
{
|
||||
// Destroy this guy
|
||||
clear(_data._payload[$ - 1]);
|
||||
.clear(_data._payload[$ - 1]);
|
||||
}
|
||||
_data._payload = _data._payload[0 .. $ - 1];
|
||||
}
|
||||
|
@ -2031,7 +2031,7 @@ Complexity: $(BIGOH howMany).
|
|||
// Destroy this guy
|
||||
foreach (ref e; _data._payload[$ - howMany .. $])
|
||||
{
|
||||
clear(e);
|
||||
.clear(e);
|
||||
}
|
||||
}
|
||||
_data._payload = _data._payload[0 .. $ - howMany];
|
||||
|
@ -4762,3 +4762,12 @@ unittest
|
|||
RedBlackTree!ubyte rt5;
|
||||
RedBlackTree!byte rt6;
|
||||
}
|
||||
|
||||
version(unittest) struct UnittestMe {
|
||||
int a;
|
||||
}
|
||||
|
||||
unittest
|
||||
{
|
||||
auto c = Array!UnittestMe();
|
||||
}
|
||||
|
|
31
std/traits.d
31
std/traits.d
|
@ -1451,6 +1451,37 @@ unittest
|
|||
static assert(hasElaborateAssign!S3);
|
||||
}
|
||||
|
||||
/**
|
||||
True if $(D S) or any type directly embedded in the representation
|
||||
of $(D S) defines an elaborate destructor. Elaborate destructors
|
||||
are introduced by defining $(D ~this()) for a $(D
|
||||
struct). (Non-struct types never have elaborate destructors, even
|
||||
though classes may define $(D ~this()).)
|
||||
*/
|
||||
template hasElaborateDestructor(S)
|
||||
{
|
||||
static if(!is(S == struct))
|
||||
{
|
||||
enum bool hasElaborateDestructor = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
enum hasElaborateDestructor = is(typeof({S s; return &s.__dtor;}))
|
||||
|| anySatisfy!(.hasElaborateDestructor, typeof(S.tupleof));
|
||||
}
|
||||
}
|
||||
|
||||
unittest
|
||||
{
|
||||
static assert(!hasElaborateDestructor!int);
|
||||
static struct S1 { }
|
||||
static assert(!hasElaborateDestructor!S1);
|
||||
static struct S2 { ~this() {} }
|
||||
static assert(hasElaborateDestructor!S2);
|
||||
static struct S3 { S2 field; }
|
||||
static assert(hasElaborateDestructor!S3);
|
||||
}
|
||||
|
||||
/**
|
||||
Yields $(D true) if and only if $(D T) is a $(D struct) or a $(D
|
||||
class) that defines a symbol called $(D name).
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue