std::result_of doesn't compile

89 Views Asked by At

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.

1

There are 1 best solutions below

1
On

It should be possible with trailing return type and decltype, like

template<typename T>
auto CallableWrapper(T callableObj) -> decltype(std::declval<T>()())
{
    ...
}