Answer by Eric for handling void type in template
Not certain this is valid, but:template<>void Foo<T>( T(*Func)() ) { // do something first (e.g. some setup) return tearDown(Func());}template<>T tearDown<T>( T result) { // do...
View ArticleAnswer by K-ballo for handling void type in template
Given that your operation does not depend on the result of the function, you can do it without a specialization. It is ok for a function returning void to return an expression of type void. So the...
View ArticleAnswer by Pubby for handling void type in template
If all you're doing is taking and releasing a lock then you should use RAII instead of calling lock/unlock functions. This is especially true if Func could throw, as if it does the code after it will...
View ArticleAnswer by gustaf r for handling void type in template
No, you need the specialization since you cannot store void (as in T result = Func();).If you're never gonna use the value, and you are fine with calling Func as the last thing, then you can...
View Articlehandling void type in template
I have a templated function that invokes another function and stores its return value, then does some work before returning the value. I'd like to extend this to handle T = void, and was wondering if...
View ArticleAnswer by Criminal_Affair_At_SO for handling void type in template
Late to the party, especially since C++17 if constexpr solves this perfectly, but if you are limited to C++11, here is my solution:For the variable, use a type helper:template <typename T> struct...
View Article