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);
}
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__)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.