1 #include <boost/config.hpp>
3 #if defined(BOOST_MSVC)
5 #pragma warning(disable: 4786) // identifier truncated in debug info
6 #pragma warning(disable: 4710) // function not inlined
7 #pragma warning(disable: 4711) // function selected for automatic inline expansion
8 #pragma warning(disable: 4514) // unreferenced inline removed
9 #pragma warning(disable: 4355) // 'this' : used in base member initializer list
10 #pragma warning(disable: 4511) // copy constructor could not be generated
11 #pragma warning(disable: 4512) // assignment operator could not be generated
13 #if (BOOST_MSVC >= 1310)
14 #pragma warning(disable: 4675) // resolved overload found with Koenig lookup
20 // intrusive_ptr_move_test.cpp
22 // Copyright (c) 2002-2005 Peter Dimov
24 // Distributed under the Boost Software License, Version 1.0. (See
25 // accompanying file LICENSE_1_0.txt or copy at
26 // http://www.boost.org/LICENSE_1_0.txt)
29 #include <boost/detail/lightweight_test.hpp>
30 #include <boost/intrusive_ptr.hpp>
31 #include <boost/detail/atomic_count.hpp>
32 #include <boost/config.hpp>
35 #if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
44 boost::detail::atomic_count use_count_;
47 base & operator=(base const &);
63 static long instances;
65 long use_count() const
70 #if !defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP)
72 inline friend void intrusive_ptr_add_ref(base * p)
77 inline friend void intrusive_ptr_release(base * p)
79 if(--p->use_count_ == 0) delete p;
91 if(--use_count_ == 0) delete this;
97 long base::instances = 0;
101 #if defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP)
106 inline void intrusive_ptr_add_ref(N::base * p)
111 inline void intrusive_ptr_release(N::base * p)
122 struct X: public virtual N::base
132 BOOST_TEST( N::base::instances == 0 );
135 boost::intrusive_ptr<X> p( new X );
136 BOOST_TEST( N::base::instances == 1 );
138 boost::intrusive_ptr<X> p2( std::move( p ) );
139 BOOST_TEST( N::base::instances == 1 );
140 BOOST_TEST( p.get() == 0 );
143 BOOST_TEST( N::base::instances == 0 );
147 boost::intrusive_ptr<X> p( new X );
148 BOOST_TEST( N::base::instances == 1 );
150 boost::intrusive_ptr<X> p2;
152 BOOST_TEST( N::base::instances == 1 );
153 BOOST_TEST( p.get() == 0 );
156 BOOST_TEST( N::base::instances == 0 );
160 boost::intrusive_ptr<X> p( new X );
161 BOOST_TEST( N::base::instances == 1 );
163 boost::intrusive_ptr<X> p2( new X );
164 BOOST_TEST( N::base::instances == 2 );
166 BOOST_TEST( N::base::instances == 1 );
167 BOOST_TEST( p.get() == 0 );
170 BOOST_TEST( N::base::instances == 0 );
173 return boost::report_errors();
176 #else // defined( BOOST_NO_CXX11_RVALUE_REFERENCES )