Function Template for Dynamic Parameter
vino.B
bheeman.vino at hotmail.com
Sun Jul 1 09:46:32 UTC 2018
All,
Request your help, the D document states that "Template
functions are useful for avoiding code duplication - instead of
writing several copies of a function, each with a different
parameter type, a single function template can be sufficient"
which mean we can passing any type of parameter using function
template, similarly who we we pass in any number of parameter of
any type(dynamic parameters) , like in python
Python
def myfunc(*arg)
def myfunc(**kwargs) // multiple key-value
def myfunc(*args, **kwargs): mix
Do we have any thing similar to the above python in D
void (func(T)( T *args) // Example
Examples:
void func(T)(T x)
{
writeln(x);
}
void main()
{ func("x"); // pass a string }
void func(T)(T n3)
{
writeln(n); // where n = 3 parameters (1, string, char)
}
void func(T)(T n2)
{
writeln(n); // where n = 3 parameters (1, string)
}
void func(T)(T n1)
{
writeln(n); // where n = 3 parameters (1 or string or char)
}
From,
Vino.B
More information about the Digitalmars-d-learn
mailing list