Cannot interpret struct at compile time
Andrej Mitrovic
andrej.mitrovich at gmail.com
Sat May 7 15:36:24 PDT 2011
Not too sure, CTFE is a pain in the ass sometimes. What exactly are
you trying to do, print field names in a custom way?
I have this piece of code I use for printing values, maybe you can
customize it for own your needs:
import std.stdio;
import std.conv;
import std.algorithm;
struct Foo
{
int abc;
int foobar;
}
void printFields(T)(T args)
{
auto values = args.tupleof;
size_t max;
size_t temp;
foreach (index, value; values)
{
temp = T.tupleof[index].stringof.length;
if (max < temp) max = temp;
}
max += 1;
foreach (index, value; values)
{
writefln("%-" ~ to!string(max) ~ "s %s",
T.tupleof[index].stringof, value);
}
}
void main()
{
writeln();
Foo foo = Foo(1, 2);
printFields(foo);
}
More information about the Digitalmars-d-learn
mailing list