Thread overview
can't I use __traits(allMembers) recursivly ?
Jan 23, 2014
Uplink_Coder
Jan 24, 2014
Tobias Pankrath
Jan 24, 2014
Uplink_Coder
Jan 24, 2014
Jacob Carlborg
Jan 24, 2014
Uplink_Coder
Jan 24, 2014
Tobias Pankrath
Jan 24, 2014
Tobias Pankrath
Jan 24, 2014
Uplink_Coder
January 23, 2014
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
January 24, 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?
January 24, 2014
I'm trying to serialize my struct through CT-Refelction
January 24, 2014
On 2014-01-24 07:11, Uplink_Coder wrote:
> I'm trying to serialize my struct through CT-Refelction

Here'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
January 24, 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 ?
January 24, 2014
On Friday, 24 January 2014 at 06:11:30 UTC, Uplink_Coder wrote:
> I'm trying to serialize my struct through CT-Refelction

Maybe your _pod_ functions needs a parameter.
// take a look at std.conv.to

string toString(P)(P pod)
{


}
January 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:
>> I'm trying to serialize my struct through CT-Refelction
>
> Maybe your _pod_ functions needs a parameter.
> // take a look at std.conv.to
>
> string toString(P)(P pod)
> {
>
>
> }

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.
January 24, 2014
I have solved by problem.
I just forgot to prepend static to the ifs I used :D