Skip to content

Commit

Permalink
std.traits.hasMember: just forward to __traits(hasMember, ...)
Browse files Browse the repository at this point in the history
This way opDispatch'ed members are recognized.

Fixes issue 14605 - RefAppender fails isOutputRange.
  • Loading branch information
aG0aep6G committed Jul 16, 2015
1 parent 984b734 commit dd21617
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
6 changes: 6 additions & 0 deletions std/array.d
Original file line number Diff line number Diff line change
Expand Up @@ -3573,6 +3573,12 @@ unittest
assert(app3.data == [1, 2, 3]);
}

unittest // issue 14605
{
static assert(isOutputRange!(Appender!(int[]), int));
static assert(isOutputRange!(RefAppender!(int[]), int));
}

unittest
{
Appender!(int[]) app;
Expand Down
23 changes: 10 additions & 13 deletions std/traits.d
Original file line number Diff line number Diff line change
Expand Up @@ -3279,19 +3279,7 @@ alias Identity(alias A) = A;
Yields $(D true) if and only if $(D T) is an aggregate that defines
a symbol called $(D name).
*/
template hasMember(T, string name)
{
static if (is(T == struct) || is(T == class) || is(T == union) || is(T == interface))
{
enum bool hasMember =
staticIndexOf!(name, __traits(allMembers, T)) != -1 ||
__traits(compiles, { mixin("alias Sym = Identity!(T."~name~");"); });
}
else
{
enum bool hasMember = false;
}
}
enum hasMember(T, string name) = __traits(hasMember, T, name);

///
unittest
Expand Down Expand Up @@ -3339,6 +3327,15 @@ unittest
static assert(hasMember!(R2!S, "T"));
}

unittest
{
static struct S
{
void opDispatch(string n, A)(A dummy) {}
}
static assert(hasMember!(S, "foo"));
}

/**
Retrieves the members of an enumerated type $(D enum E).
Expand Down

0 comments on commit dd21617

Please sign in to comment.