Named arguments via struct initialization in functions

Marc Schütz via Digitalmars-d digitalmars-d at puremagic.com
Thu Mar 10 10:48:38 PST 2016


On Tuesday, 8 March 2016 at 20:32:02 UTC, Idan Arye wrote:
> Declaring the named arguments variadically will be done by 
> adding `...` after a struct argument:
>
>     struct Options{int x; int y=1; int z=2;}
>     auto fun(Options options ...)
>
> We'll need a syntax for specifying the arguments - but that's 
> more of a matter of taste than an actual technical problem, and 
> it's going to be bikeshedded over and over, so for the purpose 
> of describing my idea let's pick a Ruby-style `:`(because `=` 
> will break the rule of 
> if-it-compiles-as-C-it-should-work-like-C):
>
>     fun(x: 4, z: 3);
>
> I've promised you to solve ambiguity, right?

--snip--

I'm not sure, but I think the problem Walter has lies with 
_detecting_ ambiguity in the first place, because that would make 
overload resolution more complicated. I personally don't think 
it's that big a problem, because selecting the candidates could 
be a step before actual (= as it is now) overload resolution.


More information about the Digitalmars-d mailing list