1 | // |
---|---|
2 | // weak_from_raw_test5.cpp |
3 | // |
4 | // Tests whether pointers returned from weak_from_raw |
5 | // expire properly |
6 | // |
7 | // Copyright 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: public boost::enable_shared_from_raw |
20 | { |
21 | public: |
22 | |
23 | explicit X( boost::weak_ptr< X > & r ) |
24 | { |
25 | r = boost::weak_from_raw( p: this ); |
26 | } |
27 | }; |
28 | |
29 | int main() |
30 | { |
31 | boost::weak_ptr<X> p1, p2; |
32 | |
33 | { |
34 | boost::shared_ptr< X > px( new X( p1 ) ); |
35 | p2 = boost::weak_from_raw( p: px.get() ); |
36 | |
37 | BOOST_TEST( !p1.expired() ); |
38 | BOOST_TEST( !p2.expired() ); |
39 | } |
40 | |
41 | BOOST_TEST( p1.expired() ); |
42 | BOOST_TEST( p2.expired() ); |
43 | |
44 | return boost::report_errors(); |
45 | } |
46 |