On Mon, Apr 19, 2010 at 05:21, Justin Spahr-Summers <
justin.spahrsumm...@gmail.com> wrote:

> You can use some expression tuple magic to accomplish something like
> that:
>
> bool check(alias func, EL ...)() {
>    GError* err;
>    bool ok = func(EL, &err);
>     if (!ok)
>        throw new Exception((*err).message);
>
>     return ok;
> }
>
> // used like:
> check!(fooXXX, arg1, ..., argN);
>
>
But in this case, you need to know the ELs at compile-time. You can make
them run-time values that way:

bool check(alias func, EL ...)(EL el) {
   GError* err;
   bool ok = func(el, &err);
    if (!ok)
       throw new Exception((*err).message);

    return ok;
}

// used like:
check!fooXXX(arg1, ..., argN);


Of course, it'd be nice to check the EL at CT to see if they correspond to
func parameters types. I don't know if you can do this with C functions, but
for D funcs you can add:

import std.traits;
bool check(alias func, EL ...)(EL el) if (is(ParameterTypeTuple!func[0..$-1]
== TypeTuple!(EL, GError*))
{
...

It's a bit strict, as it doesn't deal with implicit conversions.

Cheers,

  Philippe

Reply via email to