can't I use __traits(allMembers) recursivly ?
Tobias Pankrath
tobias at pankrath.net
Thu Jan 23 16:24:24 PST 2014
On Thursday, 23 January 2014 at 23:42:26 UTC, Uplink_Coder wrote:
> When I try to
>
> struct _pod_ {
> string s1;
> enum e1 { v1,v2 };
> }
>
> auto printPod(Pod)() if (__traits(isPOD,Pod)) {
> string result;
> foreach (member;__traits(allMembers,Pod) ) {
> auto _member=__traits(getMember,Pod,member);
> }
> writeln(result);
> }
> void main() {printPod!(_pod_);}
>
> I get
> Error: need 'this' for 's1' of type 'string'
> Error: type e1 has no value
__traits(getMember, Pod, member) is the same as Pod.member. In
your case Pod is _pod_, so in the end you are trying to access an
non-static member via the struct type. That cannot work and the
error message tells you exactly that in errorspeak.
Since you are never appending to result your code has some more
flaws and I'm not sure what you are trying to do? Do you try to
mirror std.conv.to!string?
More information about the Digitalmars-d-learn
mailing list