vendredi 31 juillet 2015

why is void_t necessary to check for the existence of a member type?

When reading Barry's answer to Check if a given type has a inner template rebind, I thought:

Why do we need void_t at all?

Why does the following not work?

#include <iostream>

template <typename X, typename Y = X>
struct has_rebind : std::false_type {};

template <typename X>
struct has_rebind<X, typename X::template rebind<int>> : std::true_type {};

struct A { };
struct B { template <typename > struct rebind { }; };

int main() {
    std::cout << has_rebind<A>::value << std::endl;
    std::cout << has_rebind<B>::value << std::endl;
}

output

0
0

demo

Aucun commentaire:

Enregistrer un commentaire