- 261 名前:デフォルトの名無しさん mailto:sage [2008/01/29(火) 17:55:27 ]
- ググったらこんなのが出てきた。
www.gamedev.net/community/forums/topic.asp?topic_id=435173 これを基に少し改造してみた。BjarneStroustrupとOthersは>>249の定義を使用。 #include <iostream> #include <boost/mpl/bool.hpp> //#include <boost/type_traits.hpp> struct SFINAE { typedef char one; typedef struct { char c[2]; } two; }; template<typename T> class has_hage_impl { template<void (T::*)()> struct Wrap {}; template<typename U> static SFINAE::one Determine(Wrap<&U::Hage>* w); template<typename U> static SFINAE::two Determine(...); public: static const bool value = sizeof(Determine<T>(0)) == sizeof(SFINAE::one); }; template<typename T> struct has_hage : boost::mpl::bool_<has_hage_impl<T>::value> {}; //boost::integral_constant<bool, has_hage_impl<T>::value>も可 int main() { std::cout << std::boolalpha << has_hage<BjarneStroustrup>::value << '\n' << has_hage<Others>::value << std::endl; }
|

|