Hi,

I am working through the book 'Programming in D' and wanted to take the sample program on http://ddili.org/ders/d.en/types.html, one step further:


    import std.stdio;

    void main() {
        writeln("Type           : ", int.stringof);
        writeln("Length in bytes: ", int.sizeof);
        writeln("Minimum value  : ", int.min);
        writeln("Maximum value  : ", int.max);
        writeln("Initial value  : ", int.init);
    }

Say, I want to have a list of types and sniff each type as I go: (this doesn't compile, yet)




auto types = [bool, byte, ubyte, short, ushort, int, uint, long, ulong, float, double, real, char, wchar, dchar];

    for (t; types) {
        sniffType(t);
    }


    void sniffType(auto myType) {
        writeln('Type           : ', myType.stringof);
        writeln('Length in bytes: ', myType.sizeof);
        writeln('Minimum value  : ', myType.min);
        writeln('Maximum value  : ', myType.max);
        writeln('Initial value  : ', myType.init);wri
    }


How would I go about achieving this?

PS: Thanks for making this book online, Ali!

Reply via email to