1 #ifndef BOOST_SMART_PTR_SHARED_ARRAY_HPP_INCLUDED
\r
2 #define BOOST_SMART_PTR_SHARED_ARRAY_HPP_INCLUDED
\r
7 // (C) Copyright Greg Colvin and Beman Dawes 1998, 1999.
\r
8 // Copyright (c) 2001, 2002 Peter Dimov
\r
10 // Distributed under the Boost Software License, Version 1.0. (See
\r
11 // accompanying file LICENSE_1_0.txt or copy at
\r
12 // http://www.boost.org/LICENSE_1_0.txt)
\r
14 // See http://www.boost.org/libs/smart_ptr/shared_array.htm for documentation.
\r
17 #include <boost/config.hpp> // for broken compiler workarounds
\r
19 #if defined(BOOST_NO_MEMBER_TEMPLATES) && !defined(BOOST_MSVC6_MEMBER_TEMPLATES)
\r
20 #include <boost/smart_ptr/detail/shared_array_nmt.hpp>
\r
23 #include <memory> // TR1 cyclic inclusion fix
\r
25 #include <boost/assert.hpp>
\r
26 #include <boost/checked_delete.hpp>
\r
28 #include <boost/smart_ptr/detail/shared_count.hpp>
\r
29 #include <boost/detail/workaround.hpp>
\r
31 #include <cstddef> // for std::ptrdiff_t
\r
32 #include <algorithm> // for std::swap
\r
33 #include <functional> // for std::less
\r
41 // shared_array extends shared_ptr to arrays.
\r
42 // The array pointed to is deleted when the last shared_array pointing to it
\r
43 // is destroyed or reset.
\r
46 template<class T> class shared_array
\r
50 // Borland 5.5.1 specific workarounds
\r
51 typedef checked_array_deleter<T> deleter;
\r
52 typedef shared_array<T> this_type;
\r
56 typedef T element_type;
\r
58 explicit shared_array(T * p = 0): px(p), pn(p, deleter())
\r
63 // Requirements: D's copy constructor must not throw
\r
65 // shared_array will release p by calling d(p)
\r
68 template<class D> shared_array(T * p, D d): px(p), pn(p, d)
\r
72 // generated copy constructor, assignment, destructor are fine
\r
74 void reset(T * p = 0)
\r
76 BOOST_ASSERT(p == 0 || p != px);
\r
77 this_type(p).swap(*this);
\r
80 template <class D> void reset(T * p, D d)
\r
82 this_type(p, d).swap(*this);
\r
85 T & operator[] (std::ptrdiff_t i) const // never throws
\r
87 BOOST_ASSERT(px != 0);
\r
88 BOOST_ASSERT(i >= 0);
\r
92 T * get() const // never throws
\r
97 // implicit conversion to "bool"
\r
98 #include <boost/smart_ptr/detail/operator_bool.hpp>
\r
100 bool unique() const // never throws
\r
102 return pn.unique();
\r
105 long use_count() const // never throws
\r
107 return pn.use_count();
\r
110 void swap(shared_array<T> & other) // never throws
\r
112 std::swap(px, other.px);
\r
118 T * px; // contained pointer
\r
119 detail::shared_count pn; // reference counter
\r
123 template<class T> inline bool operator==(shared_array<T> const & a, shared_array<T> const & b) // never throws
\r
125 return a.get() == b.get();
\r
128 template<class T> inline bool operator!=(shared_array<T> const & a, shared_array<T> const & b) // never throws
\r
130 return a.get() != b.get();
\r
133 template<class T> inline bool operator<(shared_array<T> const & a, shared_array<T> const & b) // never throws
\r
135 return std::less<T*>()(a.get(), b.get());
\r
138 template<class T> void swap(shared_array<T> & a, shared_array<T> & b) // never throws
\r
143 } // namespace boost
\r
145 #endif // #if defined(BOOST_NO_MEMBER_TEMPLATES) && !defined(BOOST_MSVC6_MEMBER_TEMPLATES)
\r
147 #endif // #ifndef BOOST_SMART_PTR_SHARED_ARRAY_HPP_INCLUDED
\r