2

I need a macro/templated function that will wrap function call of some method on specific object, i.e

a.Destroy()

where a can be of any type as well as Destroy and Destroy may or may not take 0 to n parameters. Inside this wrapper I need to do some checks.

I would like to be able to call this function as a wrapper:

DESTROY_CHECK(a.Destroy(p1,p2,...))

or

DESTROY_CHECK(a, Destroy(p1,p2,...))

How can I achieve this?

mezo
  • 423
  • 1
  • 7
  • 19

1 Answers1

0

You can consider variadic macro:

#define identifier( parameters, ... ) replacement-list

... defines a function-like macro with variable number of arguments. The additional arguments can be accessed using __VA_ARGS__ identifier, which is then replaced with arguments, supplied with the identifier to be replaced.

#define DESTROY_CHECK(x, ...) assert(x.Destroy(__VA_ARGS__))
Community
  • 1
  • 1
AlexD
  • 32,156
  • 3
  • 71
  • 65