this is almost a workaround for the lack of named parameters
J
notavail at notavailable.com
Tue Mar 26 23:45:57 PDT 2013
On Wednesday, 27 March 2013 at 03:29:24 UTC, Timothee Cour wrote:
>>>Interesting, the "doesn't not support passing the arguments
>>>out of order." can be seen either as a (temporary or not)
>>>implementation >>limitation OR as a feature.
>
> Named parameters are only interesting if we can skip some
> optional parameters.
I'd say named parameters are *more* interesting with skipping and
re-ordering, but still incredibly valuable even without. Let us
get them in people's hands first (and start the addiction process
going...bwahahaha!)
Let people experience first hand how awesome they are in a quick,
doable form.
(Feel free to contribute code that implements those skipping and
re-ordering features...)
Status update: I fixed the only known bug, and added a feature.
a. Named parameters now flow into variadic template arguments
without a hitch.
In other words, this compiles:
void test(A...)(A a) {}
void main ()
{
test(b: 33.3
c: 44.4);
}
b. There is an name-matching escape mechanism now. It uses
_underscores. If your function looks like:
void f(int a, int _b) {}
then you can call it like this:
f(a:1, anyLabelYouWant: 3);
(Actually this was necessitated by how dmd treats variadic actual
arguments; it calls them _param_0, _param_1, ..., internally. I'm
still going to call this escape-mechanism a feature, though.)
Here's the latest (see the named_parameters branch specifically)
https://github.com/glycerine/dmd/tree/named_parameters
This passes all tests.
Try it out. Try and break it.
More information about the Digitalmars-d
mailing list