Skip to content

Commit

Permalink
Fix std.traits.hasElaborateCopyConstructor static arrays issue and …
Browse files Browse the repository at this point in the history
…improve unittests

* the issue is that static arrays can also have elaborate copy constructors
* unittests are merged from `hasElaborateDestructor` ones
  • Loading branch information
denis-sh committed Oct 31, 2012
1 parent 579a346 commit 60a1e79
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions std/traits.d
Expand Up @@ -2358,32 +2358,42 @@ unittest
*/
template hasElaborateCopyConstructor(S)
{
static if(!is(S == struct))
static if(isStaticArray!S && S.length)
{
enum bool hasElaborateCopyConstructor = false;
enum bool hasElaborateCopyConstructor = hasElaborateCopyConstructor!(typeof(S[0]));
}
else
else static if(is(S == struct))
{
enum hasElaborateCopyConstructor = hasMember!(S, "__postblit")
|| anySatisfy!(.hasElaborateCopyConstructor, typeof(S.tupleof));
}
else
{
enum bool hasElaborateCopyConstructor = false;
}
}

unittest
{
static assert(!hasElaborateCopyConstructor!int);

struct S1 { this(this) {} }
static assert( hasElaborateCopyConstructor!S1);
static assert( hasElaborateCopyConstructor!(immutable(S1)));

struct S2 { uint num; }
struct S3 { uint num; S1 s; }
static assert(!hasElaborateCopyConstructor!S2);
static struct S1 { }
static struct S2 { this(this) {} }
static struct S3 { S2 field; }
static struct S4 { S3[1] field; }
static struct S5 { S3[] field; }
static struct S6 { S3[0] field; }
static struct S7 { @disable this(); S3 field; }
static assert(!hasElaborateCopyConstructor!S1);
static assert( hasElaborateCopyConstructor!S2);
static assert( hasElaborateCopyConstructor!(immutable S2));
static assert( hasElaborateCopyConstructor!S3);

struct S4 { @disable this(); this(int n){} this(this){} }
static assert( hasElaborateCopyConstructor!(S3[1]));
static assert(!hasElaborateCopyConstructor!(S3[0]));
static assert( hasElaborateCopyConstructor!S4);
static assert(!hasElaborateCopyConstructor!S5);
static assert(!hasElaborateCopyConstructor!S6);
static assert( hasElaborateCopyConstructor!S7);
}

/**
Expand Down

0 comments on commit 60a1e79

Please sign in to comment.