123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- #ifndef BOOST_SMART_PTR_SHARED_ARRAY_HPP_INCLUDED
- #define BOOST_SMART_PTR_SHARED_ARRAY_HPP_INCLUDED
- #include <boost/config.hpp>
- #if defined(BOOST_NO_MEMBER_TEMPLATES) && !defined(BOOST_MSVC6_MEMBER_TEMPLATES)
- #include <boost/smart_ptr/detail/shared_array_nmt.hpp>
- #else
- #include <memory>
- #include <boost/assert.hpp>
- #include <boost/checked_delete.hpp>
- #include <boost/smart_ptr/detail/shared_count.hpp>
- #include <boost/detail/workaround.hpp>
- #include <cstddef>
- #include <algorithm>
- #include <functional>
- namespace boost
- {
- template<class T> class shared_array
- {
- private:
-
- typedef checked_array_deleter<T> deleter;
- typedef shared_array<T> this_type;
- public:
- typedef T element_type;
- explicit shared_array(T * p = 0): px(p), pn(p, deleter())
- {
- }
-
-
-
-
-
- template<class D> shared_array(T * p, D d): px(p), pn(p, d)
- {
- }
- void reset(T * p = 0)
- {
- BOOST_ASSERT(p == 0 || p != px);
- this_type(p).swap(*this);
- }
- template <class D> void reset(T * p, D d)
- {
- this_type(p, d).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>
- bool unique() const
- {
- return pn.unique();
- }
- long use_count() const
- {
- return pn.use_count();
- }
- void swap(shared_array<T> & other)
- {
- std::swap(px, other.px);
- pn.swap(other.pn);
- }
- private:
- T * px;
- detail::shared_count pn;
- };
- template<class T> inline bool operator==(shared_array<T> const & a, shared_array<T> const & b)
- {
- return a.get() == b.get();
- }
- template<class T> inline bool operator!=(shared_array<T> const & a, shared_array<T> const & b)
- {
- return a.get() != b.get();
- }
- template<class T> inline bool operator<(shared_array<T> const & a, shared_array<T> const & b)
- {
- return std::less<T*>()(a.get(), b.get());
- }
- template<class T> void swap(shared_array<T> & a, shared_array<T> & b)
- {
- a.swap(b);
- }
- }
- #endif
- #endif
|