| 
									
										
										
										
											2009-03-01 16:00:42 +00:00
										 |  |  | #ifndef BOOST_SMART_PTR_SCOPED_ARRAY_HPP_INCLUDED
 | 
					
						
							|  |  |  | #define BOOST_SMART_PTR_SCOPED_ARRAY_HPP_INCLUDED
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //  (C) Copyright Greg Colvin and Beman Dawes 1998, 1999.
 | 
					
						
							|  |  |  | //  Copyright (c) 2001, 2002 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)
 | 
					
						
							|  |  |  | //
 | 
					
						
							| 
									
										
										
										
											2017-06-17 00:13:21 +03:00
										 |  |  | //  See http://www.boost.org/libs/smart_ptr/ for documentation.
 | 
					
						
							| 
									
										
										
										
											2009-03-01 16:00:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-11 18:35:21 +00:00
										 |  |  | #include <boost/config.hpp>
 | 
					
						
							| 
									
										
										
										
											2009-03-01 16:00:42 +00:00
										 |  |  | #include <boost/assert.hpp>
 | 
					
						
							| 
									
										
										
										
											2022-04-03 16:49:10 +01:00
										 |  |  | #include <boost/core/checked_delete.hpp>
 | 
					
						
							| 
									
										
										
										
											2013-01-09 23:41:31 +00:00
										 |  |  | #include <boost/smart_ptr/detail/sp_nullptr_t.hpp>
 | 
					
						
							| 
									
										
										
										
											2016-11-08 18:42:51 +02:00
										 |  |  | #include <boost/smart_ptr/detail/sp_noexcept.hpp>
 | 
					
						
							| 
									
										
										
										
											2009-03-01 16:00:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-01 08:29:47 -05:00
										 |  |  | #include <boost/config/workaround.hpp>
 | 
					
						
							| 
									
										
										
										
											2009-03-01 16:00:42 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include <cstddef>            // for std::ptrdiff_t
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace boost | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Debug hooks
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void sp_array_constructor_hook(void * p); | 
					
						
							|  |  |  | void sp_array_destructor_hook(void * p); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //  scoped_array extends scoped_ptr to arrays. Deletion of the array pointed to
 | 
					
						
							|  |  |  | //  is guaranteed, either on destruction of the scoped_array or via an explicit
 | 
					
						
							|  |  |  | //  reset(). Use shared_array or std::vector if your needs are more complex.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | template<class T> class scoped_array // noncopyable
 | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-02 16:45:22 +00:00
										 |  |  |     T * px; | 
					
						
							| 
									
										
										
										
											2009-03-01 16:00:42 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     scoped_array(scoped_array const &); | 
					
						
							|  |  |  |     scoped_array & operator=(scoped_array const &); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     typedef scoped_array<T> this_type; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     void operator==( scoped_array const& ) const; | 
					
						
							|  |  |  |     void operator!=( scoped_array const& ) const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     typedef T element_type; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-08 18:42:51 +02:00
										 |  |  |     explicit scoped_array( T * p = 0 ) BOOST_SP_NOEXCEPT : px( p ) | 
					
						
							| 
									
										
										
										
											2009-03-01 16:00:42 +00:00
										 |  |  |     { | 
					
						
							|  |  |  | #if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
 | 
					
						
							| 
									
										
										
										
											2009-03-02 16:45:22 +00:00
										 |  |  |         boost::sp_array_constructor_hook( px ); | 
					
						
							| 
									
										
										
										
											2009-03-01 16:00:42 +00:00
										 |  |  | #endif
 | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-12 18:06:54 +03:00
										 |  |  |     ~scoped_array() BOOST_SP_NOEXCEPT | 
					
						
							| 
									
										
										
										
											2009-03-01 16:00:42 +00:00
										 |  |  |     { | 
					
						
							|  |  |  | #if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
 | 
					
						
							| 
									
										
										
										
											2009-03-02 16:45:22 +00:00
										 |  |  |         boost::sp_array_destructor_hook( px ); | 
					
						
							| 
									
										
										
										
											2009-03-01 16:00:42 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2009-03-02 16:45:22 +00:00
										 |  |  |         boost::checked_array_delete( px ); | 
					
						
							| 
									
										
										
										
											2009-03-01 16:00:42 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-12 18:06:54 +03:00
										 |  |  |     void reset(T * p = 0) BOOST_SP_NOEXCEPT_WITH_ASSERT | 
					
						
							| 
									
										
										
										
											2009-03-01 16:00:42 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2009-03-02 16:45:22 +00:00
										 |  |  |         BOOST_ASSERT( p == 0 || p != px ); // catch self-reset errors
 | 
					
						
							| 
									
										
										
										
											2009-03-01 16:00:42 +00:00
										 |  |  |         this_type(p).swap(*this); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-12 18:06:54 +03:00
										 |  |  |     T & operator[](std::ptrdiff_t i) const BOOST_SP_NOEXCEPT_WITH_ASSERT | 
					
						
							| 
									
										
										
										
											2009-03-01 16:00:42 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2009-03-02 16:45:22 +00:00
										 |  |  |         BOOST_ASSERT( px != 0 ); | 
					
						
							|  |  |  |         BOOST_ASSERT( i >= 0 ); | 
					
						
							|  |  |  |         return px[i]; | 
					
						
							| 
									
										
										
										
											2009-03-01 16:00:42 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-12 18:06:54 +03:00
										 |  |  |     T * get() const BOOST_SP_NOEXCEPT | 
					
						
							| 
									
										
										
										
											2009-03-01 16:00:42 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2009-03-02 16:45:22 +00:00
										 |  |  |         return px; | 
					
						
							| 
									
										
										
										
											2009-03-01 16:00:42 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-02 16:45:22 +00:00
										 |  |  | // implicit conversion to "bool"
 | 
					
						
							|  |  |  | #include <boost/smart_ptr/detail/operator_bool.hpp>
 | 
					
						
							| 
									
										
										
										
											2009-03-01 16:00:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-12 18:06:54 +03:00
										 |  |  |     void swap(scoped_array & b) BOOST_SP_NOEXCEPT | 
					
						
							| 
									
										
										
										
											2009-03-01 16:00:42 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2009-03-02 16:45:22 +00:00
										 |  |  |         T * tmp = b.px; | 
					
						
							|  |  |  |         b.px = px; | 
					
						
							|  |  |  |         px = tmp; | 
					
						
							| 
									
										
										
										
											2009-03-01 16:00:42 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-11 18:35:21 +00:00
										 |  |  | #if !defined( BOOST_NO_CXX11_NULLPTR )
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-12 18:06:54 +03:00
										 |  |  | template<class T> inline bool operator==( scoped_array<T> const & p, boost::detail::sp_nullptr_t ) BOOST_SP_NOEXCEPT | 
					
						
							| 
									
										
										
										
											2012-12-11 18:35:21 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     return p.get() == 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-12 18:06:54 +03:00
										 |  |  | template<class T> inline bool operator==( boost::detail::sp_nullptr_t, scoped_array<T> const & p ) BOOST_SP_NOEXCEPT | 
					
						
							| 
									
										
										
										
											2012-12-11 18:35:21 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     return p.get() == 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-12 18:06:54 +03:00
										 |  |  | template<class T> inline bool operator!=( scoped_array<T> const & p, boost::detail::sp_nullptr_t ) BOOST_SP_NOEXCEPT | 
					
						
							| 
									
										
										
										
											2012-12-11 18:35:21 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     return p.get() != 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-12 18:06:54 +03:00
										 |  |  | template<class T> inline bool operator!=( boost::detail::sp_nullptr_t, scoped_array<T> const & p ) BOOST_SP_NOEXCEPT | 
					
						
							| 
									
										
										
										
											2012-12-11 18:35:21 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     return p.get() != 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-12 18:06:54 +03:00
										 |  |  | template<class T> inline void swap(scoped_array<T> & a, scoped_array<T> & b) BOOST_SP_NOEXCEPT | 
					
						
							| 
									
										
										
										
											2009-03-01 16:00:42 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     a.swap(b); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } // namespace boost
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif  // #ifndef BOOST_SMART_PTR_SCOPED_ARRAY_HPP_INCLUDED
 |