1 #ifndef BOOST_SCOPED_ARRAY_HPP_INCLUDED
2 #define BOOST_SCOPED_ARRAY_HPP_INCLUDED
4 // (C) Copyright Greg Colvin and Beman Dawes 1998, 1999.
5 // Copyright (c) 2001, 2002 Peter Dimov
7 // Permission to copy, use, modify, sell and distribute this software
8 // is granted provided this copyright notice appears in all copies.
9 // This software is provided "as is" without express or implied
10 // warranty, and with no claim as to its suitability for any purpose.
12 // See http://www.boost.org/libs/smart_ptr/scoped_array.htm for documentation.
15 #include <boost/assert.hpp>
16 #include <boost/checked_delete.hpp>
17 #include <boost/config.hpp> // in case ptrdiff_t not in std
18 #include <cstddef> // for std::ptrdiff_t
23 // scoped_array extends scoped_ptr to arrays. Deletion of the array pointed to
24 // is guaranteed, either on destruction of the scoped_array or via an explicit
25 // reset(). Use shared_array or std::vector if your needs are more complex.
27 template<typename T> class scoped_array // noncopyable
33 scoped_array(scoped_array const &);
34 scoped_array & operator=(scoped_array const &);
36 typedef scoped_array<T> this_type;
40 typedef T element_type;
42 explicit scoped_array(T * p = 0) : ptr(p) // never throws
46 ~scoped_array() // never throws
48 checked_array_delete(ptr);
51 void reset(T * p = 0) // never throws
55 checked_array_delete(ptr);
60 T & operator[](std::ptrdiff_t i) const // never throws
62 BOOST_ASSERT(ptr != 0);
67 T * get() const // never throws
72 // implicit conversion to "bool"
74 typedef T * (this_type::*unspecified_bool_type)() const;
76 operator unspecified_bool_type() const // never throws
78 return ptr == 0? 0: &this_type::get;
81 bool operator! () const // never throws
86 void swap(scoped_array & b) // never throws
95 template<class T> inline void swap(scoped_array<T> & a, scoped_array<T> & b) // never throws
102 #endif // #ifndef BOOST_SCOPED_ARRAY_HPP_INCLUDED