In my code, I use variadic template functions for the logging mechanism. If DEBUG
macro is defined, a message is printed; if DEBUG
is not defined, then it should print nothing.
My code:
#ifdef DEBUG
inline void LOG_CHAT(){ }
template<typename First, typename ...Rest>
void LOG_CHAT(First && first, Rest && ...rest){
std::cout << std::forward<First>(first);
LOG_CHAT(std::forward<Rest>(rest)...);
}
#else
template<typename ...Rest>
void LOG_CHAT(Rest && ...rest){
(void)(rest...);
}
#endif
I would leave the function definition empty, but I do not want to get "unused parameter" compiler warning. Therefore, parameter(s) are cast to void to get rid of the compiler warning. However, casting is causing another error that is reproduced below.
error: expected ')' before 'rest' UNUSED(...rest);
note: in definition of macro 'UNUSED' #define UNUSED(x) (void)(x)
So, my main goal is getting rid of compiler warning, either by casting to void
or using any other method. But I would be happier if I'd be able to cast it to void
.
You can have a LOG_CHAT
for release with no parameter names, that will inhibit the warning.
void LOG_CHAT(Rest && ...)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With