Default template arguments

bearophile bearophileHUGS at lycos.com
Mon Nov 19 09:41:32 PST 2012


Joseph Rushton Wakeling:

> ... or have I missed something?

Second try:

import std.stdio;

void printSize2(T)(T x) {
     writeln(T.stringof);
}

void printSize(T1 = void, T2 = real)(T2 x) {
     static if (is(T1 == void))
         printSize2!real(x);
     else
         printSize2!T1(x);
}

void main() {
     float x;
     x.printSize();       // shoud be real
     x.printSize!float(); // shoud be float
     x.printSize!real();  // shoud be real
}

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list