Go to the documentation of this file.00001 #ifndef BOOST_SMART_PTR_SHARED_ARRAY_HPP_INCLUDED
00002 #define BOOST_SMART_PTR_SHARED_ARRAY_HPP_INCLUDED
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include <boost/config.hpp>
00018
00019 #if defined(BOOST_NO_MEMBER_TEMPLATES) && !defined(BOOST_MSVC6_MEMBER_TEMPLATES)
00020 #include <boost/smart_ptr/detail/shared_array_nmt.hpp>
00021 #else
00022
00023 #include <memory>
00024
00025 #include <boost/assert.hpp>
00026 #include <boost/checked_delete.hpp>
00027
00028 #include <boost/smart_ptr/detail/shared_count.hpp>
00029 #include <boost/detail/workaround.hpp>
00030
00031 #include <cstddef>
00032 #include <algorithm>
00033 #include <functional>
00034
00035 namespace boost
00036 {
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 template<class T> class shared_array
00047 {
00048 private:
00049
00050
00051 typedef checked_array_deleter<T> deleter;
00052 typedef shared_array<T> this_type;
00053
00054 public:
00055
00056 typedef T element_type;
00057
00058 explicit shared_array(T * p = 0): px(p), pn(p, deleter())
00059 {
00060 }
00061
00062
00063
00064
00065
00066
00067
00068 template<class D> shared_array(T * p, D d): px(p), pn(p, d)
00069 {
00070 }
00071
00072
00073
00074 void reset(T * p = 0)
00075 {
00076 BOOST_ASSERT(p == 0 || p != px);
00077 this_type(p).swap(*this);
00078 }
00079
00080 template <class D> void reset(T * p, D d)
00081 {
00082 this_type(p, d).swap(*this);
00083 }
00084
00085 T & operator[] (std::ptrdiff_t i) const
00086 {
00087 BOOST_ASSERT(px != 0);
00088 BOOST_ASSERT(i >= 0);
00089 return px[i];
00090 }
00091
00092 T * get() const
00093 {
00094 return px;
00095 }
00096
00097
00098 #include <boost/smart_ptr/detail/operator_bool.hpp>
00099
00100 bool unique() const
00101 {
00102 return pn.unique();
00103 }
00104
00105 long use_count() const
00106 {
00107 return pn.use_count();
00108 }
00109
00110 void swap(shared_array<T> & other)
00111 {
00112 std::swap(px, other.px);
00113 pn.swap(other.pn);
00114 }
00115
00116 private:
00117
00118 T * px;
00119 detail::shared_count pn;
00120
00121 };
00122
00123 template<class T> inline bool operator==(shared_array<T> const & a, shared_array<T> const & b)
00124 {
00125 return a.get() == b.get();
00126 }
00127
00128 template<class T> inline bool operator!=(shared_array<T> const & a, shared_array<T> const & b)
00129 {
00130 return a.get() != b.get();
00131 }
00132
00133 template<class T> inline bool operator<(shared_array<T> const & a, shared_array<T> const & b)
00134 {
00135 return std::less<T*>()(a.get(), b.get());
00136 }
00137
00138 template<class T> void swap(shared_array<T> & a, shared_array<T> & b)
00139 {
00140 a.swap(b);
00141 }
00142
00143 }
00144
00145 #endif // #if defined(BOOST_NO_MEMBER_TEMPLATES) && !defined(BOOST_MSVC6_MEMBER_TEMPLATES)
00146
00147 #endif // #ifndef BOOST_SMART_PTR_SHARED_ARRAY_HPP_INCLUDED