1 #ifndef BOOST_SMART_PTR_SCOPED_ARRAY_HPP_INCLUDED
2 #define BOOST_SMART_PTR_SCOPED_ARRAY_HPP_INCLUDED
4 // (C) Copyright Greg Colvin and Beman Dawes 1998, 1999.
5 // Copyright (c) 2001, 2002 Peter Dimov
7 // Distributed under the Boost Software License, Version 1.0. (See
8 // accompanying file LICENSE_1_0.txt or copy at
9 // http://www.boost.org/LICENSE_1_0.txt)
11 // See http://www.boost.org/libs/smart_ptr/ for documentation.
13 #include <boost/config.hpp>
14 #include <boost/assert.hpp>
15 #include <boost/checked_delete.hpp>
16 #include <boost/smart_ptr/detail/sp_nullptr_t.hpp>
17 #include <boost/smart_ptr/detail/sp_noexcept.hpp>
19 #include <boost/detail/workaround.hpp>
21 #include <cstddef> // for std::ptrdiff_t
28 #if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
30 void sp_array_constructor_hook(void * p);
31 void sp_array_destructor_hook(void * p);
35 // scoped_array extends scoped_ptr to arrays. Deletion of the array pointed to
36 // is guaranteed, either on destruction of the scoped_array or via an explicit
37 // reset(). Use shared_array or std::vector if your needs are more complex.
39 template<class T> class scoped_array // noncopyable
45 scoped_array(scoped_array const &);
46 scoped_array & operator=(scoped_array const &);
48 typedef scoped_array<T> this_type;
50 void operator==( scoped_array const& ) const;
51 void operator!=( scoped_array const& ) const;
55 typedef T element_type;
57 explicit scoped_array( T * p = 0 ) BOOST_SP_NOEXCEPT : px( p )
59 #if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
60 boost::sp_array_constructor_hook( px );
64 ~scoped_array() BOOST_SP_NOEXCEPT
66 #if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
67 boost::sp_array_destructor_hook( px );
69 boost::checked_array_delete( px );
72 void reset(T * p = 0) BOOST_SP_NOEXCEPT_WITH_ASSERT
74 BOOST_ASSERT( p == 0 || p != px ); // catch self-reset errors
75 this_type(p).swap(*this);
78 T & operator[](std::ptrdiff_t i) const BOOST_SP_NOEXCEPT_WITH_ASSERT
80 BOOST_ASSERT( px != 0 );
81 BOOST_ASSERT( i >= 0 );
85 T * get() const BOOST_SP_NOEXCEPT
90 // implicit conversion to "bool"
91 #include <boost/smart_ptr/detail/operator_bool.hpp>
93 void swap(scoped_array & b) BOOST_SP_NOEXCEPT
101 #if !defined( BOOST_NO_CXX11_NULLPTR )
103 template<class T> inline bool operator==( scoped_array<T> const & p, boost::detail::sp_nullptr_t ) BOOST_SP_NOEXCEPT
108 template<class T> inline bool operator==( boost::detail::sp_nullptr_t, scoped_array<T> const & p ) BOOST_SP_NOEXCEPT
113 template<class T> inline bool operator!=( scoped_array<T> const & p, boost::detail::sp_nullptr_t ) BOOST_SP_NOEXCEPT
118 template<class T> inline bool operator!=( boost::detail::sp_nullptr_t, scoped_array<T> const & p ) BOOST_SP_NOEXCEPT
125 template<class T> inline void swap(scoped_array<T> & a, scoped_array<T> & b) BOOST_SP_NOEXCEPT
132 #endif // #ifndef BOOST_SMART_PTR_SCOPED_ARRAY_HPP_INCLUDED