]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/smart_ptr/test/weak_from_raw_test4.cpp
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / boost / libs / smart_ptr / test / weak_from_raw_test4.cpp
1 //
2 // weak_from_raw_test4.cpp
3 //
4 // As weak_from_raw_test2.cpp, but uses weak_from_raw
5 // in the constructor
6 //
7 // Copyright (c) 2014, 2015 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 #include <boost/smart_ptr/enable_shared_from_raw.hpp>
16 #include <boost/weak_ptr.hpp>
17 #include <boost/core/lightweight_test.hpp>
18
19 class X;
20
21 static boost::weak_ptr< X > r_;
22
23 void register_( boost::weak_ptr< X > const & r )
24 {
25 r_ = r;
26 }
27
28 void check_( boost::weak_ptr< X > const & r )
29 {
30 BOOST_TEST( !( r < r_ ) && !( r_ < r ) );
31 }
32
33 void unregister_( boost::weak_ptr< X > const & r )
34 {
35 BOOST_TEST( !( r < r_ ) && !( r_ < r ) );
36 r_.reset();
37 }
38
39 class X: public boost::enable_shared_from_raw
40 {
41 public:
42
43 X()
44 {
45 register_( boost::weak_from_raw( this ) );
46 }
47
48 ~X()
49 {
50 unregister_( boost::weak_from_raw( this ) );
51 }
52
53 void check()
54 {
55 check_( boost::weak_from_raw( this ) );
56 }
57 };
58
59 int main()
60 {
61 {
62 boost::shared_ptr< X > px( new X );
63 px->check();
64 }
65
66 return boost::report_errors();
67 }