1 //
2 //  shared_from_raw_test4 - based on esft_void_test.cpp
3 //
4 //  Copyright 2009, 2014 Peter Dimov
5 //
6 //  Distributed under the Boost Software License, Version 1.0.
7 //
8 //  See accompanying file LICENSE_1_0.txt or copy at
9 //  http://www.boost.org/LICENSE_1_0.txt
10 //
11 
12 
13 #include <boost/smart_ptr/enable_shared_from_raw.hpp>
14 #include <boost/shared_ptr.hpp>
15 #include <boost/detail/lightweight_test.hpp>
16 
17 //
18 
19 class X: public boost::enable_shared_from_raw
20 {
21 };
22 
main()23 int main()
24 {
25     boost::shared_ptr< void const volatile > pv( new X );
26     boost::shared_ptr< void > pv2 = boost::const_pointer_cast< void >( pv );
27     boost::shared_ptr< X > px = boost::static_pointer_cast< X >( pv2 );
28 
29     try
30     {
31         boost::shared_ptr< X > qx = boost::shared_from_raw( px.get() );
32 
33         BOOST_TEST( px == qx );
34         BOOST_TEST( !( px < qx ) && !( qx < px ) );
35     }
36     catch( boost::bad_weak_ptr const& )
37     {
38         BOOST_ERROR( "shared_from_this( px.get() ) failed" );
39     }
40 
41     boost::shared_ptr< X const volatile > px2( px );
42 
43     try
44     {
45         boost::shared_ptr< X const volatile > qx2 = boost::shared_from_raw( px2.get() );
46 
47         BOOST_TEST( px2 == qx2 );
48         BOOST_TEST( !( px2 < qx2 ) && !( qx2 < px2 ) );
49     }
50     catch( boost::bad_weak_ptr const& )
51     {
52         BOOST_ERROR( "shared_from_this( px2.get() ) failed" );
53     }
54 
55     return boost::report_errors();
56 }
57