Assoc array typesafe variadic functions
extrawurst via Digitalmars-d
digitalmars-d at puremagic.com
Wed Jun 3 15:16:02 PDT 2015
On Wednesday, 3 June 2015 at 19:09:52 UTC, Mint wrote:
> 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,
defining a assoc array parameter would make me expect exactly
that: that it takes a assoc array as a paramter.
>
> 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.
whats the benefit of implementing this special case ? you save
exactly 2 keystrokes ?
More information about the Digitalmars-d
mailing list