1

I'd like to come up with a c++ wrapper function that fully wraps the TraceLoggingWrite macro. TraceLoggingWrite is a macro with variadic parameters. I attempted the following code snippet, but it would encounter compilation errors because it seems like the syntax requires the wrapped function to accept a va_list parameter. If so, is there another way to accomplish this?

void WrapperFunction(String Name, ...)
{
    va_list args;
    va_start(args, Name);
    TraceLoggingWrite(gProvider,
                      Name,
                      TraceLoggingInt32(32, "Test"),
                      args);
    va_end(args);
}
Trevor Hickey
  • 36,288
  • 32
  • 162
  • 271
lancery
  • 658
  • 1
  • 6
  • 18

1 Answers1

2

You may consider using parameter pack:

template<typename... Ts>
void WrapperFunction(String Name, Ts... args)
{
    TraceLoggingWrite(gProvider,
        Name,
        TraceLoggingInt32(32, "Test"),
        args...);
}

However because TraceLoggingWrite is a variadic macro, there might be cases where parameter packs do not work. An alternative would be to create another macro, also variadic, something like this:

#define WrapperMacro(eventName, ...) TraceLoggingWrite(gProvider, eventName, __VA_ARGS__)
AlexD
  • 32,156
  • 3
  • 71
  • 65