With the expression
(void)var;
we can effectively disable unused variable warnings.
However, how does that work with arguments in a parameter pack?
template<bool Debug = DebugMode, typename... Arg>
void log_debug(const Arg&... args) {
if constexpr(Debug) {
(std::clog << ... << args) << std::endl;
} else {
//ignore the arguments willingly when not in debug
(void)args; // does not compile
}
}
CodePudding user response:
I suggest using maybe_unused
:
template<bool Debug = DebugMode, typename... Arg>
void log_debug([[maybe_unused]] Arg&&... args) {
If you for some reason don't want that, you could make a fold expression over the comma operator in your else
:
} else {
(..., (void)args);
}