Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cast variadic template type to void, expected ')' before

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.

like image 653
eneski Avatar asked Aug 15 '18 13:08

eneski


1 Answers

You can have a LOG_CHAT for release with no parameter names, that will inhibit the warning.

void LOG_CHAT(Rest && ...)
like image 54
Dani Avatar answered Sep 19 '22 09:09

Dani