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.

Mr. Anderson
  • 1,609
  • 1
  • 13
  • 24

1 Answers1

1

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

template<typename T>
auto CallableWrapper(T callableObj) -> decltype(std::declval<T>()())
{
    ...
}
Quentin
  • 62,093
  • 7
  • 131
  • 191
Some programmer dude
  • 400,186
  • 35
  • 402
  • 621