Assoc array typesafe variadic functions
Mint via Digitalmars-d
digitalmars-d at puremagic.com
Wed Jun 3 12:09:50 PDT 2015
I'm a little puzzled by the fact that typesafe variadic functions
may be declared to take an associative array, but there seems to
be no way of calling the function to take advantage of this.
ie. foo is a valid function when declared as:
void foo(int[string] bar...)
{
import std.stdio;
bar.writeln;
}
But the only way to call it seems to be to pass an assoc array as
a parameter,
foo(["a" : 1, "b" : 2]); // Valid
foo("a", 1, "b", 2); // Not valid
foo("a" : 1, "b" : 2); // Syntax error
I also can't find any mention of this in the language reference (
http://dlang.org/function.html#variadic ). I assume that the
syntax is only valid because it would take an additional
specialized language rule to do otherwise, however, it might be
neat to actually have this as a feature.
foo("a" : 1, "b" : 2); // This would be really cool.
More information about the Digitalmars-d
mailing list