07/10/29 14:56:29
>>20
ディスパッチのユーティリティとして使うとか。
boost/type_traits/detail/wrap.hpp とかもあるね。
template <class T> struct type {};
template <class T>
struct tester {
template <class U> static char (&test(U*))[1];
template <class U> static char (&test(type<U>*))[2];
template <class U> static char (&test(...))[3];
template <class U> static size_t f1(const U&) {
return sizeof(test<T>(static_cast<U*>(0)));
}
template <class U> static size_t f2(const U&) {
return sizeof(test<T>(static_cast<type<U>*>(0)));
}
};
struct X {};
struct XX : X {};
tester<X>::f1(X()); // => 1
tester<X>::f1(XX()); // => 1
tester<X>::f2(X()); // => 2
tester<X>::f2(XX()); // => 3