可调用结果类型的推导

Deduction of result type of callable

我尝试推断可调用模板参数的类型,不幸的是没有成功:

template<typename callable, typename T_out >
class A
{};

template<typename callable>
auto make_A( callable f )
{
  return A<callable, typename std::result_of_t<callable> >{ f };
}

int main()
{
  make_A( []( float f ){ return f;} );
}

以上代码导致以下错误:

error: implicit instantiation of undefined template 'std::__1::result_of<(lambda at /Users/arirasch/WWU/dev/xcode/tests/tests/main.cpp:31:11)>'
template <class _Tp> using result_of_t = typename result_of<_Tp>::type;

有人知道怎么解决吗?

非常感谢。

需要把参数列表传给std::result_of,否则无法分辨return类型(operator()毕竟可以重载)

return A<callable, std::result_of_t<callable(float)> >{ f }

(前提是 A<callable, std::result_of_t<callable(float)> 可以用 f 构造,但示例不是这种情况)