1 // Copyright 2005 Ben Hutchings <ben@decadent.org.uk>.
2 // See the file "COPYING" for licence details.
4 #ifndef INC_AUTO_ARRAY_HPP
5 #define INC_AUTO_ARRAY_HPP
9 // Like auto_ptr, but for arrays
11 template<typename element_type>
14 template<typename element_type>
17 typedef auto_array_ref<element_type> ref_type;
22 explicit auto_array(element_type * ptr)
25 auto_array(ref_type other)
26 : ptr_(other.release())
28 auto_array & operator=(auto_array & other)
30 reset(other.release());
36 element_type * get() const
40 element_type * release()
42 element_type * ptr(ptr_);
46 void reset(element_type * ptr = 0)
51 element_type & operator[](std::ptrdiff_t index)
57 return ref_type(*this);
63 template<typename element_type>
66 typedef auto_array<element_type> target_type;
68 explicit auto_array_ref(target_type & target)
71 element_type * release()
73 return target_.release();
76 target_type & target_;
79 #endif // !INC_AUTO_ARRAY_HPP