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,439
  • 1
  • 12
  • 22

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
  • 60,592
  • 7
  • 125
  • 183
Some programmer dude
  • 380,411
  • 33
  • 383
  • 585