metaprogramming question

Graham Fawcett fawcett at uwindsor.ca
Sun Apr 18 17:12:28 PDT 2010


Hi folks,

I'd like to wrap a family of C functions that look like this:

      gboolean fooXXX(arg1, ..., argN, GError** err)

Their signatures and arities vary, but they all have a GError** as
their last argument. If a function returns false, then 'err' will be
set to a relevant Error struct.

I would like to write a wrapper that would let me call these functions
sort of like this:

      check!(fooXXX(arg1, ..., argN))

where the 'check' expression would be equivalent to:

      GError* err;
      bool ok = fooXXX(arg1, ..., argN, &err);
      if (!ok)
        throw new Exception((*err).message);

Does D (2.0) offer a metaprogramming technique I could use to
accomplish this -- particularly, to inject that 'err' argument into
the tail of the fooXXX call?

Thanks,
Graham


More information about the Digitalmars-d-learn mailing list