I've got the book C++ Templates the complete guide and I'm trying to implement some of the described techniques. One of these is member function detection, but my implementation seems not working.
I can't use void_t as I'm using C++11, but I copied the definition, so this should be not the problem.
Following is the code:
namespace nt_detail
{
template< class... >
using void_t = void;
}
template<typename T, typename = nt_detail::void_t<>>
struct HasHelloMember
: std::false_type {};
template<typename T>
struct HasHelloMember<T,
nt_detail::void_t<decltype(std::declval<T>().hello())>>
: std::true_type {};
and here the test one:
class ZZZ
{
};
class ZZZ2
{
public:
void hello()
{}
};
int main()
{
if(HasHelloMember<ZZZ>::value)
{
std::cout << "ZZZ has hello" << std::endl;
}
else
{
std::cout << "ZZZ has NOT hello" << std::endl;
}
if(HasHelloMember<ZZZ2>::value)
{
std::cout << "ZZZ2 has hello" << std::endl;
}
else
{
std::cout << "ZZZ2 has NOT hello" << std::endl;
}
}
In both cases I get "has hello". Is there something wrong with my void_t implementation perhaps?