esft_void_test.cpp 940 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. //
  2. // esft_void_test.cpp
  3. //
  4. // Copyright 2009 Peter Dimov
  5. //
  6. // Distributed under the Boost Software License, Version 1.0.
  7. // See accompanying file LICENSE_1_0.txt or copy at
  8. // http://www.boost.org/LICENSE_1_0.txt
  9. //
  10. #include <boost/enable_shared_from_this.hpp>
  11. #include <boost/shared_ptr.hpp>
  12. #include <boost/detail/lightweight_test.hpp>
  13. //
  14. class X: public boost::enable_shared_from_this<X>
  15. {
  16. };
  17. int main()
  18. {
  19. boost::shared_ptr< void const volatile > pv( new X );
  20. boost::shared_ptr< void > pv2 = boost::const_pointer_cast< void >( pv );
  21. boost::shared_ptr< X > px = boost::static_pointer_cast< X >( pv2 );
  22. try
  23. {
  24. boost::shared_ptr< X > qx = px->shared_from_this();
  25. BOOST_TEST( px == qx );
  26. BOOST_TEST( !( px < qx ) && !( qx < px ) );
  27. }
  28. catch( boost::bad_weak_ptr const& )
  29. {
  30. BOOST_ERROR( "px->shared_from_this() failed" );
  31. }
  32. return boost::report_errors();
  33. }