It is possible to use the following pattern to detect whether or not x can be applied to T
template<class T, class Enable = void>
struct CanDoX: std::false_type{};
template<class T>
struct CanDoX<T, std::void_t<decltype(x(std::declval<T>()))>>:std::true_type{};
What if x
has been defined as
Foo const& x(Bar const&&) = delete;
Foo const& x(Bar const& val)
{return val.get();}
Now CanDoX<Bar>::value
is false
, because no overload accepts a temporary. Somehow, there has to be a Bar val
before the test for x(val)
.