Index: shared_ptr.htm =================================================================== --- shared_ptr.htm (revision 45160) +++ shared_ptr.htm (working copy) @@ -146,6 +146,12 @@ template<class T, class U> bool operator<(shared_ptr<T> const & a, shared_ptr<U> const & b); // never throws + template<class T, class... Args> + shared_ptr<T> make_shared( Args && ... args ); + + template<class T, class A, class... Args> + shared_ptr<T> allocate_shared( A const & a, Args && ... args ); + template<class T> void swap(shared_ptr<T> & a, shared_ptr<T> & b); // never throws template<class T> T * get_pointer(shared_ptr<T> const & p); // never throws @@ -437,6 +443,42 @@ also implement their operator< in terms of their contained subobjects' operator<.
The rest of the comparison operators are omitted by design.]
+template<class T, class... Args> + shared_ptr<T> make_shared( Args && ... args ); +template<class T, class A, class... Args> + shared_ptr<T> allocate_shared( A const & a, Args && ... args );+
+Requires: The expression
+new( pv ) T( std::forward<Args>(args)... )
, + wherepv
is avoid*
pointing to storage suitable + to hold an object of typeT
, + shall be well-formed.A
shall be an Allocator, + as described in section 20.1.5 (Allocator requirements) of the C++ Standard. + The copy constructor and destructor of A
shall not throw.Effects: Allocates memory suitable for an object of type
+T
+ and constructs an object in it via the placement new expressionnew( pv ) T()
+ ornew( pv ) T( std::forward<Args>(args)... )
. +allocate_shared
uses a copy ofa
to allocate memory. + If an exception is thrown, has no effect.Returns: A
+shared_ptr
instance that stores and owns the address + of the newly constructed object of typeT
.Postconditions:
+get() != 0 && use_count() == 1
.Throws:
+bad_alloc
, or an exception thrown fromA::allocate
+ or the constructor ofT
.Notes: This implementation allocates the memory required for the + returned
+shared_ptr
and an object of typeT
in a single + allocation. This provides efficiency equivalent to an intrusive smart pointer.The prototypes shown above are used if your compiler supports rvalue references + and variadic templates. They perfectly forward the
+args
parameters to + the constructors ofT
.Otherwise, the implementation will fall back on + forwarding the arguments to the constructors of
+T
as const references. + If you need to pass a non-const reference to a constructor ofT
, + you may do so by wrapping the parameter in a call toboost::ref
. + In addition, you will be + limited to a maximum of 9 arguments (not counting the allocator argument of + allocate_shared).
template<class T> void swap(shared_ptr<T> & a, shared_ptr<T> & b); // never throws