apply function to parameters
Jack Applegame
japplegame at gmail.com
Tue Aug 6 09:33:12 PDT 2013
On Tuesday, 6 August 2013 at 16:03:07 UTC, Dicebot wrote:
> On Tuesday, 6 August 2013 at 15:51:28 UTC, Jack Applegame wrote:
>> On Tuesday, 6 August 2013 at 14:44:18 UTC, bearophile wrote:
>>> Take a look at std.typetuple.staticMap
>> staticMap works with types, and I don't know how it can help.
>
> Not really. Anything that can be provided to template argument
> list can be stored in TypeTuple and thus processed by
> staticMap. Name is very confusing here.
Yes. Types, literals and aliases. But this doesn't help.
I wrote very ugly, but working solution. I don't like it, but I
can't invent something better. :(
auto apply(alias p, alias f, Args...)(Args args) {
auto impl(uint num, Head, Tail...)(Head head, Tail tail) {
static if(num == 0) return p(head, tail);
else return impl!(num - 1)(tail, f(head));
}
return impl!(args.length)(args);
}
apply!(fun1, fun2)(arg1, arg2, ...) === fun1(fun2(arg1),
fun2(arg2), ...)
offtop: Dicebot, do you speak russian?
More information about the Digitalmars-d-learn
mailing list