Skip to content

Commit

Permalink
Fix for issue 3272
Browse files Browse the repository at this point in the history
  • Loading branch information
andralex committed Jan 24, 2011
1 parent c84f8a6 commit 81a4a40
Showing 1 changed file with 31 additions and 9 deletions.
40 changes: 31 additions & 9 deletions std/traits.d
Expand Up @@ -878,31 +878,49 @@ assert(R.length == 4
----
*/

template RepresentationTypeTuple(T...)
template RepresentationTypeTuple(T)
{
static if (is(T == struct) || is(T == union) || is(T == class))
{
alias RepresentationTypeTupleImpl!(FieldTypeTuple!T)
RepresentationTypeTuple;
}
else static if (is(T U == typedef))
{
alias RepresentationTypeTuple!U RepresentationTypeTuple;
}
else
{
alias RepresentationTypeTupleImpl!T
RepresentationTypeTuple;
}
}

private template RepresentationTypeTupleImpl(T...)
{
static if (T.length == 0)
{
alias TypeTuple!() RepresentationTypeTuple;
alias TypeTuple!() RepresentationTypeTupleImpl;
}
else
{
static if (is(T[0] == struct) || is(T[0] == union))
// @@@BUG@@@ this should work
// alias .RepresentationTypes!(T[0].tupleof)
// RepresentationTypes;
alias .RepresentationTypeTuple!(FieldTypeTuple!(T[0]),
alias .RepresentationTypeTupleImpl!(FieldTypeTuple!(T[0]),
T[1 .. $])
RepresentationTypeTuple;
RepresentationTypeTupleImpl;
else static if (is(T[0] U == typedef))
{
alias .RepresentationTypeTuple!(FieldTypeTuple!(U),
alias .RepresentationTypeTupleImpl!(FieldTypeTuple!(U),
T[1 .. $])
RepresentationTypeTuple;
RepresentationTypeTupleImpl;
}
else
{
alias TypeTuple!(T[0], RepresentationTypeTuple!(T[1 .. $]))
RepresentationTypeTuple;
alias TypeTuple!(T[0], RepresentationTypeTupleImpl!(T[1 .. $]))
RepresentationTypeTupleImpl;
}
}
}
Expand All @@ -925,6 +943,10 @@ unittest
assert(R.length == 4
&& is(R[0] == char[]) && is(R[1] == int)
&& is(R[2] == float) && is(R[3] == S11*));

class C { int a; float b; }
alias RepresentationTypeTuple!C R1;
static assert(R1.length == 2 && is(R1[0] == int) && is(R1[1] == float));
}

/*
Expand Down Expand Up @@ -1057,7 +1079,7 @@ static assert(hasRawAliasing!(S4));
private template hasRawAliasing(T...)
{
enum hasRawAliasing
= hasRawPointerImpl!(RepresentationTypeTuple!(T)).result;
= hasRawPointerImpl!(RepresentationTypeTuple!T).result;
}

unittest
Expand Down

0 comments on commit 81a4a40

Please sign in to comment.