我想enable_if一个成员函数存在于类T中,因此我尝试编写下面的代码。
template< typename T, typename = void >
struct has_member_func : std::false_type {};
template< typename T >
struct has_member_func< T, decltype(&T::some_func) > : std::true_type {};
但是,即使类T确实有一个名为some_func的函数,它始终求值为std :: false_type。 为什么?
In the partial specialization, the 2nd template parameter should yield the type
void
; otherwise it won't be selected.You can apply
std::void_t
likeLIVE