C++03 で has_xxx の実装
久々に書いてみたら全然書き方覚えてなかったので覚書。
template<typename T> struct sfinae_helper{ typedef void type; }; template<typename T, typename U = void> struct has_xxx{ static bool const value = false; }; template<typename T> struct has_xxx<T, typename sfinae_helper<typename T::xxx>::type>{ static bool const value = true; }; struct X{ typedef void xxx; }; static_assert(has_xxx<X>::value, ""); // ok static_assert(has_xxx<int>::value, ""); // error
C++11 以降であればもっとスッキリとかけるんですけどねぇ…。