Applying a tuple to a function (and more)

Juanjo Alvarez juanjux at gmail.com
Sun Sep 19 05:35:37 PDT 2010


Philippe Sigaud wrote:

> String mixins are quite powerful, if a bit clunky at times.

Both true, for what I'm seeing of them.
 
> See also __traits(getMember, ...)
> http://digitalmars.com/d/2.0/traits.html   (look for getMember)

Nice, with getMembers I could redesign again my test code for using objects 
instead of a virtual function, but I'll keep the current design because is 
simpler for me (I'm still adapting my brain to all this genericity).

On my current implementation with functions I still have a doubt: 

I'm using template-functions like this one for my callbacks:

void somefunc(T...) (string regex, T args...) {
    foreach (arg; args) {
        writeln(arg);
    }
}

Then, I write the "selector" for it (in other part of the program) like 
this:

auto t = tuple("someregex", &(module.somefunc!(int, double)),tuple(2,3.14));

And then in a third module, I get those selectors and bind them to the 
functions like:

auto selectable = t.field[1];
selectable(t.field[0], t.field[2].expand); // Called!

With your help, this works like a charm.

But sometimes there will be no variable arguments to "somefunc" (only the 
first string), and in that case I don't know what would be the correct 
syntax to specify that the variable number of arguments will have no args, 
both for the template instantiation and for the tuple:

auto t = tuple("bla", &(module.somefunc!(void), tuple(void)); // Fails
auto t = tuple("bla", &(module.somefunc!(void, Tuple!(void)()); // Fails too


  
> Yes, typecons.Tuple has lot of nifty things going for it, but there are
> not all documented.
> You can open a bug/enhancement request at http://d.puremagic.com/issues/

I'll do it. I guess currently most of you here check the source before the 
documentation since the former looks to be pretty outdated sometimes.
 



More information about the Digitalmars-d-learn mailing list