Default template arguments
    Joseph Rushton Wakeling 
    joseph.wakeling at webdrake.net
       
    Mon Nov 19 10:50:00 PST 2012
    
    
  
On 11/19/2012 06:44 PM, bearophile wrote:
> 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);
> }
Thanks for the suggestion! :-)
Now I think of it, is there anything wrong with,
void printSizeHelper(T)(T x)
{
       writeln(x.sizeof);
}
void printSize(T1 = real, T2)(T2 x)
       if(is(T2 : T1))
{
       printSizeHelper!T1(x);
}
... bar some extra safety constraints, perhaps?
I have a feeling I'd considered that solution at some point but had put it aside 
because I was feeling sure there must be a way that didn't involve creating an 
extra template parameter.
    
    
More information about the Digitalmars-d-learn
mailing list