// (C) Copyright John Maddock 2000. Permission to copy, use, modify, sell and // distribute this software is granted provided this copyright notice appears // in all copies. This software is provided "as is" without express or implied // warranty, and with no claim as to its suitability for any purpose. #ifndef BOOST_TT_IS_BASE_AND_DERIVED_HPP_INCLUDED #define BOOST_TT_IS_BASE_AND_DERIVED_HPP_INCLUDED #include "boost/type_traits/is_class.hpp" #include "boost/type_traits/is_convertible.hpp" #include "boost/type_traits/detail/ice_and.hpp" #include "boost/config.hpp" // should be the last #include #include "boost/type_traits/detail/bool_trait_def.hpp" namespace boost { namespace detail { template struct is_base_and_derived_overloads { template static type_traits::yes_type check(D const volatile &, T); static type_traits::no_type check(B const volatile &, int); struct C { operator B const volatile &() const; operator D const volatile &(); }; static C getC(); }; template struct is_base_and_derived_impl2 { BOOST_STATIC_CONSTANT(bool, value = (sizeof(is_base_and_derived_overloads::check(is_base_and_derived_overloads::getC(), 0)) == sizeof(type_traits::yes_type)) ); }; template struct is_base_and_derived_impl3 { BOOST_STATIC_CONSTANT(bool, value = false); }; template struct is_base_and_derived_select { template struct rebind { typedef is_base_and_derived_impl3 type; }; }; template <> struct is_base_and_derived_select { template struct rebind { typedef is_base_and_derived_impl2 type; }; }; template struct is_base_and_derived_impl { typedef is_base_and_derived_select< ::boost::is_class::value, ::boost::is_class::value> selector; typedef typename selector::template rebind binder; typedef typename binder::type bound_type; BOOST_STATIC_CONSTANT(bool, value = bound_type::value); }; } // namespace detail BOOST_TT_AUX_BOOL_TRAIT_DEF2( is_base_and_derived , Base , Derived , (::boost::detail::is_base_and_derived_impl::value) ) #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION BOOST_TT_AUX_BOOL_TRAIT_PARTIAL_SPEC2_2(typename Base,typename Derived,is_base_and_derived,Base&,Derived,false) BOOST_TT_AUX_BOOL_TRAIT_PARTIAL_SPEC2_2(typename Base,typename Derived,is_base_and_derived,Base,Derived&,false) BOOST_TT_AUX_BOOL_TRAIT_PARTIAL_SPEC2_2(typename Base,typename Derived,is_base_and_derived,Base&,Derived&,false) #endif } // namespace boost #include "boost/type_traits/detail/bool_trait_undef.hpp" #endif // BOOST_TT_IS_BASE_AND_DERIVED_HPP_INCLUDED #include "test.hpp" #include "check_integral_constant.hpp" #include TYPE_TRAITS(is_base_and_derived) TT_TEST_BEGIN(is_base_and_derived) BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_and_derived::value), false); BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_and_derived::value), true); BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_and_derived::value), true); BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_and_derived::value), true); BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_and_derived::value), false); BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_and_derived::value), false); BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_and_derived::value), false); BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_and_derived::value), false); BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_and_derived::value), false); BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_and_derived::value), false); BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_and_derived::value), false); BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_and_derived::value), true); BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_and_derived::value), false); BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_and_derived::value), true); BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_and_derived::value), false); TT_TEST_END