mirror of
https://github.com/dlang/phobos.git
synced 2025-04-29 14:40:30 +03:00
std.traits.hasMember: just forward to __traits(hasMember, ...)
This way opDispatch'ed members are recognized. Fixes issue 14605 - RefAppender fails isOutputRange.
This commit is contained in:
parent
984b7343a8
commit
dd2161705a
2 changed files with 16 additions and 13 deletions
|
@ -3573,6 +3573,12 @@ unittest
|
||||||
assert(app3.data == [1, 2, 3]);
|
assert(app3.data == [1, 2, 3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unittest // issue 14605
|
||||||
|
{
|
||||||
|
static assert(isOutputRange!(Appender!(int[]), int));
|
||||||
|
static assert(isOutputRange!(RefAppender!(int[]), int));
|
||||||
|
}
|
||||||
|
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
Appender!(int[]) app;
|
Appender!(int[]) app;
|
||||||
|
|
23
std/traits.d
23
std/traits.d
|
@ -3279,19 +3279,7 @@ alias Identity(alias A) = A;
|
||||||
Yields $(D true) if and only if $(D T) is an aggregate that defines
|
Yields $(D true) if and only if $(D T) is an aggregate that defines
|
||||||
a symbol called $(D name).
|
a symbol called $(D name).
|
||||||
*/
|
*/
|
||||||
template hasMember(T, string name)
|
enum hasMember(T, string name) = __traits(hasMember, T, 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
///
|
///
|
||||||
unittest
|
unittest
|
||||||
|
@ -3339,6 +3327,15 @@ unittest
|
||||||
static assert(hasMember!(R2!S, "T"));
|
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).
|
Retrieves the members of an enumerated type $(D enum E).
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue