Default template arguments

Ali Çehreli acehreli at yahoo.com
Mon Nov 19 09:50:59 PST 2012


On 11/19/2012 09:44 AM, bearophile wrote:
> Better:
>
> import std.stdio;
>
> private void printSizeHelper(T)(T x) {
> writeln(T.stringof);
> }
>
> void printSize(T1 = void, T2)(T2 x) {
> static if (is(T1 == void))
> printSizeHelper!real(x);
> else
> printSizeHelper!T1(x);
> }
>
> void main() {
> float x;
> x.printSize();
> x.printSize!float();
> x.printSize!real();
> }
>
>
> (Keeping the two functions separated is useful against template bloat.)
>
> Bye,
> bearophile

I like that! :)

Is it possible or required to ensure that T1 is T2 in the static else 
clause?

Ali


More information about the Digitalmars-d-learn mailing list