forked from boostorg/smart_ptr
Added a default constructor to shared_count and shared_ptr for incomplete types (void).
[SVN r12815]
This commit is contained in:
@@ -186,6 +186,10 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
shared_count(): pi_(new counted_base(1, 1))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
template<class P, class D> shared_count(P p, D d): pi_(0)
|
template<class P, class D> shared_count(P p, D d): pi_(0)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -221,7 +225,7 @@ public:
|
|||||||
pi_->add_ref();
|
pi_->add_ref();
|
||||||
}
|
}
|
||||||
|
|
||||||
explicit shared_count(weak_count const & r); // throws bad_weak_to_shared_cast when r.use_count() == 0
|
explicit shared_count(weak_count const & r); // throws use_count_is_zero when r.use_count() == 0
|
||||||
|
|
||||||
shared_count & operator= (shared_count const & r) // nothrow
|
shared_count & operator= (shared_count const & r) // nothrow
|
||||||
{
|
{
|
||||||
|
@@ -81,7 +81,11 @@ public:
|
|||||||
|
|
||||||
typedef T element_type;
|
typedef T element_type;
|
||||||
|
|
||||||
explicit shared_ptr(T * p = 0): px(p), pn(p, deleter())
|
shared_ptr(): px(0), pn()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
explicit shared_ptr(T * p): px(p), pn(p, deleter()) // requires complete type
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,9 +161,14 @@ public:
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void reset(T * p = 0)
|
void reset()
|
||||||
{
|
{
|
||||||
BOOST_ASSERT(p == 0 || p != px);
|
this_type().swap(*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void reset(T * p) // requires complete type
|
||||||
|
{
|
||||||
|
BOOST_ASSERT(p == 0 || p != px); // catch self-reset errors
|
||||||
this_type(p).swap(*this);
|
this_type(p).swap(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -40,6 +40,8 @@
|
|||||||
<h2><a name="Synopsis">Synopsis</a></h2>
|
<h2><a name="Synopsis">Synopsis</a></h2>
|
||||||
<pre>namespace boost {
|
<pre>namespace boost {
|
||||||
|
|
||||||
|
class use_count_is_zero: public std::exception;
|
||||||
|
|
||||||
template<typename T> class <A href="weak_ptr.htm" >weak_ptr</A>;
|
template<typename T> class <A href="weak_ptr.htm" >weak_ptr</A>;
|
||||||
|
|
||||||
template<typename T> class shared_ptr {
|
template<typename T> class shared_ptr {
|
||||||
@@ -47,20 +49,22 @@
|
|||||||
public:
|
public:
|
||||||
typedef T <A href="#element_type" >element_type</A>;
|
typedef T <A href="#element_type" >element_type</A>;
|
||||||
|
|
||||||
explicit <A href="#constructors" >shared_ptr</A>(T * p = 0);
|
<A href="#constructors" >shared_ptr</A> ();
|
||||||
|
explicit <A href="#constructors" >shared_ptr</A> (T * p); // requires complete type
|
||||||
template<typename D> <A href="#constructors" >shared_ptr</A>(T * p, D d);
|
template<typename D> <A href="#constructors" >shared_ptr</A>(T * p, D d);
|
||||||
<A href="#destructor" >~shared_ptr</A>(); // never throws
|
<A href="#destructor" >~shared_ptr</A>(); // never throws
|
||||||
|
|
||||||
<A href="#constructors" >shared_ptr</A>(shared_ptr const & r); // never throws
|
<A href="#constructors" >shared_ptr</A>(shared_ptr const & r); // never throws
|
||||||
template<typename Y> <A href="#constructors" >shared_ptr</A>(shared_ptr<Y> const & r); // never throws
|
template<typename Y> <A href="#constructors" >shared_ptr</A>(shared_ptr<Y> const & r); // never throws
|
||||||
<A href="#constructors" >shared_ptr</A>(<A href="weak_ptr.htm" >weak_ptr</A> const & r);
|
explicit <A href="#constructors" >shared_ptr</A>(<A href="weak_ptr.htm" >weak_ptr</A> const & r);
|
||||||
template<typename Y> <A href="#constructors" >shared_ptr</A>(std::auto_ptr<Y> & r);
|
template<typename Y> <A href="#constructors" >shared_ptr</A>(std::auto_ptr<Y> & r);
|
||||||
|
|
||||||
shared_ptr & <A href="#assignment" >operator=</A>(shared_ptr const & r); // never throws
|
shared_ptr & <A href="#assignment" >operator=</A>(shared_ptr const & r); // never throws
|
||||||
template<typename Y> shared_ptr & <A href="#assignment" >operator=</A>(shared_ptr<Y> const & r); // never throws
|
template<typename Y> shared_ptr & <A href="#assignment" >operator=</A>(shared_ptr<Y> const & r); // never throws
|
||||||
template<typename Y> shared_ptr & <A href="#assignment" >operator=</A>(std::auto_ptr<Y> & r);
|
template<typename Y> shared_ptr & <A href="#assignment" >operator=</A>(std::auto_ptr<Y> & r);
|
||||||
|
|
||||||
void <A href="#reset" >reset</A>(T * p = 0);
|
void <A href="#reset" >reset</A> ();
|
||||||
|
void <A href="#reset" >reset</A> (T * p); // requires complete type
|
||||||
template<typename D> void <A href="#reset" >reset</A>(T * p, D d);
|
template<typename D> void <A href="#reset" >reset</A>(T * p, D d);
|
||||||
|
|
||||||
T & <A href="#indirection" >operator*</A>() const; // never throws
|
T & <A href="#indirection" >operator*</A>() const; // never throws
|
||||||
@@ -99,7 +103,18 @@
|
|||||||
<p>Provides the type of the template parameter T.</p>
|
<p>Provides the type of the template parameter T.</p>
|
||||||
</blockquote>
|
</blockquote>
|
||||||
<h3><a name="constructors">constructors</a></h3>
|
<h3><a name="constructors">constructors</a></h3>
|
||||||
<pre>explicit shared_ptr(T * p = 0);</pre>
|
<pre>shared_ptr();</pre>
|
||||||
|
<blockquote>
|
||||||
|
<p><b>Effects:</b> Constructs a <b>shared_ptr</b>.</p>
|
||||||
|
<p><b>Postconditions:</b> <A href="#use_count">use count</A> is 1; the stored
|
||||||
|
pointer is 0.</p>
|
||||||
|
<p><b>Throws:</b> <b>std::bad_alloc</b>.</p>
|
||||||
|
<p><b>Exception safety:</b> If an exception is thrown, the constructor has no
|
||||||
|
effect.</p>
|
||||||
|
<P><B>Notes:</B> <B>T</B> need not be a complete type. See the smart pointer <A href="smart_ptr.htm#Common requirements">
|
||||||
|
common requirements</A>.</P>
|
||||||
|
</blockquote>
|
||||||
|
<pre>explicit shared_ptr(T * p);</pre>
|
||||||
<blockquote>
|
<blockquote>
|
||||||
<p><b>Requirements:</b> The expression <code>delete p</code> must be well-formed
|
<p><b>Requirements:</b> The expression <code>delete p</code> must be well-formed
|
||||||
and must not invoke undefined behavior.
|
and must not invoke undefined behavior.
|
||||||
@@ -136,7 +151,7 @@ template<typename Y> shared_ptr(shared_ptr<Y> const & r); // nev
|
|||||||
increased by one.</p>
|
increased by one.</p>
|
||||||
<p><b>Throws:</b> nothing.</p>
|
<p><b>Throws:</b> nothing.</p>
|
||||||
</blockquote>
|
</blockquote>
|
||||||
<pre>shared_ptr(<A href="weak_ptr.htm" >weak_ptr</A> const & r);</pre>
|
<pre>explicit shared_ptr(<A href="weak_ptr.htm" >weak_ptr</A> const & r);</pre>
|
||||||
<blockquote>
|
<blockquote>
|
||||||
<p><b>Effects:</b> Constructs a <b>shared_ptr</b>, as if by storing a copy of the
|
<p><b>Effects:</b> Constructs a <b>shared_ptr</b>, as if by storing a copy of the
|
||||||
pointer stored in <STRONG>r</STRONG>.</p>
|
pointer stored in <STRONG>r</STRONG>.</p>
|
||||||
@@ -174,11 +189,26 @@ template<typename Y> shared_ptr & operator=(shared_ptr<Y> const
|
|||||||
template<typename Y> shared_ptr & operator=(std::auto_ptr<Y> & r);</pre>
|
template<typename Y> shared_ptr & operator=(std::auto_ptr<Y> & r);</pre>
|
||||||
<BLOCKQUOTE>
|
<BLOCKQUOTE>
|
||||||
<P><B>Effects:</B> Equivalent to <code>shared_ptr(r).swap(*this)</code>.</P>
|
<P><B>Effects:</B> Equivalent to <code>shared_ptr(r).swap(*this)</code>.</P>
|
||||||
|
<P><B>Notes:</B> The implementation is free to meet the effects (and the implied
|
||||||
|
guarantees) via different means, without creating a temporary. In particular,
|
||||||
|
in the example:</P>
|
||||||
|
<pre>
|
||||||
|
shared_ptr<int> p(new int);
|
||||||
|
shared_ptr<void> q(p);
|
||||||
|
p = p;
|
||||||
|
q = p;
|
||||||
|
</pre>
|
||||||
|
<p>both assignments may be no-ops.</p>
|
||||||
</BLOCKQUOTE>
|
</BLOCKQUOTE>
|
||||||
<h3><a name="reset">reset</a></h3>
|
<h3><a name="reset">reset</a></h3>
|
||||||
<pre>void reset(T * p = 0);</pre>
|
<pre>void reset();</pre>
|
||||||
|
<BLOCKQUOTE>
|
||||||
|
<P><B>Effects:</B> Equivalent to <code>shared_ptr().swap(*this)</code>.</P>
|
||||||
|
</BLOCKQUOTE>
|
||||||
|
<pre>void reset(T * p);</pre>
|
||||||
<BLOCKQUOTE>
|
<BLOCKQUOTE>
|
||||||
<P><B>Effects:</B> Equivalent to <code>shared_ptr(p).swap(*this)</code>.</P>
|
<P><B>Effects:</B> Equivalent to <code>shared_ptr(p).swap(*this)</code>.</P>
|
||||||
|
<P><B>Notes:</B> Note the implied requirement that <b>T</b> is a complete type.</P>
|
||||||
</BLOCKQUOTE>
|
</BLOCKQUOTE>
|
||||||
<pre>template<typename D> void reset(T * p, D d);</pre>
|
<pre>template<typename D> void reset(T * p, D d);</pre>
|
||||||
<BLOCKQUOTE>
|
<BLOCKQUOTE>
|
||||||
|
Reference in New Issue
Block a user