Template. C++ to D
Dennis Ritchie via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Mar 11 05:02:08 PDT 2015
Hi.
How to rewrite this code on D?
#include <string>
#include <iostream>
template <typename T>
T foo(const T &val)
{
return val;
}
template <typename T, typename ...U>
T foo(const T &val, const U &...u)
{
return val + foo(u...);
}
int main()
{
std::cout << foo(std::string("some "), std::string("test"))
<< std::endl; // prints some test
std::cout << foo(2, 2, 1) << std::endl; // prints 5
}
More information about the Digitalmars-d-learn
mailing list