template<typename f,typename...x> using result_of = typename result_of<f(x...)>::type; int ff(int){return 2;} typedef bool(*pf)(int); auto fx = [](char ch){return tolower(ch);}; result_of<decltype(&ff)()> r1 = 7; result_of<pf(int)> r2 = 2; result_of<decltype(fx)(char)> r5 = "a"; when compile gcc, following error:
main.cpp: in substitution of 'template<class f, class ... x> using result_of = typename std::result_of<_functor(_argtypes ...)>::type [with f = int (*())(int); x = {}]': main.cpp:17:30: required here main.cpp:6:57: error: function returning function using result_of = typename std::result_of<f(x...)>::type; ^ why getting error , how fix it?
there several things wrong line:
result_of<decltype(&ff)()> r1 = 7; first, result_of takes function type , list of arguments, comma separated. you're not providing them way. it's interpreting f (int)(*)(int)(), pointer function taking int returning function returning int. it's illegal in c++ have function return function, hence error.
second, ff takes int, not nothing. lastly, ff decays pointer-to-function , need actual function. correct expression be:
result_of<decltype(*ff), int> r1 = 7; similarly, next need be:
result_of<pf, int> r2 = 2; result_of<decltype(fx), char> r5 = 'a'; // fx returns int, // can't assign const char*
Comments
Post a Comment