Having problems using __traits
bearophile
bearophileHUGS at lycos.com
Sat Apr 3 11:16:42 PDT 2010
Daniel Ribeiro Maciel:
> Hello! I'm currently having this issue using __traits. Can anyone tell me what am I doing wrong, or whether this is a compiler bug or not?<
At the moment DMD2 has holes likes Swiss cheese. You have hit one, two, or more than two different bugs. This is the first bug:
struct Test {
void hello() {}
}
void main() {
Test t;
string m = "hello";
__traits(getMember, t, m)();
}
The error message is wrong: if m must be an enum/immutable string, then the error message has to say so.
The second problem can be seen here:
import std.c.stdio: puts;
class Test {
void hello() {
puts("hello!");
}
}
void methodHandler(T, alias member)() {
auto o = new T();
__traits(getMember, o, member)();
}
void main() {
auto methods = __traits(allMembers, Test);
foreach (method; methods)
if (method == "hello")
methodHandler!(Test, "hello")();
}
If you replace "hello" inside methodHandler!(Test, "hello")(); with method, the program doesn't compile. I don't know if it's the same problem as before.
I can put in bugzilla the first bug.
Bye,
bearophile
More information about the Digitalmars-d
mailing list