| 
									
										
										
										
											2009-03-10 18:26:57 +00:00
										 |  |  | //
 | 
					
						
							|  |  |  | //  sp_recursive_assign2_rv_test.cpp
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //  Copyright 2009 Peter Dimov
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //  Distributed under the Boost Software License, Version 1.0.
 | 
					
						
							|  |  |  | //  See accompanying file LICENSE_1_0.txt or copy at
 | 
					
						
							|  |  |  | //  http://www.boost.org/LICENSE_1_0.txt
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <boost/shared_ptr.hpp>
 | 
					
						
							| 
									
										
										
										
											2020-01-01 08:29:47 -05:00
										 |  |  | #include <boost/core/lightweight_test.hpp>
 | 
					
						
							| 
									
										
										
										
											2009-03-10 18:26:57 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class X | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     static int instances; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     X() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         ++instances; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ~X() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         --instances; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     X( X const& ); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int X::instances = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class Y | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     static int instances; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     Y() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         ++instances; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ~Y() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         --instances; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     Y( Y const& ); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int Y::instances = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static boost::shared_ptr<void> s_pv; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class Z | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     static int instances; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     Z() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         ++instances; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ~Z() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         --instances; | 
					
						
							|  |  |  |         s_pv = boost::shared_ptr<Y>( new Y ); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     Z( Z const& ); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int Z::instances = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int main() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     BOOST_TEST( X::instances == 0 ); | 
					
						
							|  |  |  |     BOOST_TEST( Y::instances == 0 ); | 
					
						
							|  |  |  |     BOOST_TEST( Z::instances == 0 ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     s_pv = boost::shared_ptr<Z>( new Z ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     BOOST_TEST( X::instances == 0 ); | 
					
						
							|  |  |  |     BOOST_TEST( Y::instances == 0 ); | 
					
						
							|  |  |  |     BOOST_TEST( Z::instances == 1 ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     s_pv = boost::shared_ptr<X>( new X ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     BOOST_TEST( X::instances == 0 ); | 
					
						
							|  |  |  |     BOOST_TEST( Y::instances == 1 ); | 
					
						
							|  |  |  |     BOOST_TEST( Z::instances == 0 ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     s_pv = boost::shared_ptr<Y>(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     BOOST_TEST( X::instances == 0 ); | 
					
						
							|  |  |  |     BOOST_TEST( Y::instances == 0 ); | 
					
						
							|  |  |  |     BOOST_TEST( Z::instances == 0 ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return boost::report_errors(); | 
					
						
							|  |  |  | } |