#include <boost/assert.hpp>
#include <boost/checked_delete.hpp>
-
+#include <boost/throw_exception.hpp>
#include <boost/detail/shared_count.hpp>
#include <memory> // for std::auto_ptr
public:
typedef T element_type;
+ typedef T value_type;
shared_ptr(): px(0), pn()
{
template<typename Y>
shared_ptr(shared_ptr<Y> const & r, detail::dynamic_cast_tag): px(dynamic_cast<element_type *>(r.px)), pn(r.pn)
{
- if (px == 0) // need to allocate new counter -- the cast failed
- {
- pn = detail::shared_count();
- }
+ if (px == 0) // need to allocate new counter -- the cast failed
+ {
+ pn = detail::shared_count();
+ }
}
template<typename Y>
shared_ptr(shared_ptr<Y> const & r, detail::polymorphic_cast_tag): px(dynamic_cast<element_type *>(r.px)), pn(r.pn)
{
- if (px == 0)
- {
- throw std::bad_cast();
- }
+ if (px == 0)
+ {
+ boost::throw_exception(std::bad_cast());
+ }
}
#ifndef BOOST_NO_AUTO_PTR
template<typename Y>
shared_ptr & operator=(shared_ptr<Y> const & r) // never throws
{
- px = r.px;
- pn = r.pn; // shared_count::op= doesn't throw
- return *this;
+ px = r.px;
+ pn = r.pn; // shared_count::op= doesn't throw
+ return *this;
}
#endif
template<typename Y>
shared_ptr & operator=(std::auto_ptr<Y> & r)
{
- this_type(r).swap(*this);
- return *this;
+ this_type(r).swap(*this);
+ return *this;
}
#endif
void reset()
{
- this_type().swap(*this);
+ this_type().swap(*this);
}
template<typename Y> void reset(Y * p) // Y must be complete
{
- BOOST_ASSERT(p == 0 || p != px); // catch self-reset errors
- this_type(p).swap(*this);
+ BOOST_ASSERT(p == 0 || p != px); // catch self-reset errors
+ this_type(p).swap(*this);
}
template<typename Y, typename D> void reset(Y * p, D d)
{
- this_type(p, d).swap(*this);
+ this_type(p, d).swap(*this);
}
typename detail::shared_ptr_traits<T>::reference operator* () const // never throws
{
- BOOST_ASSERT(px != 0);
- return *px;
+ BOOST_ASSERT(px != 0);
+ return *px;
}
T * operator-> () const // never throws
{
- BOOST_ASSERT(px != 0);
- return px;
+ BOOST_ASSERT(px != 0);
+ return px;
}
-
+
T * get() const // never throws
{
- return px;
+ return px;
}
// implicit conversion to "bool"
operator unspecified_bool_type() const // never throws
{
- return px == 0? 0: &this_type::get;
+ return px == 0? 0: &this_type::get;
}
bool operator! () const // never throws
{
- return px == 0;
+ return px == 0;
}
bool unique() const // never throws
{
- return pn.unique();
+ return pn.unique();
}
long use_count() const // never throws
{
- return pn.use_count();
+ return pn.use_count();
}
void swap(shared_ptr<T> & other) // never throws
{
- std::swap(px, other.px);
- pn.swap(other.pn);
+ std::swap(px, other.px);
+ pn.swap(other.pn);
}
// Tasteless as this may seem, making all members public allows member templates
#ifdef BOOST_MSVC
# pragma warning(pop)
-#endif
+#endif
#endif // #if defined(BOOST_NO_MEMBER_TEMPLATES) && !defined(BOOST_MSVC6_MEMBER_TEMPLATES)