Ticket #1897: shared_ptr.htm.patch

File shared_ptr.htm.patch, 3.8 KB (added by Frank Mori Hess, 14 years ago)
  • shared_ptr.htm

     
    146146  template<class T, class U>
    147147    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
    148148
     149  template&lt;class T, class... Args&gt;
     150    shared_ptr&lt;T&gt; <a href="#object_creation">make_shared</a>( Args &amp;&amp; ... args );
     151
     152  template&lt;class T, class A, class... Args&gt;
     153    shared_ptr&lt;T&gt; <a href="#object_creation">allocate_shared</a>( A const &amp; a, Args &amp;&amp; ... args );
     154
    149155  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
    150156
    151157  template&lt;class T&gt; T * <A href="#get_pointer" >get_pointer</A>(shared_ptr&lt;T&gt; const &amp; p); // never throws
     
    437443                                also implement their <STRONG>operator&lt;</STRONG> in terms of their contained
    438444                                subobjects' <STRONG>operator&lt;</STRONG>.</EM></P>
    439445                <P><EM>The rest of the comparison operators are omitted by design.]</EM></P>
     446                <h3><a name="object_creation">object creation</a></h3>
     447                <pre>template&lt;class T, class... Args&gt;
     448    shared_ptr&lt;T&gt; make_shared( Args &amp;&amp; ... args );
     449template&lt;class T, class A, class... Args&gt;
     450    shared_ptr&lt;T&gt; allocate_shared( A const &amp; a, Args &amp;&amp; ... args );</pre>
     451                <blockquote>
     452                        <p><b>Requires:</b> The expression <code>new( pv ) T( std::forward&lt;Args&gt;(args)... )</code>,
     453                                where <code>pv</code> is a <code>void*</code> pointing to storage suitable
     454                                to hold an object of type <code>T</code>,
     455                                shall be well-formed.  <code>A</code> shall be an <em>Allocator</em>,
     456                                as described in section 20.1.5 (<stong>Allocator requirements</strong>) of the C++ Standard.
     457                                The copy constructor and destructor of <code>A</code> shall not throw.</p>
     458                        <p><b>Effects:</b> Allocates memory suitable for an object of type <code>T</code>
     459                                and constructs an object in it via the placement new expression <code>new( pv ) T()</code>
     460                                or <code>new( pv ) T( std::forward&lt;Args&gt;(args)... )</code>.
     461                                <code>allocate_shared</code> uses a copy of <code>a</code> to allocate memory.
     462                                If an exception is thrown, has no effect.</p>
     463                        <p><b>Returns:</b> A <code>shared_ptr</code> instance that stores and owns the address
     464                                of the newly constructed object of type <code>T</code>.</p>
     465                        <p><b>Postconditions:</b> <code>get() != 0 &amp;&amp; use_count() == 1</code>.</p>
     466                        <p><b>Throws:</b> <code>bad_alloc</code>, or an exception thrown from <code>A::allocate</code>
     467                                or the constructor of <code>T</code>.</p>
     468                        <p><b>Notes:</b> This implementation allocates the memory required for the
     469                        returned <code>shared_ptr</code> and an object of type <code>T</code> in a single
     470                        allocation. This provides efficiency equivalent to an intrusive smart pointer.</p>
     471                        <p>The prototypes shown above are used if your compiler supports rvalue references
     472                        and variadic templates.  They perfectly forward the <code>args</code> parameters to
     473                        the constructors of <code>T</code>.</p>
     474                        <p>Otherwise, the implementation will fall back on
     475                        forwarding the arguments to the constructors of <code>T</code> as const references.
     476                        If you need to pass a non-const reference to a constructor of <code>T</code>,
     477                        you may do so by wrapping the parameter in a call to <code>boost::ref</code>.
     478                        In addition, you will be
     479                        limited to a maximum of 9 arguments (not counting the allocator argument of
     480                        allocate_shared).</p>
     481                </blockquote>
    440482                <h3><a name="free-swap">swap</a></h3>
    441483                <pre>template&lt;class T&gt;
    442484  void swap(shared_ptr&lt;T&gt; &amp; a, shared_ptr&lt;T&gt; &amp; b); // never throws</pre>