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>
36 #if defined( BOOST_HAS_RVALUE_REFS )
45 boost::detail::atomic_count use_count_;
48 base & operator=(base const &);
64 static long instances;
66 long use_count() const
71 #if !defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP)
73 inline friend void intrusive_ptr_add_ref(base * p)
78 inline friend void intrusive_ptr_release(base * p)
80 if(--p->use_count_ == 0) delete p;
92 if(--use_count_ == 0) delete this;
98 long base::instances = 0;
102 #if defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP)
107 inline void intrusive_ptr_add_ref(N::base * p)
112 inline void intrusive_ptr_release(N::base * p)
123 struct X: public virtual N::base
133 BOOST_TEST( N::base::instances == 0 );
136 boost::intrusive_ptr<X> p( new X );
137 BOOST_TEST( N::base::instances == 1 );
139 boost::intrusive_ptr<X> p2( std::move( p ) );
140 BOOST_TEST( N::base::instances == 1 );
141 BOOST_TEST( p.get() == 0 );
144 BOOST_TEST( N::base::instances == 0 );
148 boost::intrusive_ptr<X> p( new X );
149 BOOST_TEST( N::base::instances == 1 );
151 boost::intrusive_ptr<X> p2;
153 BOOST_TEST( N::base::instances == 1 );
154 BOOST_TEST( p.get() == 0 );
157 BOOST_TEST( N::base::instances == 0 );
161 boost::intrusive_ptr<X> p( new X );
162 BOOST_TEST( N::base::instances == 1 );
164 boost::intrusive_ptr<X> p2( new X );
165 BOOST_TEST( N::base::instances == 2 );
167 BOOST_TEST( N::base::instances == 1 );
168 BOOST_TEST( p.get() == 0 );
171 BOOST_TEST( N::base::instances == 0 );
174 return boost::report_errors();
177 #else // !defined( BOOST_HAS_RVALUE_REFS )