1 #include <boost/config.hpp>
2 
3 //
4 //  weak_from_raw_test.cpp
5 //
6 //  Copyright (c) 2009 Frank Mori Hess
7 //
8 // Distributed under the Boost Software License, Version 1.0. (See
9 // accompanying file LICENSE_1_0.txt or copy at
10 // http://www.boost.org/LICENSE_1_0.txt)
11 //
12 
13 
14 #include <boost/smart_ptr/enable_shared_from_raw.hpp>
15 #include <boost/detail/lightweight_test.hpp>
16 
17 
18 struct X: public boost::enable_shared_from_raw
19 {};
20 
basic_weak_from_raw_test()21 void basic_weak_from_raw_test()
22 {
23     X *p(new X);
24     boost::weak_ptr<X> weak = boost::weak_from_raw(p);
25     BOOST_TEST(!weak.expired());
26     boost::shared_ptr<X> shared(p);
27     weak = boost::weak_from_raw(p);
28     BOOST_TEST(weak.expired() == false);
29     boost::shared_ptr<X> shared2(weak);
30     BOOST_TEST((shared < shared2 || shared2 < shared) == false);
31     BOOST_TEST(shared.get() == p);
32 }
33 
main()34 int main()
35 {
36     basic_weak_from_raw_test();
37     return boost::report_errors();
38 }
39