metaprogramming question

Justin Spahr-Summers Justin.SpahrSummers at gmail.com
Sun Apr 18 22:43:37 PDT 2010


On Mon, 19 Apr 2010 07:28:09 +0200, Philippe Sigaud 
<philippe.sigaud at gmail.com> wrote:
> 
> On Mon, Apr 19, 2010 at 05:21, Justin Spahr-Summers <
> Justin.SpahrSummers at 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);

Yes, sorry. That's what I was trying to do originally, but I couldn't 
quite spit it out. Indeed, templating the actual arguments is a horrible 
idea.


More information about the Digitalmars-d-learn mailing list