I have a generic code that executes the passsed lambda and checks the outputs. I would like the helper method to be fully deduced, but cannot come up with the solution since the method returns std::optional and I want the processing method to return the underlying type of it. Code:
#include <optional> #include <type_traits> std::optional<int> dummy() { return {42}; }; template<typename F, typename Ret = std::result_of_t<F(void)>> static Ret process(const F& f) { Ret val{}; if(auto res = f(); res) { val = *res;} return val; } int main() { // call auto result = process(&dummy); } The result is of course type of std::optional<int>. What should I change in my template definition to deduce the return type of process to underlying type of std::optional - int?
Ret. Now it compiles.mainadded.Rettypo fix, it was perfectly fine.