I have a functional object which is a wrapper around another function:
template <typename FuncT>
class Wrapper
{
private:
FuncT funcToWrap;
public:
Wrapper(FuncT ftw) : funcToWrap(ftw){};
template<typename ...ARG>
typename std::result_of<FuncT(ARG&&...)>::type operator()(ARG&&... args){
return funcToWrap(std::forward<ARG>(args)...);
}
};
int main(){
std::function<void()> testfunc = [](){ std::cout << "Test" << std::endl; };
Wrapper<decltype(testfunc)> test{testfunc};
test();
}
What I would like to do is to mark the operator()
as [[nodiscard]]
if the std::result_of<FuncT(ARG&&...)>::type
is not void
.
What I have noticed is that when I do put the [[nodiscard]]
in case of the template evaluation of return type to void
, it will simply get ignored by my compiler.
Is this the behaviour I can rely on, is it in any way standarized?