is_base_and_derived_test.cpp 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // (C) Copyright John Maddock 2000.
  2. // Use, modification and distribution are subject to the
  3. // Boost Software License, Version 1.0. (See accompanying file
  4. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. #ifdef TEST_STD
  6. # include <type_traits>
  7. #else
  8. # include <boost/type_traits/is_base_and_derived.hpp>
  9. #endif
  10. #include "test.hpp"
  11. #include "check_integral_constant.hpp"
  12. //
  13. // Additional tests added for VC7.1 bug, 2005/04/21
  14. //
  15. struct marker{};
  16. struct foo{ int x; };
  17. template<class Class,typename Type,Type Class::*PtrToMember>
  18. struct class_member{};
  19. template<class Class,typename Type,Type Class::*PtrToMember>
  20. struct class_member2 : public marker{};
  21. TT_TEST_BEGIN(is_base_and_derived)
  22. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_and_derived<Derived,Base>::value), false);
  23. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_and_derived<Derived,Derived>::value), false);
  24. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_and_derived<Base,Base>::value), false);
  25. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_and_derived<const Base,Base>::value), false);
  26. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_and_derived<Base,Derived>::value), true);
  27. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_and_derived<Base,MultiBase>::value), true);
  28. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_and_derived<Derived,MultiBase>::value), true);
  29. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_and_derived<Derived2,MultiBase>::value), true);
  30. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_and_derived<Base,PrivateBase>::value), true);
  31. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_and_derived<NonDerived,Base>::value), false);
  32. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_and_derived<Base,void>::value), false);
  33. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_and_derived<Base,const void>::value), false);
  34. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_and_derived<void,Derived>::value), false);
  35. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_and_derived<const void,Derived>::value), false);
  36. #if defined(TEST_STD) && (TEST_STD < 2006)
  37. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_and_derived<int, int>::value), true);
  38. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_and_derived<const int, int>::value), true);
  39. #else
  40. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_and_derived<int, int>::value), false);
  41. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_and_derived<const int, int>::value), false);
  42. #endif
  43. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_and_derived<VB,VD>::value), true);
  44. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_and_derived<VD,VB>::value), false);
  45. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_and_derived<test_abc1,test_abc3>::value), true);
  46. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_and_derived<test_abc3,test_abc1>::value), false);
  47. typedef class_member<foo,int,&foo::x> mem_type;
  48. typedef class_member2<foo,int,&foo::x> mem2_type;
  49. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_and_derived<marker, mem_type>::value), false);
  50. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_and_derived<marker, mem2_type>::value), true);
  51. TT_TEST_END