Changeset 81781


Ignore:
Timestamp:
Dec 8, 2012, 12:57:04 AM (6 years ago)
Author:
Peter Dimov
Message:

Merged revision(s) 81730-81731, 81776 from trunk:
Fix get_pointer for the array case, add operator= for unique_ptr, update auto_ptr signatures to use rvalue reference when available.
........
Update shared_ptr.htm.
........
Add more unique_ptr tests.
........

Location:
branches/release
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • branches/release

  • branches/release/boost

  • branches/release/boost/smart_ptr

  • branches/release/boost/smart_ptr/shared_ptr.hpp

    r81715 r81781  
    419419
    420420    template<class Y>
    421     explicit shared_ptr(std::auto_ptr<Y> & r): px(r.get()), pn()
     421    explicit shared_ptr( std::auto_ptr<Y> & r ): px(r.get()), pn()
    422422    {
    423423        boost::detail::sp_assert_convertible< Y, T >();
    424424
    425425        Y * tmp = r.get();
    426         pn = boost::detail::shared_count(r);
     426        pn = boost::detail::shared_count( r );
    427427
    428428        boost::detail::sp_deleter_construct( this, tmp );
    429429    }
    430430
    431 #if !defined( BOOST_NO_SFINAE ) && !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
     431#if defined( BOOST_HAS_RVALUE_REFS )
     432
     433    template<class Y>
     434    shared_ptr( std::auto_ptr<Y> && r ): px(r.get()), pn()
     435    {
     436        boost::detail::sp_assert_convertible< Y, T >();
     437
     438        Y * tmp = r.get();
     439        pn = boost::detail::shared_count( r );
     440
     441        boost::detail::sp_deleter_construct( this, tmp );
     442    }
     443
     444#elif !defined( BOOST_NO_SFINAE ) && !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
    432445
    433446    template<class Ap>
     
    487500    shared_ptr & operator=( std::auto_ptr<Y> & r )
    488501    {
    489         this_type(r).swap(*this);
     502        this_type( r ).swap( *this );
    490503        return *this;
    491504    }
    492505
    493 #if !defined( BOOST_NO_SFINAE ) && !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
     506#if defined( BOOST_HAS_RVALUE_REFS )
     507
     508    template<class Y>
     509    shared_ptr & operator=( std::auto_ptr<Y> && r )
     510    {
     511        this_type( static_cast< std::auto_ptr<Y> && >( r ) ).swap( *this );
     512        return *this;
     513    }
     514
     515#elif !defined( BOOST_NO_SFINAE ) && !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
    494516
    495517    template<class Ap>
     
    503525
    504526#endif // BOOST_NO_AUTO_PTR
     527
     528#if !defined( BOOST_NO_CXX11_SMART_PTR )
     529
     530    template<class Y, class D>
     531    shared_ptr & operator=( std::unique_ptr<Y, D> && r )
     532    {
     533        this_type( static_cast< std::unique_ptr<Y, D> && >( r ) ).swap(*this);
     534        return *this;
     535    }
     536
     537#endif
    505538
    506539// Move support
     
    731764// get_pointer() enables boost::mem_fn to recognize shared_ptr
    732765
    733 template<class T> inline T * get_pointer(shared_ptr<T> const & p) BOOST_NOEXCEPT
     766template<class T> inline typename shared_ptr<T>::element_type * get_pointer(shared_ptr<T> const & p) BOOST_NOEXCEPT
    734767{
    735768    return p.get();
  • branches/release/libs

  • branches/release/libs/smart_ptr

  • branches/release/libs/smart_ptr/shared_ptr.htm

    r51703 r81781  
    33        <head>
    44                <title>shared_ptr</title>
    5                 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
     5                <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    66        </head>
    7         <body text="#000000" bgColor="#ffffff">
    8                 <h1><A href="../../index.htm"><IMG height="86" alt="boost.png (6897 bytes)" src="../../boost.png" width="277" align="middle"
    9                                         border="0"></A>shared_ptr class template</h1>
    10                 <p><A href="#Introduction">Introduction</A><br>
    11                         <A href="#BestPractices">Best Practices</A><br>
    12                         <A href="#Synopsis">Synopsis</A><br>
    13                         <A href="#Members">Members</A><br>
    14                         <A href="#functions">Free Functions</A><br>
    15                         <A href="#example">Example</A><br>
    16                         <A href="#Handle/Body">Handle/Body Idiom</A><br>
    17                         <A href="#ThreadSafety">Thread Safety</A><br>
    18                         <A href="#FAQ">Frequently Asked Questions</A><br>
    19                         <A href="smarttests.htm">Smart Pointer Timings</A><br>
    20                         <A href="sp_techniques.html">Programming Techniques</A></p>
    21                 <h2><a name="Introduction">Introduction</a></h2>
    22                 <p>The <b>shared_ptr</b> class template stores a pointer to a dynamically allocated
    23                         object, typically with a C++ <EM>new-expression</EM>. The object pointed to is
    24                         guaranteed to be deleted when the last <b>shared_ptr</b> pointing to it is
    25                         destroyed or reset. See the <A href="#example">example</A>.</p>
    26                 <p>Every <b>shared_ptr</b> meets the <b>CopyConstructible</b> and <b>Assignable</b>
    27                         requirements of the C++ Standard Library, and so can be used in standard
    28                         library containers. Comparison operators are supplied so that <b>shared_ptr</b>
     7        <body>
     8                <h1>boost::shared_ptr class template</h1>
     9                <p><a href="#Introduction">Introduction</a><br />
     10                        <a href="#BestPractices">Best Practices</a><br />
     11                        <a href="#Synopsis">Synopsis</a><br />
     12                        <a href="#Members">Members</a><br />
     13                        <a href="#functions">Free Functions</a><br />
     14                        <a href="#example">Example</a><br />
     15                        <a href="#HandleBody">Handle/Body Idiom</a><br />
     16                        <a href="#ThreadSafety">Thread Safety</a><br />
     17                        <a href="#FAQ">Frequently Asked Questions</a><br />
     18                        <a href="smarttests.htm">Smart Pointer Timings</a><br />
     19                        <a href="sp_techniques.html">Programming Techniques</a></p>
     20                <h2 id="Introduction">Introduction</h2>
     21                <p>The <code>shared_ptr</code> class template stores a pointer to a dynamically allocated
     22                        object, typically with a C++ <em>new-expression</em>. The object pointed to is
     23                        guaranteed to be deleted when the last <code>shared_ptr</code> pointing to it is
     24                        destroyed or reset.</p>
     25                <blockquote><em>Example:</em><br /><pre>shared_ptr&lt;X&gt; p1( new X );
     26shared_ptr&lt;void&gt; p2( new int(5) );
     27</pre></blockquote>
     28
     29                <p><code>shared_ptr</code> deletes the exact pointer that has been passed at construction time,
     30                complete with its original type, regardless of the template parameter. In the second example above,
     31                    when <code>p2</code> is destroyed or reset, it will call <code>delete</code> on the original <code>int*</code>
     32                    that has been passed to the constructor, even though <code>p2</code> itself is of type
     33                    <code>shared_ptr&lt;void&gt;</code> and stores a pointer of type <code>void*</code>.</p>
     34
     35                <p>Every <code>shared_ptr</code> meets the <code>CopyConstructible</code>, <code>MoveConstructible</code>,
     36                    <code>CopyAssignable</code> and <code>MoveAssignable</code>
     37                        requirements of the C++ Standard Library, and can be used in standard
     38                        library containers. Comparison operators are supplied so that <code>shared_ptr</code>
    2939                        works with the standard library's associative containers.</p>
    30                 <p>Normally, a <b>shared_ptr</b> cannot correctly hold a pointer to a dynamically
    31                         allocated array. See <A href="shared_array.htm"><b>shared_array</b></A> for
    32                         that usage.</p>
    33                 <p>Because the implementation uses reference counting, cycles of <b>shared_ptr</b> instances
    34                         will not be reclaimed. For example, if <b>main()</b> holds a <b>shared_ptr</b> to
    35                         <b>A</b>, which directly or indirectly holds a <b>shared_ptr</b> back to <b>A</b>,
    36                         <b>A</b>'s use count will be 2. Destruction of the original <b>shared_ptr</b> will
    37                         leave <b>A</b> dangling with a use count of 1. Use <A href="weak_ptr.htm">weak_ptr</A>
     40                <p>Because the implementation uses reference counting, cycles of <code>shared_ptr</code> instances
     41                        will not be reclaimed. For example, if <code>main()</code> holds a <code>shared_ptr</code> to
     42                        <code>A</code>, which directly or indirectly holds a <code>shared_ptr</code> back to <code>A</code>,
     43                        <code>A</code>'s use count will be 2. Destruction of the original <code>shared_ptr</code> will
     44                        leave <code>A</code> dangling with a use count of 1. Use <a href="weak_ptr.htm">weak_ptr</a>
    3845                        to "break cycles."</p>
    39                 <p>The class template is parameterized on <b>T</b>, the type of the object pointed
    40                         to. <STRONG>shared_ptr</STRONG> and most of its member functions place no
    41                         requirements on <STRONG>T</STRONG>; it is allowed to be an incomplete type, or <STRONG>
    42                                 void</STRONG>. Member functions that do place additional requirements (<A href="#constructors">constructors</A>,
    43                         <A href="#reset">reset</A>) are explicitly documented below.</p>
    44                 <P><STRONG>shared_ptr&lt;T&gt;</STRONG> can be implicitly converted to <STRONG>shared_ptr&lt;U&gt;</STRONG>
    45                         whenever <STRONG>T*</STRONG> can be implicitly converted to <STRONG>U*</STRONG>.
    46                         In particular, <STRONG>shared_ptr&lt;T&gt;</STRONG> is implicitly convertible
    47                         to <STRONG>shared_ptr&lt;T const&gt;</STRONG>, to <STRONG>shared_ptr&lt;U&gt;</STRONG>
    48                         where <STRONG>U</STRONG> is an accessible base of <STRONG>T</STRONG>, and to <STRONG>
    49                                 shared_ptr&lt;void&gt;</STRONG>.</P>
    50                 <P><STRONG>shared_ptr</STRONG> is now part of <STRONG>TR1</STRONG>, the first C++
    51                         Library Technical Report. The latest draft of <STRONG>TR1</STRONG> is available
    52                         at the following location:</P>
    53                 <P><A href="http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2005/n1745.pdf">http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2005/n1745.pdf</A>
    54                         (1.36Mb PDF)</P>
    55                 <P>This implementation conforms to the TR1 specification, with the only exception
    56                         that it resides in namespace <code>boost</code> instead of <code>std::tr1</code>.</P>
    57                 <h2><a name="BestPractices">Best Practices</a></h2>
    58                 <P>A simple guideline that nearly eliminates the possibility of memory leaks is:
    59                         always use a named smart pointer variable to hold the result of <STRONG>new. </STRONG>
    60                         Every occurence of the <STRONG>new</STRONG> keyword in the code should have the
    61                         form:</P>
    62                 <PRE>shared_ptr&lt;T&gt; p(new Y);</PRE>
    63                 <P>It is, of course, acceptable to use another smart pointer in place of <STRONG>shared_ptr</STRONG>
    64                         above; having <STRONG>T</STRONG> and <STRONG>Y</STRONG> be the same type, or
    65                         passing arguments to <STRONG>Y</STRONG>'s constructor is also OK.</P>
    66                 <P>If you observe this guideline, it naturally follows that you will have no
    67                         explicit <STRONG>delete</STRONG>s; <STRONG>try/catch</STRONG> constructs will
    68                         be rare.</P>
    69                 <P>Avoid using unnamed <STRONG>shared_ptr</STRONG> temporaries to save typing; to
    70                         see why this is dangerous, consider this example:</P>
    71                 <PRE>void f(shared_ptr&lt;int&gt;, int);
     46                <p>The class template is parameterized on <code>T</code>, the type of the object pointed
     47                        to. <code>shared_ptr</code> and most of its member functions place no
     48                        requirements on <code>T</code>; it is allowed to be an incomplete type, or <code>
     49                                void</code>. Member functions that do place additional requirements (<a href="#constructors">constructors</a>,
     50                        <a href="#reset">reset</a>) are explicitly documented below.</p>
     51                <p><code>shared_ptr&lt;T&gt;</code> can be implicitly converted to <code>shared_ptr&lt;U&gt;</code>
     52                        whenever <code>T*</code> can be implicitly converted to <code>U*</code>.
     53                        In particular, <code>shared_ptr&lt;T&gt;</code> is implicitly convertible
     54                        to <code>shared_ptr&lt;T const&gt;</code>, to <code>shared_ptr&lt;U&gt;</code>
     55                        where <code>U</code> is an accessible base of <code>T</code>, and to <code>
     56                                shared_ptr&lt;void&gt;</code>.</p>
     57                <p><code>shared_ptr</code> is now part of the C++11 Standard, as <code>std::shared_ptr</code>.</p>
     58                <p>Starting with Boost release 1.53, <code>shared_ptr</code> can be used to hold a pointer to a dynamically
     59                        allocated array. This is accomplished by using an array type (<code>T[]</code> or <code>T[N]</code>) as
     60                        the template parameter. There is almost no difference between using an unsized array, <code>T[]</code>,
     61                        and a sized array, <code>T[N]</code>; the latter just enables <code>operator[]</code> to perform a range check
     62                        on the index.</p>
     63                <blockquote><em>Example:</em><br /><pre>shared_ptr&lt;double[1024]&gt; p1( new double(1024) );
     64shared_ptr&lt;double[]&gt; p2( new double(n) );
     65</pre></blockquote>
     66
     67                <h2 id="BestPractices">Best Practices</h2>
     68                <p>A simple guideline that nearly eliminates the possibility of memory leaks is:
     69                        always use a named smart pointer variable to hold the result of <code>new</code>.
     70                        Every occurence of the <code>new</code> keyword in the code should have the
     71                        form:</p>
     72                <pre>shared_ptr&lt;T&gt; p(new Y);</pre>
     73                <p>It is, of course, acceptable to use another smart pointer in place of <code>shared_ptr</code>
     74                        above; having <code>T</code> and <code>Y</code> be the same type, or
     75                        passing arguments to <code>Y</code>'s constructor is also OK.</p>
     76                <p>If you observe this guideline, it naturally follows that you will have no
     77                        explicit <code>delete</code> statements; <code>try/catch</code> constructs will
     78                        be rare.</p>
     79                <p>Avoid using unnamed <code>shared_ptr</code> temporaries to save typing; to
     80                        see why this is dangerous, consider this example:</p>
     81                <pre>void f(shared_ptr&lt;int&gt;, int);
    7282int g();
    7383
    7484void ok()
    7585{
    76     shared_ptr&lt;int&gt; p(new int(2));
    77     f(p, g());
     86    shared_ptr&lt;int&gt; p( new int(2) );
     87    f( p, g() );
    7888}
    7989
    8090void bad()
    8191{
    82     f(shared_ptr&lt;int&gt;(new int(2)), g());
     92    f( shared_ptr&lt;int&gt;( new int(2) ), g() );
    8393}
    84 </PRE>
    85                 <P>The function <STRONG>ok</STRONG> follows the guideline to the letter, whereas <STRONG>
    86                                 bad</STRONG> constructs the temporary <STRONG>shared_ptr</STRONG> in place,
     94</pre>
     95                <p>The function <code>ok</code> follows the guideline to the letter, whereas
     96                    <code>bad</code> constructs the temporary <code>shared_ptr</code> in place,
    8797                        admitting the possibility of a memory leak. Since function arguments are
    88                         evaluated in unspecified order, it is possible for <STRONG>new int(2)</STRONG> to
    89                         be evaluated first, <STRONG>g()</STRONG> second, and we may never get to the <STRONG>
    90                                 shared_ptr </STRONG>constructor if <STRONG>g</STRONG> throws an exception.
    91                         See <A href="http://www.gotw.ca/gotw/056.htm">Herb Sutter's treatment</A> (also <A href="http://www.cuj.com/reference/articles/2002/0212/0212_sutter.htm">
    92                                 here</A>) of the issue for more information.</P>
    93                 <P>The exception safety problem described above may also be eliminated by using
     98                        evaluated in unspecified order, it is possible for <code>new int(2)</code> to
     99                        be evaluated first, <code>g()</code> second, and we may never get to the
     100            <code>shared_ptr</code>constructor if <code>g</code> throws an exception.
     101                        See <a href="http://www.gotw.ca/gotw/056.htm">Herb Sutter's treatment</a> (also <a href="http://www.cuj.com/reference/articles/2002/0212/0212_sutter.htm">
     102                                here</a>) of the issue for more information.</p>
     103                <p>The exception safety problem described above may also be eliminated by using
    94104                        the <a href="make_shared.html"><code>make_shared</code></a>
    95105                        or <a href="make_shared.html"><code>allocate_shared</code></a>
    96                         factory functions defined in boost/make_shared.hpp.  These factory functions also provide
    97                         an efficiency benefit by consolidating allocations.<P>
    98                 <h2><a name="Synopsis">Synopsis</a></h2>
     106                        factory functions defined in <code>boost/make_shared.hpp</code>.
     107                        These factory functions also provide an efficiency benefit by consolidating allocations.</p>
     108                <h2 id="Synopsis">Synopsis</h2>
    99109                <pre>namespace boost {
    100110
    101111  class bad_weak_ptr: public std::exception;
    102112
    103   template&lt;class T&gt; class <A href="weak_ptr.htm" >weak_ptr</A>;
     113  template&lt;class T&gt; class <a href="weak_ptr.htm" >weak_ptr</a>;
    104114
    105115  template&lt;class T&gt; class shared_ptr {
     
    107117    public:
    108118
    109       typedef T <A href="#element_type" >element_type</A>;
    110 
    111       <A href="#constructors" >shared_ptr</A>(); // never throws
    112       template&lt;class Y&gt; explicit <A href="#constructors" >shared_ptr</A>(Y * p);
    113       template&lt;class Y, class D&gt; <A href="#constructors" >shared_ptr</A>(Y * p, D d);
    114       template&lt;class Y, class D, class A&gt; <A href="#allocator_constructor" >shared_ptr</A>(Y * p, D d, A a);
    115       <A href="#destructor" >~shared_ptr</A>(); // never throws
    116 
    117       <A href="#constructors" >shared_ptr</A>(shared_ptr const &amp; r); // never throws
    118       template&lt;class Y&gt; <A href="#constructors" >shared_ptr</A>(shared_ptr&lt;Y&gt; const &amp; r); // never throws
    119       template&lt;class Y&gt; <A href="#constructors" >shared_ptr</A>(shared_ptr&lt;Y&gt; const &amp; r, T * p); // never throws
    120       template&lt;class Y&gt; explicit <A href="#constructors" >shared_ptr</A>(<A href="weak_ptr.htm" >weak_ptr</A>&lt;Y&gt; const &amp; r);
    121       template&lt;class Y&gt; explicit <A href="#constructors" >shared_ptr</A>(std::auto_ptr&lt;Y&gt; &amp; r);
    122 
    123       shared_ptr &amp; <A href="#assignment" >operator=</A>(shared_ptr const &amp; r); // never throws
    124       template&lt;class Y&gt; shared_ptr &amp; <A href="#assignment" >operator=</A>(shared_ptr&lt;Y&gt; const &amp; r); // never throws
    125       template&lt;class Y&gt; shared_ptr &amp; <A href="#assignment" >operator=</A>(std::auto_ptr&lt;Y&gt; &amp; r);
    126 
    127       void <A href="#reset" >reset</A>(); // never throws
    128       template&lt;class Y&gt; void <A href="#reset" >reset</A>(Y * p);
    129       template&lt;class Y, class D&gt; void <A href="#reset" >reset</A>(Y * p, D d);
    130       template&lt;class Y, class D, class A&gt; void <A href="#reset" >reset</A>(Y * p, D d, A a);
    131       template&lt;class Y&gt; void <A href="#reset" >reset</A>(shared_ptr&lt;Y&gt; const &amp; r, T * p); // never throws
    132 
    133       T &amp; <A href="#indirection" >operator*</A>() const; // never throws
    134       T * <A href="#indirection" >operator-&gt;</A>() const; // never throws
    135       T * <A href="#get" >get</A>() const; // never throws
    136 
    137       bool <A href="#unique" >unique</A>() const; // never throws
    138       long <A href="#use_count" >use_count</A>() const; // never throws
    139 
    140       operator <A href="#conversions" ><i>unspecified-bool-type</i></A>() const; // never throws
    141 
    142       void <A href="#swap" >swap</A>(shared_ptr &amp; b); // never throws
     119      typedef <em>see below</em> <a href="#element_type" >element_type</a>;
     120
     121      <a href="#default_constructor" >shared_ptr</a>(); // never throws
     122
     123      template&lt;class Y&gt; explicit <a href="#pointer_constructor" >shared_ptr</a>(Y * p);
     124      template&lt;class Y, class D&gt; <a href="#deleter_constructor" >shared_ptr</a>(Y * p, D d);
     125      template&lt;class Y, class D, class A&gt; <a href="#deleter_constructor" >shared_ptr</a>(Y * p, D d, A a);
     126
     127      <a href="#destructor" >~shared_ptr</a>(); // never throws
     128
     129      <a href="#copy_constructor" >shared_ptr</a>(shared_ptr const &amp; r); // never throws
     130      template&lt;class Y&gt; <a href="#copy_constructor" >shared_ptr</a>(shared_ptr&lt;Y&gt; const &amp; r); // never throws
     131
     132      <a href="#move_constructor" >shared_ptr</a>(shared_ptr &amp;&amp; r); // never throws
     133      template&lt;class Y&gt; <a href="#move_constructor" >shared_ptr</a>(shared_ptr&lt;Y&gt; &amp;&amp; r); // never throws
     134
     135      template&lt;class Y&gt; <a href="#aliasing_constructor" >shared_ptr</a>(shared_ptr&lt;Y&gt; const &amp; r, element_type * p); // never throws
     136
     137      template&lt;class Y&gt; explicit <a href="#weak_ptr_constructor" >shared_ptr</a>(<a href="weak_ptr.htm" >weak_ptr</a>&lt;Y&gt; const &amp; r);
     138
     139      template&lt;class Y&gt; explicit <a href="#auto_ptr_constructor" >shared_ptr</a>(std::auto_ptr&lt;Y&gt; &amp; r);
     140      template&lt;class Y&gt; <a href="#auto_ptr_constructor" >shared_ptr</a>(std::auto_ptr&lt;Y&gt; &amp;&amp; r);
     141
     142      template&lt;class Y, class D&gt; <a href="#unique_ptr_constructor" >shared_ptr</a>(std::unique_ptr&lt;Y, D&gt; &amp;&amp; r);
     143
     144      shared_ptr &amp; <a href="#assignment" >operator=</a>(shared_ptr const &amp; r); // never throws
     145      template&lt;class Y&gt; shared_ptr &amp; <a href="#assignment" >operator=</a>(shared_ptr&lt;Y&gt; const &amp; r); // never throws
     146
     147      shared_ptr &amp; <a href="#assignment" >operator=</a>(shared_ptr const &amp;&amp; r); // never throws
     148      template&lt;class Y&gt; shared_ptr &amp; <a href="#assignment" >operator=</a>(shared_ptr&lt;Y&gt; const &amp;&amp; r); // never throws
     149
     150      template&lt;class Y&gt; shared_ptr &amp; <a href="#assignment" >operator=</a>(std::auto_ptr&lt;Y&gt; &amp; r);
     151      template&lt;class Y&gt; shared_ptr &amp; <a href="#assignment" >operator=</a>(std::auto_ptr&lt;Y&gt; &amp;&amp; r);
     152
     153      template&lt;class Y, class D&gt; shared_ptr &amp; <a href="#assignment" >operator=</a>(std::unique_ptr&lt;Y, D&gt; &amp;&amp; r);
     154
     155      void <a href="#reset" >reset</a>(); // never throws
     156
     157      template&lt;class Y&gt; void <a href="#reset" >reset</a>(Y * p);
     158      template&lt;class Y, class D&gt; void <a href="#reset" >reset</a>(Y * p, D d);
     159      template&lt;class Y, class D, class A&gt; void <a href="#reset" >reset</a>(Y * p, D d, A a);
     160
     161      template&lt;class Y&gt; void <a href="#reset" >reset</a>(shared_ptr&lt;Y&gt; const &amp; r, element_type * p); // never throws
     162
     163      T &amp; <a href="#indirection" >operator*</a>() const; // never throws; only valid when T is not an array type
     164      T * <a href="#indirection" >operator-&gt;</a>() const; // never throws; only valid when T is not an array type
     165
     166      element_type &amp; <a href="#indirection" >operator[]</a>( std::ptrdiff_t i ) const; // never throws; only valid when T is an array type
     167
     168      element_type * <a href="#get" >get</a>() const; // never throws
     169
     170      bool <a href="#unique" >unique</a>() const; // never throws
     171      long <a href="#use_count" >use_count</a>() const; // never throws
     172
     173      operator <a href="#conversions" ><i>unspecified-bool-type</i></a>() const; // never throws
     174
     175      void <a href="#swap" >swap</a>(shared_ptr &amp; b); // never throws
     176     
     177      template&lt;class Y&gt; bool <a href="#owner_before" >owner_before</a>( shared_ptr&lt;Y&gt; const &amp; rhs ) const; // never throws
     178      template&lt;class Y&gt; bool <a href="#owner_before" >owner_before</a>( weak_ptr&lt;Y&gt; const &amp; rhs ) const; // never throws
    143179  };
    144180
    145181  template&lt;class T, class U&gt;
    146     bool <A href="#comparison" >operator==</A>(shared_ptr&lt;T&gt; const &amp; a, shared_ptr&lt;U&gt; const &amp; b); // never throws
     182    bool <a href="#comparison" >operator==</a>(shared_ptr&lt;T&gt; const &amp; a, shared_ptr&lt;U&gt; const &amp; b); // never throws
    147183
    148184  template&lt;class T, class U&gt;
    149     bool <A href="#comparison" >operator!=</A>(shared_ptr&lt;T&gt; const &amp; a, shared_ptr&lt;U&gt; const &amp; b); // never throws
     185    bool <a href="#comparison" >operator!=</a>(shared_ptr&lt;T&gt; const &amp; a, shared_ptr&lt;U&gt; const &amp; b); // never throws
    150186
    151187  template&lt;class T, class U&gt;
    152     bool <A href="#comparison" >operator&lt;</A>(shared_ptr&lt;T&gt; const &amp; a, shared_ptr&lt;U&gt; const &amp; b); // never throws
    153 
    154   template&lt;class T&gt; void <A href="#free-swap" >swap</A>(shared_ptr&lt;T&gt; &amp; a, shared_ptr&lt;T&gt; &amp; b); // never throws
    155 
    156   template&lt;class T&gt; T * <A href="#get_pointer" >get_pointer</A>(shared_ptr&lt;T&gt; const &amp; p); // never throws
     188    bool <a href="#comparison" >operator&lt;</a>(shared_ptr&lt;T&gt; const &amp; a, shared_ptr&lt;U&gt; const &amp; b); // never throws
     189
     190  template&lt;class T&gt; void <a href="#free-swap" >swap</a>(shared_ptr&lt;T&gt; &amp; a, shared_ptr&lt;T&gt; &amp; b); // never throws
     191
     192  template&lt;class T&gt; typename shared_ptr&lt;T&gt;::element_type * <a href="#get_pointer" >get_pointer</a>(shared_ptr&lt;T&gt; const &amp; p); // never throws
    157193
    158194  template&lt;class T, class U&gt;
    159     shared_ptr&lt;T&gt; <A href="#static_pointer_cast" >static_pointer_cast</A>(shared_ptr&lt;U&gt; const &amp; r); // never throws
     195    shared_ptr&lt;T&gt; <a href="#static_pointer_cast" >static_pointer_cast</a>(shared_ptr&lt;U&gt; const &amp; r); // never throws
    160196
    161197  template&lt;class T, class U&gt;
    162     shared_ptr&lt;T&gt; <A href="#const_pointer_cast" >const_pointer_cast</A>(shared_ptr&lt;U&gt; const &amp; r); // never throws
     198    shared_ptr&lt;T&gt; <a href="#const_pointer_cast" >const_pointer_cast</a>(shared_ptr&lt;U&gt; const &amp; r); // never throws
    163199
    164200  template&lt;class T, class U&gt;
    165     shared_ptr&lt;T&gt; <A href="#dynamic_pointer_cast" >dynamic_pointer_cast</A>(shared_ptr&lt;U&gt; const &amp; r); // never throws
     201    shared_ptr&lt;T&gt; <a href="#dynamic_pointer_cast" >dynamic_pointer_cast</a>(shared_ptr&lt;U&gt; const &amp; r); // never throws
     202
     203  template&lt;class T, class U&gt;
     204    shared_ptr&lt;T&gt; <a href="#reinterpret_pointer_cast" >reinterpet_pointer_cast</a>(shared_ptr&lt;U&gt; const &amp; r); // never throws
    166205
    167206  template&lt;class E, class T, class Y&gt;
    168     std::basic_ostream&lt;E, T&gt; &amp; <A href="#insertion-operator" >operator&lt;&lt;</A> (std::basic_ostream&lt;E, T&gt; &amp; os, shared_ptr&lt;Y&gt; const &amp; p);
     207    std::basic_ostream&lt;E, T&gt; &amp; <a href="#insertion-operator" >operator&lt;&lt;</a> (std::basic_ostream&lt;E, T&gt; &amp; os, shared_ptr&lt;Y&gt; const &amp; p);
    169208
    170209  template&lt;class D, class T&gt;
    171     D * <A href="#get_deleter">get_deleter</A>(shared_ptr&lt;T&gt; const &amp; p);
     210    D * <a href="#get_deleter">get_deleter</a>(shared_ptr&lt;T&gt; const &amp; p);
    172211}</pre>
    173                 <h2><a name="Members">Members</a></h2>
    174                 <h3><a name="element_type">element_type</a></h3>
    175                 <pre>typedef T element_type;</pre>
    176                 <blockquote>
    177                         <p>Provides the type of the template parameter T.</p>
    178                 </blockquote>
    179                 <h3><a name="constructors">constructors</a></h3>
     212                <h2 id="Members">Members</h2>
     213                <h3 id="element_type">element_type</h3>
     214                <pre>typedef <em>...</em> element_type;</pre>
     215                <blockquote>
     216                        <p><code>element_type</code> is <code>T</code> when <code>T</code> is not an array type,
     217                and <code>U</code> when <code>T</code> is <code>U[]</code> or <code>U[N]</code>.</p>
     218                </blockquote>
     219                <h3 id="default_constructor">default constructor</h3>
    180220                <pre>shared_ptr(); // never throws</pre>
    181221                <blockquote>
    182                         <p><b>Effects:</b> Constructs an <EM>empty</EM> <b>shared_ptr</b>.</p>
     222                        <p><b>Effects:</b> Constructs an <em>empty</em> <code>shared_ptr</code>.</p>
    183223                        <p><b>Postconditions:</b> <code>use_count() == 0 &amp;&amp; get() == 0</code>.</p>
    184224                        <p><b>Throws:</b> nothing.</p>
    185225                </blockquote>
    186                 <P><EM>[The nothrow guarantee is important, since <STRONG>reset()</STRONG> is specified
     226                <p><em>[The nothrow guarantee is important, since <code>reset()</code> is specified
    187227                                in terms of the default constructor; this implies that the constructor must not
    188                                 allocate memory.]</EM></P>
     228                                allocate memory.]</em></p>
     229                <h3 id="pointer_constructor">pointer constructor</h3>
    189230                <pre>template&lt;class Y&gt; explicit shared_ptr(Y * p);</pre>
    190231                <blockquote>
    191                         <p><b>Requirements:</b> <b>p</b> must be convertible to <b>T *</b>. <STRONG>Y</STRONG>
    192                                 must be a complete type. The expression <code>delete p</code> must be
    193                                 well-formed, must not invoke undefined behavior, and must not throw exceptions.
     232                        <p><b>Requirements:</b>
     233                            <code>Y</code> must be a complete type.
     234                            The expression <code>delete[] p</code>, when <code>T</code> is an array type, or <code>delete p</code>,
     235                            when <code>T</code> is not an array type,
     236                            must be well-formed, must not invoke undefined behavior, and must not throw exceptions.
     237                            When <code>T</code> is <code>U[N]</code>, <code>Y (*) [N]</code> must be convertible to <code>T*</code>;
     238                            when <code>T</code> is <code>U[]</code>, <code>Y (*) []</code> must be convertible to <code>T*</code>;
     239                            otherwise, <code>Y*</code> must be convertible to <code>T*</code>.
    194240                        </p>
    195                         <p><b>Effects:</b> Constructs a <b>shared_ptr</b> that <EM>owns</EM> the pointer <b>p</b>.</p>
     241                        <p><b>Effects:</b>
     242                            When <code>T</code> is not an array type, constructs a <code>shared_ptr</code> that <em>owns</em>
     243                            the pointer <code>p</code>.
     244                            Otherwise, constructs  a <code>shared_ptr</code> that <em>owns</em>
     245                            <code>p</code> and a deleter of an unspecified type that calls <code>delete[] p</code>.</p>
    196246                        <p><b>Postconditions:</b> <code>use_count() == 1 &amp;&amp; get() == p</code>.</p>
    197                         <p><b>Throws:</b> <STRONG>std::bad_alloc</STRONG>, or an implementation-defined
     247                        <p><b>Throws:</b> <code>std::bad_alloc</code>, or an implementation-defined
    198248                                exception when a resource other than memory could not be obtained.</p>
    199                         <p><b>Exception safety:</b> If an exception is thrown, <code>delete p</code> is
    200                                 called.</p>
    201                         <P><STRONG>Notes:</STRONG> <B>p</B> must be a pointer to an object that was
    202                                 allocated via a C++ <B>new</B> expression or be 0. The postcondition that <A href="#use_count">
    203                                         use count</A> is 1 holds even if <b>p</b> is 0; invoking <STRONG>delete</STRONG>
    204                                 on a pointer that has a value of 0 is harmless.</P>
    205                 </blockquote>
    206                 <P><EM>[This constructor has been changed to a template in order to remember the actual
    207                                 pointer type passed. The destructor will call <STRONG>delete</STRONG> with the
    208                                 same pointer, complete with its original type, even when <STRONG>T</STRONG> does
    209                                 not have a virtual destructor, or is <STRONG>void</STRONG>.</EM></P>
    210                 <P><EM>The optional intrusive counting support has been dropped as it exposes too much
    211                                 implementation details and doesn't interact well with <STRONG>weak_ptr</STRONG>.
    212                                 The current implementation uses a different mechanism, <A href="enable_shared_from_this.html">
    213                                         enable_shared_from_this</A>, to solve the "<STRONG>shared_ptr</STRONG> from <STRONG>
    214                                         this</STRONG>" problem.</EM><EM>]</EM></P>
    215                 <a name="allocator_constructor"></a>
     249                        <p><b>Exception safety:</b> If an exception is thrown, the constructor calls
     250                            <code>delete[] p</code>, when <code>T</code> is an array type,
     251                            or <code>delete p</code>, when <code>T</code> is not an array type.</p>
     252                        <p><b>Notes:</b> <code>p</code> must be a pointer to an object that was
     253                                allocated via a C++ <code>new</code> expression or be 0. The postcondition that <a href="#use_count">
     254                                        use count</a> is 1 holds even if <code>p</code> is 0; invoking <code>delete</code>
     255                                on a pointer that has a value of 0 is harmless.</p>
     256                </blockquote>
     257                <p><em>[This constructor is a template in order to remember the actual
     258                                pointer type passed. The destructor will call <code>delete</code> with the
     259                                same pointer, complete with its original type, even when <code>T</code> does
     260                                not have a virtual destructor, or is <code>void</code>.]</em></p>
     261                <h3 id="deleter_constructor">constructors taking a deleter</h3>
    216262                <pre>template&lt;class Y, class D&gt; shared_ptr(Y * p, D d);
    217263template&lt;class Y, class D, class A&gt; shared_ptr(Y * p, D d, A a);</pre>
    218264                <blockquote>
    219                         <p><b>Requirements:</b> <B>p</B> must be convertible to <B>T *</B>. <STRONG>D</STRONG>
    220                                 must be <STRONG>CopyConstructible</STRONG>. The copy constructor and destructor
    221                                 of <b>D</b> must not throw. The expression <code>d(p)</code> must be
    222                                 well-formed, must not invoke undefined behavior, and must not throw exceptions. <STRONG>
    223                                         A</STRONG> must be an <EM>Allocator</EM>, as described in section 20.1.5 (<STRONG>Allocator
    224                                         requirements</STRONG>) of the C++ Standard.
     265                        <p><b>Requirements:</b>
     266                            <code>D</code> must be <code>CopyConstructible</code>. The copy constructor and destructor
     267                                of <code>D</code> must not throw. The expression <code>d(p)</code> must be
     268                                well-formed, must not invoke undefined behavior, and must not throw exceptions.
     269                                <code>A</code> must be an <em>Allocator</em>, as described in section 20.1.5
     270                                (<code>Allocator requirements</code>) of the C++ Standard.
     271                            When <code>T</code> is <code>U[N]</code>, <code>Y (*) [N]</code> must be convertible to <code>T*</code>;
     272                            when <code>T</code> is <code>U[]</code>, <code>Y (*) []</code> must be convertible to <code>T*</code>;
     273                            otherwise, <code>Y*</code> must be convertible to <code>T*</code>.
    225274                        </p>
    226                         <p><b>Effects:</b> Constructs a <b>shared_ptr</b> that <EM>owns</EM> the pointer <STRONG>
    227                                         p</STRONG> and the deleter <b>d</b>. The second constructor allocates
    228                                 memory using a copy of <STRONG>a</STRONG>.</p>
     275                        <p><b>Effects:</b> Constructs a <code>shared_ptr</code> that <em>owns</em> the pointer <code>
     276                                        p</code> and the deleter <code>d</code>. The second constructor allocates
     277                                memory using a copy of <code>a</code>.</p>
    229278                        <p><b>Postconditions:</b> <code>use_count() == 1 &amp;&amp; get() == p</code>.</p>
    230                         <p><b>Throws:</b> <STRONG>std::bad_alloc</STRONG>, or an implementation-defined
     279                        <p><b>Throws:</b> <code>std::bad_alloc</code>, or an implementation-defined
    231280                                exception when a resource other than memory could not be obtained.</p>
    232281                        <p><b>Exception safety:</b> If an exception is thrown, <code>d(p)</code> is called.</p>
    233                         <p><b>Notes:</b> When the the time comes to delete the object pointed to by <b>p</b>,
    234                                 the stored copy of <STRONG>d</STRONG> is invoked with the stored copy of <STRONG>p</STRONG>
     282                        <p><b>Notes:</b> When the the time comes to delete the object pointed to by <code>p</code>,
     283                                the stored copy of <code>d</code> is invoked with the stored copy of <code>p</code>
    235284                                as an argument.</p>
    236285                </blockquote>
    237                 <P><EM>[Custom deallocators allow a factory function returning a <STRONG>shared_ptr</STRONG>
     286                <p><em>[Custom deallocators allow a factory function returning a <code>shared_ptr</code>
    238287                                to insulate the user from its memory allocation strategy. Since the deallocator
    239288                                is not part of the type, changing the allocation strategy does not break source
    240289                                or binary compatibility, and does not require a client recompilation. For
    241                                 example, a "no-op" deallocator is useful when returning a <STRONG>shared_ptr</STRONG>
    242                                 to a statically allocated object, and other variations allow a <STRONG>shared_ptr</STRONG>
    243                                 to be used as a wrapper for another smart pointer, easing interoperability.</EM></P>
    244                 <P><EM>The support for custom deallocators does not impose significant overhead. Other <STRONG>
    245                                         shared_ptr</STRONG> features still require a deallocator to be kept.</EM></P>
    246                 <P><EM>The requirement that the copy constructor of <b>D</b> does not throw comes from
    247                                 the pass by value. If the copy constructor throws, the pointer is leaked.
    248                                 Removing the requirement requires a pass by (const) reference.</EM></P>
    249                 <P><EM>The main problem with pass by reference lies in its interaction with rvalues. A
    250                                 const reference may still cause a copy, and will require a const operator(). A
    251                                 non-const reference won't bind to an rvalue at all. A good solution to this
    252                                 problem is the rvalue reference proposed in <A href="http://std.dkuug.dk/jtc1/sc22/wg21/docs/papers/2002/n1377.htm">
    253                                         N1377</A>/<A href="http://std.dkuug.dk/jtc1/sc22/wg21/docs/papers/2002/n1385.htm">N1385</A>.]</EM></P>
     290                                example, a "no-op" deallocator is useful when returning a <code>shared_ptr</code>
     291                                to a statically allocated object, and other variations allow a <code>shared_ptr</code>
     292                                to be used as a wrapper for another smart pointer, easing interoperability.</em></p>
     293                <p><em>The support for custom deallocators does not impose significant overhead. Other <code>
     294                                        shared_ptr</code> features still require a deallocator to be kept.</em></p>
     295                <p><em>The requirement that the copy constructor of <code>D</code> does not throw comes from
     296                                the pass by value. If the copy constructor throws, the pointer would leak.]</em></p>
     297                <h3 id="copy_constructor">copy and converting constructors</h3>
    254298                <pre>shared_ptr(shared_ptr const &amp; r); // never throws
    255299template&lt;class Y&gt; shared_ptr(shared_ptr&lt;Y&gt; const &amp; r); // never throws</pre>
    256300                <blockquote>
    257                         <p><b>Effects:</b> If <b>r</b> is <EM>empty</EM>, constructs an <EM>empty</EM> <b>shared_ptr</b>;
    258                                 otherwise, constructs a <b>shared_ptr</b> that <EM>shares ownership</EM> with <b>r</b>.</p>
     301                        <p><b>Requires:</b> <code>Y*</code> should be convertible to <code>T*</code>.</p>
     302                        <p><b>Effects:</b> If <code>r</code> is <em>empty</em>, constructs an <em>empty</em> <code>shared_ptr</code>;
     303                                otherwise, constructs a <code>shared_ptr</code> that <em>shares ownership</em> with <code>r</code>.</p>
    259304                        <p><b>Postconditions:</b> <code>get() == r.get() &amp;&amp; use_count() ==
    260305                                        r.use_count()</code>.</p>
    261306                        <p><b>Throws:</b> nothing.</p>
    262307                </blockquote>
    263                 <pre>template&lt;class Y&gt; shared_ptr(shared_ptr&lt;Y&gt; const &amp; r, T * p); // never throws</pre>
    264                 <blockquote>
    265                         <p><b>Effects:</b> constructs a <b>shared_ptr</b> that <EM>shares ownership</EM> with
    266                                 <b>r</b> and stores <b>p</b>.</p>
     308                <h3 id="move_constructor">move constructors</h3>
     309                <pre>shared_ptr(shared_ptr &amp;&amp; r); // never throws
     310template&lt;class Y&gt; shared_ptr(shared_ptr&lt;Y&gt; &amp;&amp; r); // never throws</pre>
     311                <blockquote>
     312                        <p><b>Requires:</b> <code>Y*</code> should be convertible to <code>T*</code>.</p>
     313                        <p><b>Effects:</b> Move-constructs a <code>shared_ptr</code> from <code>r</code>.</p>
     314                        <p><b>Postconditions:</b> <code>*this</code> contains the old value of <code>r</code>. <code>r</code> is <em>empty</em> and <code>r.get() == 0</code>.</p>
     315                        <p><b>Throws:</b> nothing.</p>
     316                </blockquote>
     317                <h3 id="aliasing_constructor">aliasing constructor</h3>
     318                <pre>template&lt;class Y&gt; shared_ptr(shared_ptr&lt;Y&gt; const &amp; r, element_type * p); // never throws</pre>
     319                <blockquote>
     320                        <p><b>Effects:</b> constructs a <code>shared_ptr</code> that <em>shares ownership</em> with
     321                                <code>r</code> and stores <code>p</code>.</p>
    267322                        <p><b>Postconditions:</b> <code>get() == p &amp;&amp; use_count() == r.use_count()</code>.</p>
    268323                        <p><b>Throws:</b> nothing.</p>
    269324                </blockquote>
    270                 <pre>template&lt;class Y&gt; explicit shared_ptr(<A href="weak_ptr.htm" >weak_ptr</A>&lt;Y&gt; const &amp; r);</pre>
    271                 <blockquote>
    272                         <p><b>Effects:</b> Constructs a <b>shared_ptr</b> that <EM>shares ownership</EM> with
    273                                 <b>r</b> and stores a copy of the pointer stored in <STRONG>r</STRONG>.</p>
     325                <h3 id="weak_ptr_constructor">weak_ptr constructor</h3>
     326                <pre>template&lt;class Y&gt; explicit shared_ptr(<a href="weak_ptr.htm" >weak_ptr</a>&lt;Y&gt; const &amp; r);</pre>
     327                <blockquote>
     328                        <p><b>Requires:</b> <code>Y*</code> should be convertible to <code>T*</code>.</p>
     329                        <p><b>Effects:</b> Constructs a <code>shared_ptr</code> that <em>shares ownership</em> with
     330                                <code>r</code> and stores a copy of the pointer stored in <code>r</code>.</p>
    274331                        <p><b>Postconditions:</b> <code>use_count() == r.use_count()</code>.</p>
    275                         <p><b>Throws:</b> <b>bad_weak_ptr</b> when <code>r.use_count() == 0</code>.</p>
     332                        <p><b>Throws:</b> <code>bad_weak_ptr</code> when <code>r.use_count() == 0</code>.</p>
    276333                        <p><b>Exception safety:</b> If an exception is thrown, the constructor has no
    277334                                effect.</p>
    278335                </blockquote>
    279                 <pre>template&lt;class Y&gt; shared_ptr(std::auto_ptr&lt;Y&gt; &amp; r);</pre>
    280                 <BLOCKQUOTE>
    281                         <P><B>Effects:</B> Constructs a <B>shared_ptr</B>, as if by storing a copy of <STRONG>r.release()</STRONG>.</P>
     336                <h3 id="auto_ptr_constructor">auto_ptr constructors</h3>
     337                <pre>template&lt;class Y&gt; shared_ptr(std::auto_ptr&lt;Y&gt; &amp; r);
     338template&lt;class Y&gt; shared_ptr(std::auto_ptr&lt;Y&gt; &amp;&amp; r);</pre>
     339                <blockquote>
     340                        <p><b>Requires:</b> <code>Y*</code> should be convertible to <code>T*</code>.</p>
     341                        <p><b>Effects:</b> Constructs a <code>shared_ptr</code>, as if by storing a copy of <code>r.release()</code>.</p>
    282342                        <p><b>Postconditions:</b> <code>use_count() == 1</code>.</p>
    283                         <p><b>Throws:</b> <STRONG>std::bad_alloc</STRONG>, or an implementation-defined
     343                        <p><b>Throws:</b> <code>std::bad_alloc</code>, or an implementation-defined
    284344                                exception when a resource other than memory could not be obtained.</p>
    285                         <P><B>Exception safety:</B> If an exception is thrown, the constructor has no
    286                                 effect.</P>
    287                 </BLOCKQUOTE>
    288                 <P><EM>[This constructor takes a the source <STRONG>auto_ptr</STRONG> by reference and
    289                                 not by value, and cannot accept <STRONG>auto_ptr</STRONG> temporaries. This is
    290                                 by design, as the constructor offers the strong guarantee; an rvalue reference
    291                                 would solve this problem, too.]</EM></P>
    292                 <h3><a name="destructor">destructor</a></h3>
     345                        <p><b>Exception safety:</b> If an exception is thrown, the constructor has no
     346                                effect.</p>
     347                </blockquote>
     348                <h3 id="unique_ptr_constructor">unique_ptr constructor</h3>
     349                <pre>template&lt;class Y, class D&gt; shared_ptr(std::unique_ptr&lt;Y, D&gt; &amp;&amp; r);</pre>
     350                <blockquote>
     351                        <p><b>Requires:</b> <code>Y*</code> should be convertible to <code>T*</code>.</p>
     352                        <p><b>Effects:</b>
     353                            Equivalent to <code>shared_ptr( r.release(), r.get_deleter() )</code> when <code>D</code> is not a reference type.
     354                            Otherwise, equivalent to <code>shared_ptr( r.release(), <em>del</em> )</code>, where <em>del</em> is a deleter
     355                            that stores the reference <code>rd</code> returned from <code>r.get_deleter()</code> and <code>del(p)</code> calls <code>rd(p)</code>.</p>
     356                        <p><b>Postconditions:</b> <code>use_count() == 1</code>.</p>
     357                        <p><b>Throws:</b> <code>std::bad_alloc</code>, or an implementation-defined
     358                                exception when a resource other than memory could not be obtained.</p>
     359                        <p><b>Exception safety:</b> If an exception is thrown, the constructor has no
     360                                effect.</p>
     361                </blockquote>
     362                <h3 id="destructor">destructor</h3>
    293363                <pre>~shared_ptr(); // never throws</pre>
    294                 <BLOCKQUOTE>
    295                         <P><B>Effects:</B></P>
    296                         <UL>
    297                                 <LI>
    298                                         If <STRONG>*this</STRONG> is <EM>empty</EM>, or <EM>shares ownership</EM> with
    299                                         another <STRONG>shared_ptr</STRONG> instance (<code>use_count() &gt; 1</code>),
    300                                 there are no side effects.
    301                                 <LI>
    302                                         Otherwise, if <STRONG>*this</STRONG> <EM>owns</EM> a pointer <STRONG>p</STRONG>
    303                                         and a deleter <STRONG>d</STRONG>, <code>d(p)</code>
    304                                 is called.
    305                                 <LI>
    306                                         Otherwise, <STRONG>*this</STRONG> <EM>owns</EM> a pointer <STRONG>p</STRONG>,
    307                                         and <code>delete p</code> is called.</LI></UL>
    308                         <P><B>Throws:</B> nothing.</P>
    309                 </BLOCKQUOTE>
    310                 <H3><a name="assignment">assignment</a></H3>
     364                <blockquote>
     365                        <p><b>Effects:</b></p>
     366                        <ul>
     367                                <li>
     368                                        If <code>*this</code> is <em>empty</em>, or <em>shares ownership</em> with
     369                                        another <code>shared_ptr</code> instance (<code>use_count() &gt; 1</code>),
     370                                    there are no side effects.</li>
     371                                <li>
     372                                        Otherwise, if <code>*this</code> <em>owns</em> a pointer <code>p</code>
     373                                        and a deleter <code>d</code>, <code>d(p)</code>
     374                                    is called.</li>
     375                                <li>
     376                                        Otherwise, <code>*this</code> <em>owns</em> a pointer <code>p</code>,
     377                                        and <code>delete p</code> is called.</li>
     378                        </ul>
     379                        <p><b>Throws:</b> nothing.</p>
     380                </blockquote>
     381                <h3 id="assignment">assignment</h3>
    311382                <pre>shared_ptr &amp; operator=(shared_ptr const &amp; r); // never throws
    312383template&lt;class Y&gt; shared_ptr &amp; operator=(shared_ptr&lt;Y&gt; const &amp; r); // never throws
    313384template&lt;class Y&gt; shared_ptr &amp; operator=(std::auto_ptr&lt;Y&gt; &amp; r);</pre>
    314                 <BLOCKQUOTE>
    315                         <P><B>Effects:</B> Equivalent to <code>shared_ptr(r).swap(*this)</code>.</P>
    316                         <P><B>Returns:</B> <code>*this</code>.</P>
    317                         <P><B>Notes:</B> The use count updates caused by the temporary object construction
     385                <blockquote>
     386                        <p><b>Effects:</b> Equivalent to <code>shared_ptr(r).swap(*this)</code>.</p>
     387                        <p><b>Returns:</b> <code>*this</code>.</p>
     388                        <p><b>Notes:</b> The use count updates caused by the temporary object construction
    318389                                and destruction are not considered observable side effects, and the
    319390                                implementation is free to meet the effects (and the implied guarantees) via
    320                                 different means, without creating a temporary. In particular, in the example:</P>
     391                                different means, without creating a temporary. In particular, in the example:</p>
    321392                        <pre>shared_ptr&lt;int&gt; p(new int);
    322393shared_ptr&lt;void&gt; q(p);
     
    325396</pre>
    326397                        <p>both assignments may be no-ops.</p>
    327                 </BLOCKQUOTE>
    328                 <h3><a name="reset">reset</a></h3>
     398                </blockquote>
     399                <pre>shared_ptr &amp; operator=(shared_ptr &amp;&amp; r); // never throws
     400template&lt;class Y&gt; shared_ptr &amp; operator=(shared_ptr&lt;Y&gt; &amp;&amp; r); // never throws
     401template&lt;class Y&gt; shared_ptr &amp; operator=(std::auto_ptr&lt;Y&gt; &amp;&amp; r);
     402template&lt;class Y, class D&gt; shared_ptr &amp; operator=(std::unique_ptr&lt;Y, D&gt; &amp;&amp; r);</pre>
     403                <blockquote>
     404                        <p><b>Effects:</b> Equivalent to <code>shared_ptr( std::move(r) ).swap(*this)</code>.</p>
     405                        <p><b>Returns:</b> <code>*this</code>.</p>
     406                </blockquote>
     407                <h3 id="reset">reset</h3>
    329408                <pre>void reset(); // never throws</pre>
    330                 <BLOCKQUOTE>
    331                         <P><B>Effects:</B> Equivalent to <code>shared_ptr().swap(*this)</code>.</P>
    332                 </BLOCKQUOTE>
     409                <blockquote>
     410                        <p><b>Effects:</b> Equivalent to <code>shared_ptr().swap(*this)</code>.</p>
     411                </blockquote>
    333412                <pre>template&lt;class Y&gt; void reset(Y * p);</pre>
    334                 <BLOCKQUOTE>
    335                         <P><B>Effects:</B> Equivalent to <code>shared_ptr(p).swap(*this)</code>.</P>
    336                 </BLOCKQUOTE>
     413                <blockquote>
     414                        <p><b>Effects:</b> Equivalent to <code>shared_ptr(p).swap(*this)</code>.</p>
     415                </blockquote>
    337416                <pre>template&lt;class Y, class D&gt; void reset(Y * p, D d);</pre>
    338                 <BLOCKQUOTE>
    339                         <P><B>Effects:</B> Equivalent to <code>shared_ptr(p, d).swap(*this)</code>.</P>
    340                 </BLOCKQUOTE>
     417                <blockquote>
     418                        <p><b>Effects:</b> Equivalent to <code>shared_ptr(p, d).swap(*this)</code>.</p>
     419                </blockquote>
    341420                <pre>template&lt;class Y, class D, class A&gt; void reset(Y * p, D d, A a);</pre>
    342                 <BLOCKQUOTE>
    343                         <P><B>Effects:</B> Equivalent to <code>shared_ptr(p, d, a).swap(*this)</code>.</P>
    344                 </BLOCKQUOTE>
    345                 <pre>template&lt;class Y&gt; void reset(shared_ptr&lt;Y&gt; const &amp; r, T * p); // never throws</pre>
    346                 <BLOCKQUOTE>
    347                         <P><B>Effects:</B> Equivalent to <code>shared_ptr(r, p).swap(*this)</code>.</P>
    348                 </BLOCKQUOTE>
    349                 <h3><a name="indirection">indirection</a></h3>
     421                <blockquote>
     422                        <p><b>Effects:</b> Equivalent to <code>shared_ptr(p, d, a).swap(*this)</code>.</p>
     423                </blockquote>
     424                <pre>template&lt;class Y&gt; void reset(shared_ptr&lt;Y&gt; const &amp; r, element_type * p); // never throws</pre>
     425                <blockquote>
     426                        <p><b>Effects:</b> Equivalent to <code>shared_ptr(r, p).swap(*this)</code>.</p>
     427                </blockquote>
     428                <h3 id="indirection">indirection</h3>
    350429                <pre>T &amp; operator*() const; // never throws</pre>
    351430                <blockquote>
    352                         <p><b>Requirements:</b> The stored pointer must not be 0.</p>
     431                        <p><b>Requirements:</b> <code>T</code> should not be an array type. The stored pointer must not be 0.</p>
    353432                        <p><b>Returns:</b> a reference to the object pointed to by the stored pointer.</p>
    354433                        <p><b>Throws:</b> nothing.</p>
     
    356435                <pre>T * operator-&gt;() const; // never throws</pre>
    357436                <blockquote>
    358                         <p><b>Requirements:</b> The stored pointer must not be 0.</p>
     437                        <p><b>Requirements:</b> <code>T</code> should not be an array type. The stored pointer must not be 0.</p>
    359438                        <p><b>Returns:</b> the stored pointer.</p>
    360439                        <p><b>Throws:</b> nothing.</p>
    361440                </blockquote>
    362                 <h3><a name="get">get</a></h3>
    363                 <pre>T * get() const; // never throws</pre>
     441                <pre>element_type &amp; operator[]( std::ptrdiff_t i ) const; // never throws</pre>
     442                <blockquote>
     443                        <p><b>Requirements:</b> <code>T</code> should be an array type. The stored pointer must not be 0.
     444                            <code>i &gt;= 0</code>. If <code>T</code> is <code>U[N]</code>, <code>i &lt; N</code>.</p>
     445                        <p><b>Returns:</b> <code>get()[ i ]</code>.</p>
     446                        <p><b>Throws:</b> nothing.</p>
     447                </blockquote>
     448                <h3 id="get">get</h3>
     449                <pre>element_type * get() const; // never throws</pre>
    364450                <blockquote>
    365451                        <p><b>Returns:</b> the stored pointer.</p>
    366452                        <p><b>Throws:</b> nothing.</p>
    367453                </blockquote>
    368                 <h3><a name="unique">unique</a></h3>
     454                <h3 id="unique">unique</h3>
    369455                <pre>bool unique() const; // never throws</pre>
    370456                <blockquote>
    371457                        <p><b>Returns:</b> <code>use_count() == 1</code>.</p>
    372458                        <p><b>Throws:</b> nothing.</p>
    373                         <P><B>Notes:</B> <code>unique()</code> may be faster than <code>use_count()</code>.
     459                        <p><b>Notes:</b> <code>unique()</code> may be faster than <code>use_count()</code>.
    374460                                If you are using <code>unique()</code> to implement copy on write, do not rely
    375                                 on a specific value when the stored pointer is zero.</P>
    376                 </blockquote>
    377                 <h3><a name="use_count">use_count</a></h3>
     461                                on a specific value when the stored pointer is zero.</p>
     462                </blockquote>
     463                <h3 id="use_count">use_count</h3>
    378464                <pre>long use_count() const; // never throws</pre>
    379465                <blockquote>
    380                         <p><b>Returns:</b> the number of <b>shared_ptr</b> objects, <STRONG>*this</STRONG> included,
    381                                 that <i>share ownership</i> with <b>*this</b>, or 0 when <STRONG>*this</STRONG>
    382                                 is <EM>empty</EM>.</p>
    383                         <p><b>Throws:</b> nothing.</p>
    384                         <P><B>Notes:</B> <code>use_count()</code> is not necessarily efficient. Use only
    385                                 for debugging and testing purposes, not for production code.</P>
    386                 </blockquote>
    387                 <h3><a name="conversions">conversions</a></h3>
     466                        <p><b>Returns:</b> the number of <code>shared_ptr</code> objects, <code>*this</code> included,
     467                                that <i>share ownership</i> with <code>*this</code>, or 0 when <code>*this</code>
     468                                is <em>empty</em>.</p>
     469                        <p><b>Throws:</b> nothing.</p>
     470                        <p><b>Notes:</b> <code>use_count()</code> is not necessarily efficient. Use only
     471                                for debugging and testing purposes, not for production code.</p>
     472                </blockquote>
     473                <h3 id="conversions">conversions</h3>
    388474                <pre>operator <i>unspecified-bool-type</i> () const; // never throws</pre>
    389475                <blockquote>
     
    391477                                equivalent to <code>get() != 0</code>.</p>
    392478                        <p><b>Throws:</b> nothing.</p>
    393                         <P><B>Notes:</B> This conversion operator allows <b>shared_ptr</b> objects to be
     479                        <p><b>Notes:</b> This conversion operator allows <code>shared_ptr</code> objects to be
    394480                                used in boolean contexts, like <code>if (p &amp;&amp; p-&gt;valid()) {}</code>.
    395481                                The actual target type is typically a pointer to a member function, avoiding
    396                                 many of the implicit conversion pitfalls.</P>
    397                 </blockquote>
    398                 <P><EM>[The conversion to bool is not merely syntactic sugar. It allows <STRONG>shared_ptr</STRONG>s
    399                                 to be declared in conditions when using <A href="#dynamic_pointer_cast">dynamic_pointer_cast</A>
    400                                 or <A href="weak_ptr.htm#lock">weak_ptr::lock</A>.]</EM></P>
    401                 <h3><a name="swap">swap</a></h3>
     482                                many of the implicit conversion pitfalls.</p>
     483                </blockquote>
     484                <p><em>[The conversion to bool is not merely syntactic sugar. It allows <code>shared_ptr</code>s
     485                                to be declared in conditions when using <a href="#dynamic_pointer_cast">dynamic_pointer_cast</a>
     486                                or <a href="weak_ptr.htm#lock">weak_ptr::lock</a>.]</em></p>
     487                <h3 id="swap">swap</h3>
    402488                <pre>void swap(shared_ptr &amp; b); // never throws</pre>
    403489                <blockquote>
     
    405491                        <p><b>Throws:</b> nothing.</p>
    406492                </blockquote>
    407                 <h2><a name="functions">Free Functions</a></h2>
    408                 <h3><a name="comparison">comparison</a></h3>
     493                <h2 id="functions">Free Functions</h2>
     494                <h3 id="comparison">comparison</h3>
    409495                <pre>template&lt;class T, class U&gt;
    410496  bool operator==(shared_ptr&lt;T&gt; const &amp; a, shared_ptr&lt;U&gt; const &amp; b); // never throws</pre>
     
    423509                <blockquote>
    424510                        <p><b>Returns:</b> an unspecified value such that</p>
    425                         <UL>
    426                                 <LI>
    427                                         <b>operator&lt;</b> is a strict weak ordering as described in section 25.3 <code>[lib.alg.sorting]</code>
    428                                 of the C++ standard;
    429                                 <LI>
    430                                         under the equivalence relation defined by <STRONG>operator&lt;</STRONG>, <code>!(a
    431                                                 &lt; b) &amp;&amp; !(b &lt; a)</code>, two <STRONG>shared_ptr</STRONG> instances
    432                                         are equivalent if and only if they <EM>share ownership</EM> or are both <EM>empty</EM>.</LI></UL>
    433                         <p><b>Throws:</b> nothing.</p>
    434                         <P><B>Notes:</B> Allows <STRONG>shared_ptr</STRONG> objects to be used as keys in
    435                                 associative containers.</P>
    436                 </blockquote>
    437                 <P><EM>[<STRONG>Operator&lt;</STRONG> has been preferred over a <STRONG>std::less </STRONG>
    438                                 specialization for consistency and legality reasons, as <STRONG>std::less</STRONG>
    439                                 is required to return the results of <STRONG>operator&lt;</STRONG>, and many
    440                                 standard algorithms use <STRONG>operator&lt;</STRONG> instead of <STRONG>std::less</STRONG>
    441                                 for comparisons when a predicate is not supplied. Composite objects, like <STRONG>std::pair</STRONG>,
    442                                 also implement their <STRONG>operator&lt;</STRONG> in terms of their contained
    443                                 subobjects' <STRONG>operator&lt;</STRONG>.</EM></P>
    444                 <P><EM>The rest of the comparison operators are omitted by design.]</EM></P>
    445                 <h3><a name="free-swap">swap</a></h3>
     511                        <ul>
     512                                <li>
     513                                        <code>operator&lt;</code> is a strict weak ordering as described in section 25.3 <code>[lib.alg.sorting]</code>
     514                                    of the C++ standard;</li>
     515                                <li>
     516                                        under the equivalence relation defined by <code>operator&lt;</code>, <code>!(a
     517                                                &lt; b) &amp;&amp; !(b &lt; a)</code>, two <code>shared_ptr</code> instances
     518                                        are equivalent if and only if they <em>share ownership</em> or are both <em>empty</em>.</li></ul>
     519                        <p><b>Throws:</b> nothing.</p>
     520                        <p><b>Notes:</b> Allows <code>shared_ptr</code> objects to be used as keys in
     521                                associative containers.</p>
     522                </blockquote>
     523                <p><em>[<code>Operator&lt;</code> has been preferred over a <code>std::less</code>
     524                                specialization for consistency and legality reasons, as <code>std::less</code>
     525                                is required to return the results of <code>operator&lt;</code>, and many
     526                                standard algorithms use <code>operator&lt;</code> instead of <code>std::less</code>
     527                                for comparisons when a predicate is not supplied. Composite objects, like <code>std::pair</code>,
     528                                also implement their <code>operator&lt;</code> in terms of their contained
     529                                subobjects' <code>operator&lt;</code>.</em></p>
     530                <p><em>The rest of the comparison operators are omitted by design.]</em></p>
     531                <h3 id="free-swap">swap</h3>
    446532                <pre>template&lt;class T&gt;
    447533  void swap(shared_ptr&lt;T&gt; &amp; a, shared_ptr&lt;T&gt; &amp; b); // never throws</pre>
    448                 <BLOCKQUOTE>
    449                         <P><B>Effects:</B> Equivalent to <code>a.swap(b)</code>.</P>
    450                         <P><B>Throws:</B> nothing.</P>
    451                         <P><B>Notes:</B> Matches the interface of <B>std::swap</B>. Provided as an aid to
    452                                 generic programming.</P>
    453                 </BLOCKQUOTE>
    454                 <P><EM>[<STRONG>swap</STRONG> is defined in the same namespace as <STRONG>shared_ptr</STRONG>
    455                                 as this is currently the only legal way to supply a <STRONG>swap</STRONG> function
    456                                 that has a chance to be used by the standard library.]</EM></P>
    457                 <h3><a name="get_pointer">get_pointer</a></h3>
     534                <blockquote>
     535                        <p><b>Effects:</b> Equivalent to <code>a.swap(b)</code>.</p>
     536                        <p><b>Throws:</b> nothing.</p>
     537                        <p><b>Notes:</b> Matches the interface of <code>std::swap</code>. Provided as an aid to
     538                                generic programming.</p>
     539                </blockquote>
     540                <p><em>[<code>swap</code> is defined in the same namespace as <code>shared_ptr</code>
     541                                as this is currently the only legal way to supply a <code>swap</code> function
     542                                that has a chance to be used by the standard library.]</em></p>
     543                <h3 id="get_pointer">get_pointer</h3>
    458544                <pre>template&lt;class T&gt;
    459   T * get_pointer(shared_ptr&lt;T&gt; const &amp; p); // never throws</pre>
    460                 <BLOCKQUOTE>
    461                         <P><B>Returns:</B> <code>p.get()</code>.</P>
    462                         <P><B>Throws:</B> nothing.</P>
    463                         <P><B>Notes:</B> Provided as an aid to generic programming. Used by <A href="../bind/mem_fn.html">
    464                                         mem_fn</A>.</P>
    465                 </BLOCKQUOTE>
    466                 <h3><a name="static_pointer_cast">static_pointer_cast</a></h3>
     545  typename shared_ptr&lt;T&gt;::element_type * get_pointer(shared_ptr&lt;T&gt; const &amp; p); // never throws</pre>
     546                <blockquote>
     547                        <p><b>Returns:</b> <code>p.get()</code>.</p>
     548                        <p><b>Throws:</b> nothing.</p>
     549                        <p><b>Notes:</b> Provided as an aid to generic programming. Used by <a href="../bind/mem_fn.html">
     550                                        mem_fn</a>.</p>
     551                </blockquote>
     552                <h3 id="static_pointer_cast">static_pointer_cast</h3>
    467553                <pre>template&lt;class T, class U&gt;
    468554  shared_ptr&lt;T&gt; static_pointer_cast(shared_ptr&lt;U&gt; const &amp; r); // never throws</pre>
    469                 <BLOCKQUOTE>
    470                         <P><STRONG>Requires:</STRONG> The expression <code>static_cast&lt;T*&gt;(r.get())</code>
    471                                 must be well-formed.</P>
    472                         <P><B>Returns:</B> If <b>r</b> is <i>empty</i>, an <i>empty</i> <b>shared_ptr&lt;T&gt;</b>;
    473                                 otherwise, a <STRONG>shared_ptr&lt;T&gt;</STRONG> object that stores a copy of <code>
    474                                         static_cast&lt;T*&gt;(r.get())</code> and <i>shares ownership</i> with <b>r</b>.</P>
    475                         <P><B>Throws:</B> nothing.</P>
    476                         <P><B>Notes:</B> the seemingly equivalent expression</P>
    477                         <p><code>shared_ptr&lt;T&gt;(static_cast&lt;T*&gt;(r.get()))</code></p>
    478                         <p>will eventually result in undefined behavior, attempting to delete the same
     555                <blockquote>
     556                        <p><b>Requires:</b> The expression <code>static_cast&lt;T*&gt;( (U*)0 )</code>
     557                                must be well-formed.</p>
     558                        <p><b>Returns:</b> <code>shared_ptr&lt;T&gt;( r, static_cast&lt;typename shared_ptr&lt;T&gt;::element_type*&gt;(r.get()) )</code>.</p>
     559                        <p><b>Throws:</b> nothing.</p>
     560                        <p><b>Notes:</b> the seemingly equivalent expression
     561                            <code>shared_ptr&lt;T&gt;(static_cast&lt;T*&gt;(r.get()))</code>
     562                            will eventually result in undefined behavior, attempting to delete the same
    479563                                object twice.</p>
    480                 </BLOCKQUOTE>
    481                 <h3><a name="const_pointer_cast">const_pointer_cast</a></h3>
     564                </blockquote>
     565                <h3 id="const_pointer_cast">const_pointer_cast</h3>
    482566                <pre>template&lt;class T, class U&gt;
    483567  shared_ptr&lt;T&gt; const_pointer_cast(shared_ptr&lt;U&gt; const &amp; r); // never throws</pre>
    484                 <BLOCKQUOTE>
    485                         <P><STRONG>Requires:</STRONG> The expression <code>const_cast&lt;T*&gt;(r.get())</code>
    486                                 must be well-formed.</P>
    487                         <P><B>Returns:</B> If <b>r</b> is <i>empty</i>, an <i>empty</i> <b>shared_ptr&lt;T&gt;</b>;
    488                                 otherwise, a <STRONG>shared_ptr&lt;T&gt;</STRONG> object that stores a copy of <code>
    489                                         const_cast&lt;T*&gt;(r.get())</code> and <i>shares ownership</i> with <b>r</b>.</P>
    490                         <P><B>Throws:</B> nothing.</P>
    491                         <P><B>Notes:</B> the seemingly equivalent expression</P>
    492                         <p><code>shared_ptr&lt;T&gt;(const_cast&lt;T*&gt;(r.get()))</code></p>
    493                         <p>will eventually result in undefined behavior, attempting to delete the same
    494                                 object twice.</p>
    495                 </BLOCKQUOTE>
    496                 <h3><a name="dynamic_pointer_cast">dynamic_pointer_cast</a></h3>
     568                <blockquote>
     569                        <p><b>Requires:</b> The expression <code>const_cast&lt;T*&gt;( (U*)0 )</code>
     570                                must be well-formed.</p>
     571                        <p><b>Returns:</b> <code>shared_ptr&lt;T&gt;( r, const_cast&lt;typename shared_ptr&lt;T&gt;::element_type*&gt;(r.get()) )</code>.</p>
     572                        <p><b>Throws:</b> nothing.</p>
     573                </blockquote>
     574                <h3 id="dynamic_pointer_cast">dynamic_pointer_cast</h3>
    497575                <pre>template&lt;class T, class U&gt;
    498576  shared_ptr&lt;T&gt; dynamic_pointer_cast(shared_ptr&lt;U&gt; const &amp; r);</pre>
    499                 <BLOCKQUOTE>
    500                         <P><STRONG>Requires:</STRONG> The expression <CODE>dynamic_cast&lt;T*&gt;(r.get())</CODE>
    501                                 must be well-formed and its behavior defined.</P>
    502                         <P><B>Returns:</B></P>
    503                         <UL>
    504                                 <LI>
    505                                         When <CODE>dynamic_cast&lt;T*&gt;(r.get())</CODE> returns a nonzero value, a <STRONG>
    506                                                 shared_ptr&lt;T&gt;</STRONG> object that stores a copy of it and <i>shares
    507                                                 ownership</i> with <STRONG>r</STRONG>;
    508                                 <LI>
    509                                         Otherwise, an <i>empty</i> <STRONG>shared_ptr&lt;T&gt;</STRONG> object.</LI></UL>
    510                         <P><B>Throws:</B> nothing.</P>
    511                         <P><B>Notes:</B> the seemingly equivalent expression</P>
    512                         <P><CODE>shared_ptr&lt;T&gt;(dynamic_cast&lt;T*&gt;(r.get()))</CODE></P>
    513                         <P>will eventually result in undefined behavior, attempting to delete the same
    514                                 object twice.</P>
    515                 </BLOCKQUOTE>
    516                 <h3><a name="insertion-operator">operator&lt;&lt;</a></h3>
     577                <blockquote>
     578                        <p><b>Requires:</b> The expression <code>dynamic_cast&lt;T*&gt;( (U*)0 )</code>
     579                                must be well-formed.</p>
     580                        <p><b>Returns:</b></p>
     581                        <ul>
     582                                <li>
     583                                        When <code>dynamic_cast&lt;typename shared_ptr&lt;T&gt;::element_type*&gt;(r.get())</code> returns a nonzero value <code>p</code>,
     584                                        <code>shared_ptr&lt;T&gt;(r, p)</code>;</li>
     585                                <li>
     586                                        Otherwise, <code>shared_ptr&lt;T&gt;()</code>.</li></ul>
     587                        <p><b>Throws:</b> nothing.</p>
     588                </blockquote>
     589                <h3 id="reinterpret_pointer_cast">reinterpret_pointer_cast</h3>
     590                <pre>template&lt;class T, class U&gt;
     591  shared_ptr&lt;T&gt; reinterpret_pointer_cast(shared_ptr&lt;U&gt; const &amp; r); // never throws</pre>
     592                <blockquote>
     593                        <p><b>Requires:</b> The expression <code>reinterpret_cast&lt;T*&gt;( (U*)0 )</code>
     594                                must be well-formed.</p>
     595                        <p><b>Returns:</b> <code>shared_ptr&lt;T&gt;( r, reinterpret_cast&lt;typename shared_ptr&lt;T&gt;::element_type*&gt;(r.get()) )</code>.</p>
     596                        <p><b>Throws:</b> nothing.</p>
     597                </blockquote>
     598                <h3 id="insertion-operator">operator&lt;&lt;</h3>
    517599                <pre>template&lt;class E, class T, class Y&gt;
    518600    std::basic_ostream&lt;E, T&gt; &amp; operator&lt;&lt; (std::basic_ostream&lt;E, T&gt; &amp; os, shared_ptr&lt;Y&gt; const &amp; p);</pre>
    519                 <BLOCKQUOTE>
    520                         <p><STRONG>Effects:</STRONG> <code>os &lt;&lt; p.get();</code>.</p>
    521                         <P><B>Returns:</B> <b>os</b>.</P>
    522                 </BLOCKQUOTE>
    523                 <h3><a name="get_deleter">get_deleter</a></h3>
     601                <blockquote>
     602                        <p><b>Effects:</b> <code>os &lt;&lt; p.get();</code>.</p>
     603                        <p><b>Returns:</b> <code>os</code>.</p>
     604                </blockquote>
     605                <h3 id="get_deleter">get_deleter</h3>
    524606                <pre>template&lt;class D, class T&gt;
    525607    D * get_deleter(shared_ptr&lt;T&gt; const &amp; p);</pre>
    526                 <BLOCKQUOTE>
    527                         <P><B>Returns:</B> If <STRONG>*this</STRONG> <EM>owns</EM> a deleter <STRONG>d</STRONG>
    528                                 of type (cv-unqualified) <STRONG>D</STRONG>, returns <code>&amp;d</code>;
    529                                 otherwise returns 0.</P>
    530                         <P><B>Throws:</B> nothing.</P>
    531                 </BLOCKQUOTE>
    532                 <h2><a name="example">Example</a></h2>
    533                 <p>See <A href="example/shared_ptr_example.cpp">shared_ptr_example.cpp</A> for a
    534                         complete example program. The program builds a <b>std::vector</b> and <b>std::set</b>
    535                         of <b>shared_ptr</b> objects.</p>
    536                 <p>Note that after the containers have been populated, some of the <b>shared_ptr</b>
     608                <blockquote>
     609                        <p><b>Returns:</b> If <code>*this</code> <em>owns</em> a deleter <code>d</code>
     610                                of type (cv-unqualified) <code>D</code>, returns <code>&amp;d</code>;
     611                                otherwise returns 0.</p>
     612                        <p><b>Throws:</b> nothing.</p>
     613                </blockquote>
     614                <h2 id="example">Example</h2>
     615                <p>See <a href="example/shared_ptr_example.cpp">shared_ptr_example.cpp</a> for a
     616                        complete example program. The program builds a <code>std::vector</code> and <code>std::set</code>
     617                        of <code>shared_ptr</code> objects.</p>
     618                <p>Note that after the containers have been populated, some of the <code>shared_ptr</code>
    537619                        objects will have a use count of 1 rather than a use count of 2, since the set
    538                         is a <b>std::set</b> rather than a <b>std::multiset</b>, and thus does not
     620                        is a <code>std::set</code> rather than a <code>std::multiset</code>, and thus does not
    539621                        contain duplicate entries. Furthermore, the use count may be even higher at
    540                         various times while <b>push_back</b> and <b>insert</b> container operations are
     622                        various times while <code>push_back</code> and <code>insert</code> container operations are
    541623                        performed. More complicated yet, the container operations may throw exceptions
    542624                        under a variety of circumstances. Getting the memory management and exception
    543625                        handling in this example right without a smart pointer would be a nightmare.</p>
    544                 <h2><a name="Handle/Body">Handle/Body</a> Idiom</h2>
    545                 <p>One common usage of <b>shared_ptr</b> is to implement a handle/body (also called
     626                <h2 id="HandleBody">Handle/Body Idiom</h2>
     627                <p>One common usage of <code>shared_ptr</code> is to implement a handle/body (also called
    546628                        pimpl) idiom which avoids exposing the body (implementation) in the header
    547629                        file.</p>
    548                 <p>The <A href="example/shared_ptr_example2_test.cpp">shared_ptr_example2_test.cpp</A>
    549                         sample program includes a header file, <A href="example/shared_ptr_example2.hpp">shared_ptr_example2.hpp</A>,
    550                         which uses a <b>shared_ptr&lt;&gt;</b> to an incomplete type to hide the
     630                <p>The <a href="example/shared_ptr_example2_test.cpp">shared_ptr_example2_test.cpp</a>
     631                        sample program includes a header file, <a href="example/shared_ptr_example2.hpp">shared_ptr_example2.hpp</a>,
     632                        which uses a <code>shared_ptr</code> to an incomplete type to hide the
    551633                        implementation. The instantiation of member functions which require a complete
    552                         type occurs in the <A href="example/shared_ptr_example2.cpp">shared_ptr_example2.cpp</A>
     634                        type occurs in the <a href="example/shared_ptr_example2.cpp">shared_ptr_example2.cpp</a>
    553635                        implementation file. Note that there is no need for an explicit destructor.
    554                         Unlike ~scoped_ptr, ~shared_ptr does not require that <b>T</b> be a complete
     636                        Unlike <code>~scoped_ptr</code>, <code>~shared_ptr</code> does not require that <code>T</code> be a complete
    555637                        type.</p>
    556                 <h2><a name="ThreadSafety">Thread Safety</a></h2>
    557                 <p><STRONG>shared_ptr</STRONG> objects offer the same level of thread safety as
    558                         built-in types. A <STRONG>shared_ptr</STRONG> instance can be "read" (accessed
    559                         using only const operations) simultaneously by multiple threads. Different <STRONG>shared_ptr</STRONG>
    560                         instances can be "written to" (accessed using mutable operations such as <STRONG>operator=
    561                         </STRONG>or <STRONG>reset</STRONG>) simultaneosly by multiple threads (even
     638                <h2 id="ThreadSafety">Thread Safety</h2>
     639                <p><code>shared_ptr</code> objects offer the same level of thread safety as
     640                        built-in types. A <code>shared_ptr</code> instance can be "read" (accessed
     641                        using only const operations) simultaneously by multiple threads. Different <code>shared_ptr</code>
     642                        instances can be "written to" (accessed using mutable operations such as <code>operator=
     643                        </code>or <code>reset</code>) simultaneosly by multiple threads (even
    562644                        when these instances are copies, and share the same reference count
    563645                        underneath.)</p>
    564                 <P>Any other simultaneous accesses result in undefined behavior.</P>
    565                 <P>Examples:</P>
     646                <p>Any other simultaneous accesses result in undefined behavior.</p>
     647                <p>Examples:</p>
    566648                <pre>shared_ptr&lt;int&gt; p(new int(42));
    567649
     
    607689</pre>
    608690                <p>&nbsp;</p>
    609                 <P>Starting with Boost release 1.33.0, <STRONG>shared_ptr</STRONG> uses a lock-free
    610                         implementation on the following platforms:</P>
    611                 <UL>
    612                         <LI>
    613                         GNU GCC on x86 or x86-64;
    614                         <LI>
    615                         GNU GCC on IA64;
    616                         <LI>
    617                         Metrowerks CodeWarrior on PowerPC;
    618                         <LI>
    619                         GNU GCC on PowerPC;
    620                         <LI>
    621                                 Windows.</LI></UL>
    622                 <P>If your program is single-threaded and does not link to any libraries that might
    623                         have used <STRONG>shared_ptr</STRONG> in its default configuration, you can <STRONG>
    624                                 #define</STRONG> the macro <STRONG>BOOST_SP_DISABLE_THREADS</STRONG> on a
    625                         project-wide basis to switch to ordinary non-atomic reference count updates.</P>
    626                 <P>(Defining <STRONG>BOOST_SP_DISABLE_THREADS</STRONG> in some, but not all,
     691                <p>Starting with Boost release 1.33.0, <code>shared_ptr</code> uses a lock-free
     692                        implementation on most common platforms.</p>
     693                <p>If your program is single-threaded and does not link to any libraries that might
     694                        have used <code>shared_ptr</code> in its default configuration, you can <code>
     695                                #define</code> the macro <code>BOOST_SP_DISABLE_THREADS</code> on a
     696                        project-wide basis to switch to ordinary non-atomic reference count updates.</p>
     697                <p>(Defining <code>BOOST_SP_DISABLE_THREADS</code> in some, but not all,
    627698                        translation units is technically a violation of the One Definition Rule and
    628699                        undefined behavior. Nevertheless, the implementation attempts to do its best to
    629700                        accommodate the request to use non-atomic updates in those translation units.
    630                         No guarantees, though.)</P>
    631                 <P>You can define the macro <STRONG>BOOST_SP_USE_PTHREADS</STRONG> to turn off the
    632                         lock-free platform-specific implementation and fall back to the generic <STRONG>pthread_mutex_t</STRONG>-based
    633                         code.</P>
    634                 <h2><a name="FAQ">Frequently Asked Questions</a></h2>
    635                 <P><B>Q.</B> There are several variations of shared pointers, with different
     701                        No guarantees, though.)</p>
     702                <p>You can define the macro <code>BOOST_SP_USE_PTHREADS</code> to turn off the
     703                        lock-free platform-specific implementation and fall back to the generic
     704                        <code>pthread_mutex_t</code>-based code.</p>
     705                <h2 id="FAQ">Frequently Asked Questions</h2>
     706                <p><b>Q.</b> There are several variations of shared pointers, with different
    636707                        tradeoffs; why does the smart pointer library supply only a single
    637708                        implementation? It would be useful to be able to experiment with each type so
    638                         as to find the most suitable for the job at hand?</P>
    639                 <P>
    640                         <b>A.</b> An important goal of <STRONG>shared_ptr</STRONG> is to provide a
     709                        as to find the most suitable for the job at hand?</p>
     710                <p>
     711                        <b>A.</b> An important goal of <code>shared_ptr</code> is to provide a
    641712                        standard shared-ownership pointer. Having a single pointer type is important
    642713                        for stable library interfaces, since different shared pointers typically cannot
    643714                        interoperate, i.e. a reference counted pointer (used by library A) cannot share
    644                         ownership with a linked pointer (used by library B.)<BR>
    645                 </P>
    646                 <P><B>Q.</B> Why doesn't <B>shared_ptr</B> have template parameters supplying
    647                         traits or policies to allow extensive user customization?</P>
    648                 <P>
    649                         <B>A.</B> Parameterization discourages users. The <B>shared_ptr</B> template is
     715                        ownership with a linked pointer (used by library B.)
     716                </p>
     717                <p><b>Q.</b> Why doesn't <code>shared_ptr</code> have template parameters supplying
     718                        traits or policies to allow extensive user customization?</p>
     719                <p>
     720                        <b>A.</b> Parameterization discourages users. The <code>shared_ptr</code> template is
    650721                        carefully crafted to meet common needs without extensive parameterization. Some
    651722                        day a highly configurable smart pointer may be invented that is also very easy
    652                         to use and very hard to misuse. Until then, <B>shared_ptr</B> is the smart
     723                        to use and very hard to misuse. Until then, <code>shared_ptr</code> is the smart
    653724                        pointer of choice for a wide range of applications. (Those interested in policy
    654                         based smart pointers should read <A href="http://www.awprofessional.com/bookstore/product.asp?isbn=0201704315&amp;rl=1">
    655                                 Modern C++ Design</A> by Andrei Alexandrescu.)<BR>
    656                 </P>
    657                 <P><B>Q.</B> I am not convinced. Default parameters can be used where appropriate
    658                         to hide the complexity. Again, why not policies?</P>
    659                 <P>
    660                         <B>A.</B> Template parameters affect the type. See the answer to the first
    661                         question above.<BR>
    662                 </P>
    663                 <P><B>Q.</B> Why doesn't <b>shared_ptr</b> use a linked list implementation?</P>
    664                 <P>
     725                        based smart pointers should read <a href="http://www.awprofessional.com/bookstore/product.asp?isbn=0201704315&amp;rl=1">
     726                                Modern C++ Design</a> by Andrei Alexandrescu.)
     727                </p>
     728                <p><b>Q.</b> I am not convinced. Default parameters can be used where appropriate
     729                        to hide the complexity. Again, why not policies?</p>
     730                <p>
     731                        <b>A.</b> Template parameters affect the type. See the answer to the first
     732                        question above.
     733                </p>
     734                <p><b>Q.</b> Why doesn't <code>shared_ptr</code> use a linked list implementation?</p>
     735                <p>
    665736                        <b>A.</b> A linked list implementation does not offer enough advantages to
    666                         offset the added cost of an extra pointer. See <A href="smarttests.htm">timings</A>
     737                        offset the added cost of an extra pointer. See <a href="smarttests.htm">timings</a>
    667738                        page. In addition, it is expensive to make a linked list implementation thread
    668                         safe.<BR>
    669                 </P>
    670                 <P><b>Q.</b> Why doesn't <b>shared_ptr</b> (or any of the other Boost smart
    671                         pointers) supply an automatic conversion to <b>T*</b>?</P>
    672                 <P>
    673                         <b>A.</b> Automatic conversion is believed to be too error prone.<BR>
    674                 </P>
    675                 <P><B>Q.</B> Why does <b>shared_ptr</b> supply use_count()?</P>
    676                 <P>
     739                        safe.
     740                </p>
     741                <p><b>Q.</b> Why doesn't <code>shared_ptr</code> (or any of the other Boost smart
     742                        pointers) supply an automatic conversion to <code>T*</code>?</p>
     743                <p>
     744                        <b>A.</b> Automatic conversion is believed to be too error prone.
     745                </p>
     746                <p><b>Q.</b> Why does <code>shared_ptr</code> supply use_count()?</p>
     747                <p>
    677748                        <b>A.</b> As an aid to writing test cases and debugging displays. One of the
    678                         progenitors had use_count(), and it was useful in tracking down bugs in a
    679                         complex project that turned out to have cyclic-dependencies.<BR>
    680                 </P>
    681                 <P><B>Q.</B> Why doesn't <b>shared_ptr</b> specify complexity requirements?</P>
    682                 <P>
     749                        progenitors had <code>use_count()</code>, and it was useful in tracking down bugs in a
     750                        complex project that turned out to have cyclic-dependencies.
     751                </p>
     752                <p><b>Q.</b> Why doesn't <code>shared_ptr</code> specify complexity requirements?</p>
     753                <p>
    683754                        <b>A.</b> Because complexity requirements limit implementors and complicate the
    684                         specification without apparent benefit to <b>shared_ptr</b> users. For example,
     755                        specification without apparent benefit to <code>shared_ptr</code> users. For example,
    685756                        error-checking implementations might become non-conforming if they had to meet
    686                         stringent complexity requirements.<BR>
    687                 </P>
    688                 <P><b>Q.</b> Why doesn't <b>shared_ptr</b> provide a release() function?</P>
    689                 <P>
    690                         <b>A.</b> <b>shared_ptr</b> cannot give away ownership unless it's unique()
    691                         because the other copy will still destroy the object.</P>
     757                        stringent complexity requirements.
     758                </p>
     759                <p><b>Q.</b> Why doesn't <code>shared_ptr</code> provide a <code>release()</code> function?</p>
     760                <p>
     761                        <b>A.</b> <code>shared_ptr</code> cannot give away ownership unless it's <code>unique()</code>
     762                        because the other copy will still destroy the object.</p>
    692763                <p>Consider:</p>
    693764                <blockquote><pre>shared_ptr&lt;int&gt; a(new int);
     
    699770                </blockquote>
    700771                <p>Furthermore, the pointer returned by <code>release()</code> would be difficult
    701                         to deallocate reliably, as the source <b>shared_ptr</b> could have been created
    702                         with a custom deleter.<BR>
    703                 </p>
    704                 <P><b>Q.</b> Why is <code>operator-&gt;()</code> const, but its return value is a
    705                         non-const pointer to the element type?</P>
    706                 <P>
     772                        to deallocate reliably, as the source <code>shared_ptr</code> could have been created
     773                        with a custom deleter.
     774                </p>
     775                <p><b>Q.</b> Why is <code>operator-&gt;()</code> const, but its return value is a
     776                        non-const pointer to the element type?</p>
     777                <p>
    707778                        <b>A.</b> Shallow copy pointers, including raw pointers, typically don't
    708779                        propagate constness. It makes little sense for them to do so, as you can always
    709780                        obtain a non-const pointer from a const one and then proceed to modify the
    710                         object through it.<b>shared_ptr</b> is "as close to raw pointers as possible
    711                         but no closer".<BR>
    712                         <BR>
    713                 </P>
    714                 <hr>
    715                 <p>
    716                         $Date$</p>
     781                        object through it. <code>shared_ptr</code> is "as close to raw pointers as possible
     782                        but no closer".
     783                </p>
     784                <hr />
    717785                <p><small>Copyright 1999 Greg Colvin and Beman Dawes. Copyright 2002 Darin Adler.
    718                                 Copyright 2002-2005 Peter Dimov. Distributed under the Boost Software License,
    719                                 Version 1.0. See accompanying file <A href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</A>
    720                                 or copy at <A href="http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</A>.</small></p>
     786                                Copyright 2002-2005, 2012 Peter Dimov. Distributed under the Boost Software License,
     787                                Version 1.0. See accompanying file <a href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a>
     788                                or copy at <a href="http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</a>.</small></p>
    721789        </body>
    722790</html>
  • branches/release/libs/smart_ptr/test/sp_unique_ptr_test.cpp

    r81335 r81781  
    9292        p3.reset();
    9393        BOOST_TEST( X::instances == 0 );
     94
     95        p2 = std::unique_ptr<X>( new X );
     96        BOOST_TEST( X::instances == 1 );
     97
     98        p2 = std::unique_ptr<X>( new X );
     99        BOOST_TEST( X::instances == 1 );
     100
     101        p2.reset();
     102        BOOST_TEST( X::instances == 0 );
     103    }
     104
     105    {
     106        BOOST_TEST( X::instances == 0 );
     107
     108        std::unique_ptr<X> p( new X );
     109        BOOST_TEST( X::instances == 1 );
     110
     111        boost::shared_ptr<X const> p2( std::move( p ) );
     112        BOOST_TEST( X::instances == 1 );
     113        BOOST_TEST( p.get() == 0 );
     114
     115        boost::shared_ptr<X const> p3 = p2->shared_from_this();
     116        BOOST_TEST( p2 == p3 );
     117        BOOST_TEST( !(p2 < p3) && !(p3 < p2) );
     118
     119        p2.reset();
     120        p3.reset();
     121        BOOST_TEST( X::instances == 0 );
     122
     123        p2 = std::unique_ptr<X>( new X );
     124        BOOST_TEST( X::instances == 1 );
     125
     126        p2 = std::unique_ptr<X>( new X );
     127        BOOST_TEST( X::instances == 1 );
     128
     129        p2.reset();
     130        BOOST_TEST( X::instances == 0 );
     131    }
     132
     133    {
     134        BOOST_TEST( X::instances == 0 );
     135
     136        std::unique_ptr<X> p( new X );
     137        BOOST_TEST( X::instances == 1 );
     138
     139        boost::shared_ptr<void> p2( std::move( p ) );
     140        BOOST_TEST( X::instances == 1 );
     141        BOOST_TEST( p.get() == 0 );
     142
     143        p2.reset();
     144        BOOST_TEST( X::instances == 0 );
     145
     146        p2 = std::unique_ptr<X>( new X );
     147        BOOST_TEST( X::instances == 1 );
     148
     149        p2 = std::unique_ptr<X>( new X );
     150        BOOST_TEST( X::instances == 1 );
     151
     152        p2.reset();
     153        BOOST_TEST( X::instances == 0 );
    94154    }
    95155
     
    106166        p2.reset();
    107167        BOOST_TEST( Y::instances == 0 );
     168
     169        p2 = std::unique_ptr<Y, YD>( new Y, YD() );
     170        BOOST_TEST( Y::instances == 1 );
     171
     172        p2 = std::unique_ptr<Y, YD>( new Y, YD() );
     173        BOOST_TEST( Y::instances == 1 );
     174
     175        p2.reset();
     176        BOOST_TEST( Y::instances == 0 );
    108177    }
    109178
     
    122191        p2.reset();
    123192        BOOST_TEST( Y::instances == 0 );
     193
     194        p2 = std::unique_ptr<Y, YD&>( new Y, yd );
     195        BOOST_TEST( Y::instances == 1 );
     196
     197        p2 = std::unique_ptr<Y, YD&>( new Y, yd );
     198        BOOST_TEST( Y::instances == 1 );
     199
     200        p2.reset();
     201        BOOST_TEST( Y::instances == 0 );
    124202    }
    125203
     
    135213        BOOST_TEST( Y::instances == 1 );
    136214        BOOST_TEST( p.get() == 0 );
     215
     216        p2.reset();
     217        BOOST_TEST( Y::instances == 0 );
     218
     219        p2 = std::unique_ptr<Y, YD const&>( new Y, yd );
     220        BOOST_TEST( Y::instances == 1 );
     221
     222        p2 = std::unique_ptr<Y, YD const&>( new Y, yd );
     223        BOOST_TEST( Y::instances == 1 );
    137224
    138225        p2.reset();
Note: See TracChangeset for help on using the changeset viewer.