www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Named variadic arguments

reply bearophile <bearophileHUGS lycos.com> writes:
Coming from this question, named variadic arguments:
http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D.learn&article_id=18586

It's a possible way to implement something like this Python code:
def foo(x, y, **kwds):
  # here kwds is a dict of str:value

With another kind of typesafe variadic function:
void foo(int x, int y, Box[string] kwds ...) {}

foo(1, 2, z:10, w:30);
==>
In foo kwds == ["z":box(10), "w":box(30)];
(Variant or something else can be used instead of Box.)

Bye,
bearophile
Jan 05 2010
parent bearophile <bearophileHUGS lycos.com> writes:
 With another kind of typesafe variadic function:
 void foo(int x, int y, Box[string] kwds ...) {}

While that can be useful, so far I've never find an use of "typesafe variadic functions for class objects" (See D docs about typesafe variadic functions). If no one uses this feature then it can be removed from D2. Bye, bearophile
Jan 06 2010