From 5a6cd1cf3ee66077dc14ca17a421f6869859197d Mon Sep 17 00:00:00 2001
From: Peter Dimov Provides the type of the template parameter T. Effects: Constructs a shared_ptr. Postconditions: use count is 1; the stored
+ pointer is 0. Throws: std::bad_alloc. Exception safety: If an exception is thrown, the constructor has no
+ effect. Notes: T need not be a complete type. See the smart pointer
+ common requirements. Requirements: The expression Throws: nothing. Effects: Constructs a shared_ptr, as if by storing a copy of the
pointer stored in r. Effects: Equivalent to Notes: The implementation is free to meet the effects (and the implied
+ guarantees) via different means, without creating a temporary. In particular,
+ in the example: both assignments may be no-ops. Effects: Equivalent to Effects: Equivalent to Notes: Note the implied requirement that T is a complete type. Requires: The expression Synopsis
namespace boost {
+ class use_count_is_zero: public std::exception;
+
template<typename T> class weak_ptr;
template<typename T> class shared_ptr {
@@ -47,20 +49,22 @@
public:
typedef T element_type;
- explicit shared_ptr(T * p = 0);
+ shared_ptr ();
+ explicit shared_ptr (T * p); // requires complete type
template<typename D> shared_ptr(T * p, D d);
~shared_ptr(); // never throws
shared_ptr(shared_ptr const & r); // never throws
template<typename Y> shared_ptr(shared_ptr<Y> const & r); // never throws
- shared_ptr(weak_ptr const & r);
+ explicit shared_ptr(weak_ptr const & r);
template<typename Y> shared_ptr(std::auto_ptr<Y> & r);
shared_ptr & operator=(shared_ptr const & r); // never throws
template<typename Y> shared_ptr & operator=(shared_ptr<Y> const & r); // never throws
template<typename Y> shared_ptr & operator=(std::auto_ptr<Y> & r);
- void reset(T * p = 0);
+ void reset ();
+ void reset (T * p); // requires complete type
template<typename D> void reset(T * p, D d);
T & operator*() const; // never throws
@@ -99,7 +103,18 @@
constructors
- explicit shared_ptr(T * p = 0);
+ shared_ptr();
+
+
+ explicit shared_ptr(T * p);
- delete p
must be well-formed
and must not invoke undefined behavior.
@@ -136,7 +151,7 @@ template<typename Y> shared_ptr(shared_ptr<Y> const & r); // nev
increased by one.shared_ptr(weak_ptr const & r);
+ explicit shared_ptr(weak_ptr const & r);
shared_ptr(r).swap(*this)
.
+shared_ptr<int> p(new int);
+shared_ptr<void> q(p);
+p = p;
+q = p;
+
+ reset
- void reset(T * p = 0);
+ void reset();
+
+
+ shared_ptr().swap(*this)
.void reset(T * p);
shared_ptr(p).swap(*this)
.template<typename D> void reset(T * p, D d);
@@ -312,8 +342,8 @@ template<typename Y> shared_ptr & operator=(std::auto_ptr<Y> &am
shared_ptr<T> shared_polymorphic_cast(shared_ptr<U> const & r);
- polymorphic_cast<T*>(r.get())
must be well-formed and
- its behavior defined.
Returns: A shared_ptr<T> object that stores a copy
of polymorphic_cast<T*>(r.get())
and shares ownership with r.
Requires: The expression
+ polymorphic_downcast<T*>(r.get()) must be well-formed + and its behavior defined.- polymorphic_downcast<T*>(r.get())
must be well-formed - and its behavior defined.Returns: A shared_ptr<T> object that stores a copy of
polymorphic_downcast<T*>(r.get())
and shares ownership with r.