Template. C++ to D

Namespace via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Mar 11 05:10:31 PDT 2015


Or even shorter:

import std.stdio;

T foo(T, Args...)(auto ref const T val, auto ref const Args u)
{
     static if (Args.length > 0) {
         static if (is(T == string))
             return val ~ foo(u);
         else
             return val + foo(u);
     } else {
         return val;
     }
}

void main()
{
     writeln(foo("some ", "test")); // prints some test
     writeln(foo(2, 2, 1));      // prints 5
}


More information about the Digitalmars-d-learn mailing list