digitalmars.D.learn - can't I use __traits(allMembers) recursivly ?
- Uplink_Coder (16/16) Jan 23 2014 When I try to
- Tobias Pankrath (8/24) Jan 23 2014 __traits(getMember, Pod, member) is the same as Pod.member. In
- Uplink_Coder (1/1) Jan 23 2014 I'm trying to serialize my struct through CT-Refelction
- Jacob Carlborg (6/7) Jan 23 2014 Here's a serialization library if you need it [1]. It will hopefully be...
- Uplink_Coder (6/6) Jan 24 2014 Orange is neat
- Tobias Pankrath (6/7) Jan 24 2014 Maybe your _pod_ functions needs a parameter.
- Tobias Pankrath (5/12) Jan 24 2014 Oops, that was not finished. __traits(getMember, pod, member)
- Uplink_Coder (2/2) Jan 24 2014 I have solved by problem.
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
Jan 23 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?
Jan 23 2014
I'm trying to serialize my struct through CT-Refelction
Jan 23 2014
On 2014-01-24 07:11, Uplink_Coder wrote:I'm trying to serialize my struct through CT-RefelctionHere's a serialization library if you need it [1]. It will hopefully be included as std.serialization in Phobos at some point. https://github.com/jacob-carlborg/orange -- /Jacob Carlborg
Jan 23 2014
Orange is neat I had a look at but, the docs are abit lacking ... I don't really know how to get it to do what i want Well I have an Enum in a Struct and I need to serialze the struct members and "unfold" the enum. can orange do that ?
Jan 24 2014
On Friday, 24 January 2014 at 06:11:30 UTC, Uplink_Coder wrote:I'm trying to serialize my struct through CT-RefelctionMaybe your _pod_ functions needs a parameter. // take a look at std.conv.to string toString(P)(P pod) { }
Jan 24 2014
On Friday, 24 January 2014 at 09:14:31 UTC, Tobias Pankrath wrote:On Friday, 24 January 2014 at 06:11:30 UTC, Uplink_Coder wrote:Oops, that was not finished. __traits(getMember, pod, member) could now be used. But you'll need to check if member really is a field. So it's easier to iterate over std.traits.FieldTypeTuple directly.I'm trying to serialize my struct through CT-RefelctionMaybe your _pod_ functions needs a parameter. // take a look at std.conv.to string toString(P)(P pod) { }
Jan 24 2014
I have solved by problem. I just forgot to prepend static to the ifs I used :D
Jan 24 2014