With c++17 we have fancy new is_invocable and fancy new prvalues that aren\'t really values.
This permits you to create an object without having to first logically const
Is there an alternative, or do we have to invent our own trait to handle this case?
Yeah, you'd just have to write your own trait that doesn't use declval
. Assuming you have std::is_detected lying around (which I know you certainly do):
template T make();
template
using invoke_result_t = decltype(std::declval()(make()...));
// ^^^^^^^^^^^^^ ^^^^^
template
using is_invocable = std::is_detected;
This way, std::is_invocable
is false_type
, but is_invocable
is true_type
.
I intentionally use declval
for the function instead of make
so as to allow using decltype(f)
here. Really, invoke_result_t
should be more complicated, and "do the right thing" for pointers to members, etc. But this is at least a simple approximation that indicates the viability of this approach.