On Mon, Apr 19, 2010 at 07:31, BCS <n...@anon.com> wrote:

> Or you can mangel that a bit:
>
> template check(alias func) {
>  bool check(EL ...)() {
>
>     GError* err;
>     bool ok = func(EL, &err);
>     if (!ok)
>        throw new Exception((*err).message);
>     return ok;
>  }
> }
>
> that should allow you to call it like:
>
> check!(fooXXX)(arg1, ..., argN);


(I guess you meant bool check(EL...)(EL el) in the second stage.)

Yes, this example is even more powerful. The version I posted already allows
you to write

check!fun(params); // no need to give explictly the EL, the compiler wil
deduce them for you

 but yours allow you to 'store' the checking of fun and then to use it for
any parameter typetuple. Maybe not useful for the OP, but mighty handy in
some other cases.
I discovered this trick a few weeks ago and, though a bitch to code
sometimes, it's very nice to have.

Usage:

alias check!foo fooCheck; // checkFoo is a templated function, so it's _not_
a function. You cannot assign it to a variable.
                                                 // use alias instead.

// some other code //
auto check1 = fooCheck(1,2,3);
//
auto check2 = fooCheck("a","b", 2.34);

It's particularly useful when foo is polymorphic. Again, not interesting for
the OP, but very fun.

Philippe

Reply via email to