pointer_to_other_test.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. //
  2. // pointer_to_other_test.cpp - a test for boost/pointer_to_other.hpp
  3. //
  4. // Copyright (c) 2005 Peter Dimov
  5. //
  6. // Distributed under the Boost Software License, Version 1.0. (See
  7. // accompanying file LICENSE_1_0.txt or copy at
  8. // http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. #include <boost/pointer_to_other.hpp>
  11. #include <boost/shared_ptr.hpp>
  12. #include <boost/shared_array.hpp>
  13. #include <boost/scoped_ptr.hpp>
  14. #include <boost/scoped_array.hpp>
  15. #include <boost/intrusive_ptr.hpp>
  16. #include <boost/config.hpp>
  17. #include <memory>
  18. template<class T, class U> void assert_same_type( T** pt = 0, U** pu = 0 )
  19. {
  20. pt = pu;
  21. }
  22. struct X;
  23. struct Y;
  24. int main()
  25. {
  26. // shared_ptr
  27. assert_same_type< boost::pointer_to_other< boost::shared_ptr<X>, Y >::type, boost::shared_ptr<Y> >();
  28. assert_same_type< boost::pointer_to_other< boost::shared_ptr<X>, void >::type, boost::shared_ptr<void> >();
  29. assert_same_type< boost::pointer_to_other< boost::shared_ptr<void>, Y >::type, boost::shared_ptr<Y> >();
  30. // shared_array
  31. assert_same_type< boost::pointer_to_other< boost::shared_array<X>, Y >::type, boost::shared_array<Y> >();
  32. assert_same_type< boost::pointer_to_other< boost::shared_array<X>, void >::type, boost::shared_array<void> >();
  33. assert_same_type< boost::pointer_to_other< boost::shared_array<void>, Y >::type, boost::shared_array<Y> >();
  34. // scoped_ptr
  35. assert_same_type< boost::pointer_to_other< boost::scoped_ptr<X>, Y >::type, boost::scoped_ptr<Y> >();
  36. assert_same_type< boost::pointer_to_other< boost::scoped_ptr<X>, void >::type, boost::scoped_ptr<void> >();
  37. assert_same_type< boost::pointer_to_other< boost::scoped_ptr<void>, Y >::type, boost::scoped_ptr<Y> >();
  38. // scoped_array
  39. assert_same_type< boost::pointer_to_other< boost::scoped_array<X>, Y >::type, boost::scoped_array<Y> >();
  40. assert_same_type< boost::pointer_to_other< boost::scoped_array<X>, void >::type, boost::scoped_array<void> >();
  41. assert_same_type< boost::pointer_to_other< boost::scoped_array<void>, Y >::type, boost::scoped_array<Y> >();
  42. // intrusive_ptr
  43. assert_same_type< boost::pointer_to_other< boost::intrusive_ptr<X>, Y >::type, boost::intrusive_ptr<Y> >();
  44. assert_same_type< boost::pointer_to_other< boost::intrusive_ptr<X>, void >::type, boost::intrusive_ptr<void> >();
  45. assert_same_type< boost::pointer_to_other< boost::intrusive_ptr<void>, Y >::type, boost::intrusive_ptr<Y> >();
  46. #if !defined( BOOST_NO_AUTO_PTR )
  47. // auto_ptr
  48. assert_same_type< boost::pointer_to_other< std::auto_ptr<X>, Y >::type, std::auto_ptr<Y> >();
  49. assert_same_type< boost::pointer_to_other< std::auto_ptr<X>, void >::type, std::auto_ptr<void> >();
  50. assert_same_type< boost::pointer_to_other< std::auto_ptr<void>, Y >::type, std::auto_ptr<Y> >();
  51. #endif
  52. // raw pointer
  53. assert_same_type< boost::pointer_to_other< X *, Y >::type, Y * >();
  54. assert_same_type< boost::pointer_to_other< X *, void >::type, void * >();
  55. assert_same_type< boost::pointer_to_other< void *, Y >::type, Y * >();
  56. return 0;
  57. }