0

I'm trying to use std::result_of to determine the return type of a callable object:

template <typename T>
std::result_of<T()>::type CallableWrapper(T callableObj) {
    return callableObj();
}

Somewhere else in the code:

auto i = CallableWrapper([](){return 1;});

This code doesn't compile for some reason. I will appreciate if someone would tell me why.

4

1 回答 1

1

应该可以使用尾随返回类型 and decltype,例如

template<typename T>
auto CallableWrapper(T callableObj) -> decltype(std::declval<T>()())
{
    ...
}
于 2015-08-02T16:30:13.183 回答