I've been trying to find out the return type of a lambda expression to know if the function returns a void
, or not.
My first thought was using std::invoke_result
, however that did not work as expected, since it doesnt work with std::is_same
, which expects two types.
Here's what i've been trying
auto lamb = [] ( int x ) { cout << x << endl; };
is_same<(invoke_result<decltype(lamb),int>),void>;
The error is:
trabapply2.cc:32:50: error: template argument 1 is invalid
is_same<(invoke_result<decltype(lamb),int>),void>;
Any suggestions?
invoke_result_t
asinvoke_result
is just the type trait type. This will work:static_assert(std::is_same_v<(std::invoke_result_t<decltype(lamb),int>), void>);
– Joseph Thomson Sep 27 '19 at 1:08