123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- #ifndef BOOST_SMART_PTR_SCOPED_ARRAY_HPP_INCLUDED
- #define BOOST_SMART_PTR_SCOPED_ARRAY_HPP_INCLUDED
- #include <boost/assert.hpp>
- #include <boost/checked_delete.hpp>
- #include <boost/config.hpp>
- #include <boost/detail/workaround.hpp>
- #include <cstddef>
- namespace boost
- {
- #if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
- void sp_array_constructor_hook(void * p);
- void sp_array_destructor_hook(void * p);
- #endif
- template<class T> class scoped_array
- {
- private:
- T * px;
- 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;
- explicit scoped_array( T * p = 0 ) : px( p )
- {
- #if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
- boost::sp_array_constructor_hook( px );
- #endif
- }
- ~scoped_array()
- {
- #if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
- boost::sp_array_destructor_hook( px );
- #endif
- boost::checked_array_delete( px );
- }
- void reset(T * p = 0)
- {
- BOOST_ASSERT( p == 0 || p != px );
- this_type(p).swap(*this);
- }
- T & operator[](std::ptrdiff_t i) const
- {
- BOOST_ASSERT( px != 0 );
- BOOST_ASSERT( i >= 0 );
- return px[i];
- }
- T * get() const
- {
- return px;
- }
- #include <boost/smart_ptr/detail/operator_bool.hpp>
- void swap(scoped_array & b)
- {
- T * tmp = b.px;
- b.px = px;
- px = tmp;
- }
- };
- template<class T> inline void swap(scoped_array<T> & a, scoped_array<T> & b)
- {
- a.swap(b);
- }
- }
- #endif
|