[ create a new paste ] login | about

Link: http://codepad.org/lSDTFd7E    [ raw code | fork ]

D, pasted on Apr 25:
import std.stdio;
import std.conv;
import std.algorithm;

struct Foo
{
    float stepFloat;
    float smallStepFloat;
    float largeStepFloat;
    string label = "label";
    int flags;
    int minInteger;
    int maxInteger;
    int stepInteger;
    int largeStepInteger;
    string shortLabel = "short";
    short displayIndex;
    short category;
    short numParametersInCategory;
    short reserved;
    void func() { }
    int func2(int x, int y) { return 1; }
}

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()
{
    Foo properties;

    writeln();
    printFields(properties);
}


Create a new paste based on this one


Comments: