テンプレートファンクターラッパーから任意の型 (void または非 void) を返す方法は? 事前条件と事後条件にラッパーを使用するため、戻り値をラッパーから返す前にローカル変数に格納する必要があります。しかし、返された型が void の場合、変数は void 型を持つことができないため、コンパイラはエラーを返します。ここで何ができるでしょうか?
template <typename Functor, typename... Args>
auto Decorate(Functor f, Args&&... args)
-> decltype(f(std::forward<Args>(args)...)) {
// preconditions
const auto result = f(std::forward<Args>(args)...);
// postconditions
return result;
}