# include # include # include # include # include # include "boost/type_traits/is_same.hpp" # include #include #include #include namespace detail { typedef char One; typedef struct { char a[2]; } Two; } // namespace detail #define TYPE_HAS_MEMBER_TYPE(STRUCT_NAME, MEMBER_TYPE) \ namespace detail { \ \ template One STRUCT_NAME(typename T::MEMBER_TYPE (*)()); \ template Two STRUCT_NAME(...); \ \ } /* namespace detail */ \ \ template \ struct STRUCT_NAME \ : boost::mpl::bool_< sizeof(detail::STRUCT_NAME(0)) == 1 > \ {} TYPE_HAS_MEMBER_TYPE(has_char_type, char_type); TYPE_HAS_MEMBER_TYPE(has_traits_type, traits_type); #undef TYPE_HAS_MEMBER_TYPE template struct is_derived_from_std_basic_ostream : boost::mpl::and_< boost::mpl::and_< has_char_type , has_traits_type > , boost::mpl::or_< boost::is_same< std::basic_ostream< typename T::char_type, typename T::traits_type > , T > , boost::is_base_and_derived< std::basic_ostream< typename T::char_type, typename T::traits_type > , T > > > {}; int main() { print(is_derived_from_std_basic_ostream()); print(is_derived_from_std_basic_ostream()); print(is_derived_from_std_basic_ostream()); print(is_derived_from_std_basic_ostream()); print(is_derived_from_std_basic_ostream()); print(is_derived_from_std_basic_ostream()); print(is_derived_from_std_basic_ostream()); print(is_derived_from_std_basic_ostream()); print(is_derived_from_std_basic_ostream()); print(is_derived_from_std_basic_ostream()); print(is_derived_from_std_basic_ostream()); print(is_derived_from_std_basic_ostream()); return 0; }