On Tuesday, 10 June 2014 at 20:01:37 UTC, Nordlöw wrote:
Notice that A.init.tupleof segfaults for classes so that is
_not_ an adviced solution in a generic solution!
There's no need to use .init:
import std.stdio;
struct Foo {
int a, b;
}
void main() {
writeln(__traits(id
On Tuesday, 10 June 2014 at 16:13:31 UTC, Adam D. Ruppe wrote:
Two options: do allMembers and filter it out to only be data
members, or do some slicing of tupleof.stringof:
S s;
foreach(idx, member; s.tupleof) {
writeln("Name: ", s.tupleof[idx].stringof[2..$]);
}
The tupleof[idx] inside th
On Tuesday, 10 June 2014 at 17:29:35 UTC, Dicebot wrote:
On Tuesday, 10 June 2014 at 16:10:09 UTC, Nordlöw wrote:
Is there a way to iterate over the symbolic names of the data
members of a class instance?
I'm currently using .tupleof to get its values (and in turn
types) to implement pretty
BTW: Can DMD serve use file and line location of user defined
type aswell?
Thx!
Correction: I mean serve *us*
I am not sure I understand the question. Does this help?
struct A
{
int x;
double y;
}
void main()
{
foreach (idx, elem; A.init.tupleof)
{
pragma(msg, __traits(identifier, A.tupleof[idx]));
}
}
// output:
// x
// y
Exactly what I wanted!
On Tuesday, 10 June 2014 at 16:10:09 UTC, Nordlöw wrote:
Is there a way to iterate over the symbolic names of the data
members of a class instance?
I'm currently using .tupleof to get its values (and in turn
types) to implement pretty printing to multiple backends
(currently testing HTML) u
On Tuesday, 10 June 2014 at 16:30:52 UTC, Nordlöw wrote:
What trait should I use to filter out data members?
No trait, more like an is thing to see if the thing has an init.
I think
static if(is(typeof(__traits(getMember, Thing, name).init)) { }
will do it. (BTW the sample chapter of my boo
On Tuesday, 10 June 2014 at 16:13:31 UTC, Adam D. Ruppe wrote:
Two options: do allMembers and filter it out to only be data
members, or do some slicing of tupleof.stringof:
What trait should I use to filter out data members?
S s;
foreach(idx, member; s.tupleof) {
writeln("Name: ", s.tupleo
Two options: do allMembers and filter it out to only be data
members, or do some slicing of tupleof.stringof:
S s;
foreach(idx, member; s.tupleof) {
writeln("Name: ", s.tupleof[idx].stringof[2..$]);
}
The tupleof[idx] inside the loop is important instead of just
using member because then y
Is there a way to iterate over the symbolic names of the data
members of a class instance?
I'm currently using .tupleof to get its values (and in turn
types) to implement pretty printing to multiple backends
(currently testing HTML) using as much of D's compile time
reflection as possible:
10 matches
Mail list logo