Selection of a package of variational parameters for (void)

I really had the following problem: I want to be able to build using -Wall -Wextra -Werror , however the following code will complain about unused options:

 struct foo { template <typename... Args> static void bar() { } template <typename T, typename ... Args> static void bar(T&& value, Args&& ... args) { #ifdef DEBUG std::cout << value; bar(std::forward<Args>(args)...); #endif } }; 

The first unused parameter is easy to fix:

  #ifdef DEBUG std::cout << value; bar(std::forward<Args>(args)...); #else // Shut the compiler up (void) value; #endif 

My question is: how can I do this with the remaining args ? Neither

 (void)(args...); 

Nor

 (void)(args)...; 

will complain about a parameter package that is not expandable.

(This is under GCC 4.7.3, if it will make any difference to the potential solution).

+6
source share
2 answers

When working with a variation template, it is cleaner to use a sink:

 struct sink { template<typename ...Args> sink(Args const & ... ) {} }; #ifdef DEBUG std::cout << value; bar(std::forward<Args>(args)...); #else sink { value, args ... }; //eat all unused arguments! #endif 
+9
source

You can really go with a code name here.

 #ifdef DEBUG #define DEBUG_NAME(x) x #else #define DEBUG_NAME(x) #endif static void bar(T&& DEBUG_NAME(value), Args&& DEBUG_NAME(args)) {} 
+1
source

Source: https://habr.com/ru/post/956524/


All Articles