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
15
16#include <boost/smart_ptr/enable_shared_from_raw.hpp>
17#include <boost/shared_ptr.hpp>
18#include <boost/core/lightweight_test.hpp>
19
20//
21
22class X: public boost::enable_shared_from_raw
23{
24};
25
26void null_deleter( void const* )
27{
28}
29
30int main()
31{
32 boost::shared_ptr<X> px( new X );
33
34 {
35 boost::shared_ptr<X> px2( px.get(), null_deleter );
36 BOOST_TEST( px == px2 );
37 }
38
39 try
40 {
41 boost::shared_ptr< X > qx = boost::shared_from_raw( p: px.get() );
42
43 BOOST_TEST( px == qx );
44 BOOST_TEST( !( px < qx ) && !( qx < px ) );
45 }
46 catch( boost::bad_weak_ptr const& )
47 {
48 BOOST_ERROR( "shared_from_raw( px.get() ) failed" );
49 }
50
51 return boost::report_errors();
52}
53

source code of boost/libs/smart_ptr/test/shared_from_raw_test3.cpp