shared_from_raw_test3.cpp 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. //
  2. // shared_from_raw_test3 - based on esft_second_ptr_test.cpp
  3. //
  4. // This test has been extracted from a real
  5. // scenario that occurs in Boost.Python
  6. //
  7. // Copyright 2009, 2014 Peter Dimov
  8. //
  9. // Distributed under the Boost Software License, Version 1.0.
  10. //
  11. // See accompanying file LICENSE_1_0.txt or copy at
  12. // http://www.boost.org/LICENSE_1_0.txt
  13. //
  14. #include <boost/smart_ptr/enable_shared_from_raw.hpp>
  15. #include <boost/shared_ptr.hpp>
  16. #include <boost/detail/lightweight_test.hpp>
  17. //
  18. class X: public boost::enable_shared_from_raw
  19. {
  20. };
  21. void null_deleter( void const* )
  22. {
  23. }
  24. int main()
  25. {
  26. boost::shared_ptr<X> px( new X );
  27. {
  28. boost::shared_ptr<X> px2( px.get(), null_deleter );
  29. BOOST_TEST( px == px2 );
  30. }
  31. try
  32. {
  33. boost::shared_ptr< X > qx = boost::shared_from_raw( px.get() );
  34. BOOST_TEST( px == qx );
  35. BOOST_TEST( !( px < qx ) && !( qx < px ) );
  36. }
  37. catch( boost::bad_weak_ptr const& )
  38. {
  39. BOOST_ERROR( "shared_from_raw( px.get() ) failed" );
  40. }
  41. return boost::report_errors();
  42. }