mirror of
https://github.com/boostorg/smart_ptr.git
synced 2025-07-30 12:47:28 +02:00
Improve documentation for make_shared for arrays
This commit is contained in:
@ -8,13 +8,13 @@
|
||||
<h1><img height="86" alt="boost.png (6897 bytes)" src="../../boost.png"
|
||||
width="277" align="middle" border="0">make_shared and allocate_shared
|
||||
for arrays</h1>
|
||||
<p><a href="#Introduction">Introduction</a><br>
|
||||
<a href="#Synopsis">Synopsis</a><br>
|
||||
<p><a href="#introduction">Introduction</a><br>
|
||||
<a href="#synopsis">Synopsis</a><br>
|
||||
<a href="#common">Common Requirements</a><br>
|
||||
<a href="#functions">Free Functions</a><br>
|
||||
<a href="#example">Examples</a><br>
|
||||
<a href="#history">History</a><br>
|
||||
<a href="#references">References</a></p>
|
||||
<h2><a name="Introduction">Introduction</a></h2>
|
||||
<h2><a name="introduction">Introduction</a></h2>
|
||||
<p>Originally the Boost function templates <code>make_shared</code> and
|
||||
<code>allocate_shared</code> were for efficient allocation of shared
|
||||
objects only. There was a need to have efficient allocation of
|
||||
@ -28,24 +28,24 @@
|
||||
<code>make_shared</code> uses the global operator <code>new</code> to
|
||||
allocate memory, whereas <code>allocate_shared</code> uses an
|
||||
user-supplied allocator, allowing finer control.</p>
|
||||
<h2><a name="Synopsis">Synopsis</a></h2>
|
||||
<h2><a name="synopsis">Synopsis</a></h2>
|
||||
<pre>namespace boost {
|
||||
template<typename U> // U is T[]
|
||||
shared_ptr<U> <a href="#functions">make_shared</a>(size_t size);
|
||||
|
||||
template<typename U, typename A> // U is T[]
|
||||
shared_ptr<U> <a href="#functions">allocate_shared</a>(const A& allocator, size_t size);
|
||||
|
||||
|
||||
template<typename U> // U is T[N]
|
||||
shared_ptr<U> <a href="#functions">make_shared</a>();
|
||||
|
||||
template<typename U, typename A> // U is T[N]
|
||||
shared_ptr<U> <a href="#functions">allocate_shared</a>(const A& allocator);
|
||||
|
||||
|
||||
template<typename U> // U is T[]
|
||||
shared_ptr<U> <a href="#functions">make_shared</a>(size_t size, const T& value);
|
||||
|
||||
template<typename U, typename A> // U is T[]
|
||||
template<typename U, typename A> // U is T[]
|
||||
shared_ptr<U> <a href="#functions">allocate_shared</a>(const A& allocator, size_t size, const T& value);
|
||||
|
||||
template<typename U> // U is T[N]
|
||||
@ -66,95 +66,183 @@
|
||||
template<typename U, typename A> // U is T[N]
|
||||
shared_ptr<U> <a href="#functions">allocate_shared_noinit</a>(const A& allocator);
|
||||
}</pre>
|
||||
<h2><a name="functions">Free Functions</a></h2>
|
||||
<pre>template<typename U> // U is T[]
|
||||
shared_ptr<U> make_shared(size_t size);
|
||||
|
||||
template<typename U, typename A> // U is T[]
|
||||
shared_ptr<U> allocate_shared(const A& allocator, size_t size);
|
||||
|
||||
template<typename U> // U is T[N]
|
||||
shared_ptr<U> make_shared();
|
||||
|
||||
template<typename U, typename A> // U is T[N]
|
||||
shared_ptr<U> allocate_shared(const A& allocator);</pre>
|
||||
<h2><a name="common">Common Requirements</a></h2>
|
||||
<pre>template<typename U>
|
||||
shared_ptr<U> make_shared(<em>args</em>);
|
||||
template<typename U, typename A>
|
||||
shared_ptr<U> allocate_shared(const A& allocator, <em>args</em>);
|
||||
template<typename U>
|
||||
shared_ptr<U> make_shared_noinit(<em>args</em>);
|
||||
template<typename U, typename A>
|
||||
shared_ptr<U> allocate_shared_noinit(const A& allocator, <em>args</em>);</pre>
|
||||
<blockquote>
|
||||
<p><b>Requires:</b> The expression
|
||||
<code>new(pointer) T()</code>, where <code>pointer</code> is a
|
||||
<code>void*</code> pointing to storage suitable to hold an object of
|
||||
type <code>T</code>, shall be well-formed. <code>A</code> shall be an
|
||||
<em>Allocator</em>, as described in section 20.1.5 (<strong>Allocator
|
||||
requirements</strong>) of the C++ Standard. The copy constructor and
|
||||
destructor of <code>A</code> shall not throw.</p>
|
||||
<p><b>Effects:</b> Allocates memory suitable for an array of type
|
||||
<code>T</code> and size <code>size</code> and constructs an array of
|
||||
objects in it via the placement new expression <code>new(pointer)
|
||||
T()</code>. <code>allocate_shared</code> uses a copy of
|
||||
<code>allocator</code> to allocate memory. If an exception is thrown,
|
||||
has no effect.</p>
|
||||
<p><b>Requires:</b> <code>U</code> is of the form <code>T[]</code> or
|
||||
<code>T[N]</code>. <code>A</code> shall be an <em>Allocator</em>, as
|
||||
described in section 17.6.3.5 [<strong>Allocator
|
||||
requirements</strong>] of the C++ Standard. The copy constructor and
|
||||
destructor of <code>A</code> shall not throw exceptions.</p>
|
||||
<p><b>Effects:</b> Allocates memory for an object of type <code>U</code>
|
||||
(or <code>T[size]</code> when <code>U</code> is <code>T[]</code>,
|
||||
where <code>size</code> is determined from <code><em>args</em></code>
|
||||
as specified by the concrete overload). The object is initialized as
|
||||
specified by the concrete overload. The templates
|
||||
<code>allocate_shared</code> and <code>allocate_shared_noinit</code>
|
||||
use a copy of <code>allocator</code> to allocate memory. If an
|
||||
exception is thrown, the functions have no effect.</p>
|
||||
<p><b>Returns:</b> A <code>shared_ptr</code> instance that stores and
|
||||
owns the address of the newly constructed array of type <code>T</code>
|
||||
and size <code>size</code>.</p>
|
||||
<p><b>Postconditions:</b>
|
||||
<code>get() != 0 && use_count() == 1</code>.</p>
|
||||
<p><b>Throws:</b> <code>bad_alloc</code>, or an exception thrown from
|
||||
<code>A::allocate</code> or the constructor of <code>T</code>.</p>
|
||||
<p><b>Notes:</b> This implementation allocates the memory required for
|
||||
the returned <code>shared_ptr</code> and an array of type
|
||||
<code>T</code> of size <code>size</code> in a single allocation. This
|
||||
provides efficiency to equivalent to an intrusive smart pointer.</p>
|
||||
</blockquote>
|
||||
<pre>template<typename U> // U is T[]
|
||||
shared_ptr<U> make_shared(size_t size, const T& value);
|
||||
|
||||
template<typename U, typename A> // U is T[]
|
||||
shared_ptr<U> allocate_shared(const A& allocator, size_t size, const T& value);
|
||||
|
||||
template<typename U> // U is T[N]
|
||||
shared_ptr<U> make_shared(const T& value);
|
||||
|
||||
template<typename U, typename A> // U is T[N]
|
||||
shared_ptr<U> allocate_shared(const A& allocator, const T& value);</pre>
|
||||
<blockquote>
|
||||
<p><b>Notes:</b> These overloads initialize array objects with the given
|
||||
owns the address of the newly constructed object.</p>
|
||||
<p><b>Postconditions:</b> <code>r.get() != 0 &&
|
||||
r.use_count() == 1</code>, where <code>r</code> is the return
|
||||
value.</p>
|
||||
<p><b>Throws:</b> <code>bad_alloc</code>, an exception thrown from
|
||||
<code>A::allocate</code>, or from the initialization of the
|
||||
object.</p>
|
||||
</blockquote>
|
||||
<pre>template<typename U> // U is T[]
|
||||
shared_ptr<U> make_shared_noinit(size_t size);
|
||||
|
||||
template<typename U, typename A> // U is T[]
|
||||
shared_ptr<U> allocate_shared_noinit(const A& allocator, size_t size);
|
||||
|
||||
template<typename U> // U is T[N]
|
||||
shared_ptr<U> make_shared_noinit();
|
||||
|
||||
template<typename U, typename A> // U is T[N]
|
||||
shared_ptr<U> allocate_shared_noinit(const A& allocator);</pre>
|
||||
<blockquote>
|
||||
<p><b>Notes:</b> These overloads do not perform value initialization of
|
||||
array objects.</p>
|
||||
</blockquote>
|
||||
<h2><a name="example">Examples</a></h2>
|
||||
<p>The following examples value-initialize objects.</p>
|
||||
<blockquote>
|
||||
<pre>boost::shared_ptr<int[]> a1 = boost::make_shared<int[]>(size);
|
||||
boost::shared_ptr<int[8]> a2 = boost::make_shared<int[8]>();
|
||||
boost::shared_ptr<int[][2]> a3 = boost::make_shared<int[][2]>(size);
|
||||
boost::shared_ptr<int[4][2]> a4 = boost::make_shared<int[4][2]>();</pre>
|
||||
<p><b>Remarks:</b></p>
|
||||
<blockquote>
|
||||
<p>This implementation performs no more than one memory
|
||||
allocation. This provides efficiency to equivalent to an intrusive
|
||||
smart pointer.</p>
|
||||
<p>When an object of an array type <code>T</code> is specified to be
|
||||
initialized to a value of the same type <code>value</code>, this
|
||||
shall be interpreted to mean that each array element of the object
|
||||
is initialized to the corresponding element from
|
||||
<code>value</code>.</p>
|
||||
<p>When an object of an array type is specified to be
|
||||
value-initialized, this shall be interpreted to mean that each
|
||||
array element of the object is value-initialized.</p>
|
||||
<p>Array elements are initialized in ascending order of their
|
||||
addresses.</p>
|
||||
<p>When a subobject of a non-array type <code>T</code> is specified to
|
||||
be initialized to a value <code>value</code>, or to
|
||||
<code>T(list...)</code>, where <code>list...</code> is a list of
|
||||
constructor arguments, <code>make_shared</code> shall perform this
|
||||
initialization via the expression <code>::new(ptr) T(value)</code>
|
||||
or <code>::new(ptr) T(list...)</code> respectively, where
|
||||
<code>ptr</code> has type <code>void*</code> and points to storage
|
||||
suitable to hold an object of type <code>T</code>.</p>
|
||||
<p>When a subobject of non-array type <code>T</code> is specified to
|
||||
be value-initialized, <code>make_shared</code> shall perform this
|
||||
initialization via the expression <code>::new(ptr) T()</code>, where
|
||||
<code>ptr</code> has type <code>void*</code> and points to storage
|
||||
suitable to hold an object of type <code>T</code>.</p>
|
||||
<p>When a subobject of non-array type <code>T</code> is specified to
|
||||
be default-initialized, <code>make_shared_noinit</code> and
|
||||
<code>allocate_shared_noinit</code> shall perform this
|
||||
initialization via the expression <code>::new(ptr) T</code>, where
|
||||
<code>ptr</code> has type <code>void*</code> and points to storage
|
||||
suitable to hold an object of type <code>T</code>.</p>
|
||||
<p>When the lifetime of the object managed by the return value ends,
|
||||
or when the initialization of an array element throws an exception,
|
||||
the initialized elements should be destroyed in the reverse order
|
||||
of their construction.</p>
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
<p>The following examples initialize objects with a given value.</p>
|
||||
<h2><a name="functions">Free Functions</a></h2>
|
||||
<pre>template<typename U>
|
||||
shared_ptr<U> make_shared(size_t size);
|
||||
template<typename U, typename A>
|
||||
shared_ptr<U> allocate_shared(const A& allocator, size_t size);</pre>
|
||||
<blockquote>
|
||||
<pre>boost::shared_ptr<int[]> a5 = boost::make_shared<int[]>(size, 1);
|
||||
boost::shared_ptr<int[8]> a6 = boost::make_shared<int[8]>(1);
|
||||
boost::shared_ptr<int[][2]> a7 = boost::make_shared<int[][2]>(size, {1, 2});
|
||||
boost::shared_ptr<int[4][2]> a8 = boost::make_shared<int[4][2]>({1, 2});</pre>
|
||||
<p><b>Returns:</b> A <code>shared_ptr</code> to a value-initialized
|
||||
object of type <code>T[size]</code>.</p>
|
||||
<p><b>Remarks:</b> These overloads shall only participate in overload
|
||||
resolution when <code>U</code> is of the form <code>T[]</code>.</p>
|
||||
</blockquote>
|
||||
<p>The following examples default-initialize objects.</p>
|
||||
<blockquote>
|
||||
<pre>boost::shared_ptr<int[]> a9 = boost::make_shared_noinit<int[]>(size);
|
||||
boost::shared_ptr<int[8]> a10 = boost::make_shared_noinit<int[8]>();
|
||||
boost::shared_ptr<int[][2]> a11 = boost::make_shared_noinit<int[][2]>(size);
|
||||
boost::shared_ptr<int[4][2]> a12 = boost::make_shared_noinit<int[4][2]>();</pre>
|
||||
<p><b>Examples:</b></p>
|
||||
<blockquote>
|
||||
<pre>boost::shared_ptr<int[]> a1 = boost::make_shared<int[]>(size);
|
||||
boost::shared_ptr<int[][2]> a2 = boost::make_shared<int[][2]>(size);</pre>
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
<pre>template<typename U>
|
||||
shared_ptr<U> make_shared();
|
||||
template<typename U, typename A>
|
||||
shared_ptr<U> allocate_shared(const A& allocator);</pre>
|
||||
<blockquote>
|
||||
<p><b>Returns:</b> A <code>shared_ptr</code> to a value-initialized
|
||||
object of type <code>T[N]</code>.</p>
|
||||
<p><b>Remarks:</b> These overloads shall only participate in overload
|
||||
resolution when <code>U</code> is of the form <code>T[N]</code>.</p>
|
||||
</blockquote>
|
||||
<blockquote>
|
||||
<p><b>Examples:</b></p>
|
||||
<blockquote>
|
||||
<pre>boost::shared_ptr<int[8]> a1 = boost::make_shared<int[8]>();
|
||||
boost::shared_ptr<int[4][2]> a2 = boost::make_shared<int[4][2]>();</pre>
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
<pre>template<typename U>
|
||||
shared_ptr<U> make_shared(size_t size, const T& value);
|
||||
template<typename U, typename A>
|
||||
shared_ptr<U> allocate_shared(const A& allocator, size_t size, const T& value);</pre>
|
||||
<blockquote>
|
||||
<p><b>Returns:</b> A <code>shared_ptr</code> to an object of type
|
||||
<code>T[size]</code>, where each array element of type <code>T</code>
|
||||
is initialized to <code>value</code>.</p>
|
||||
<p><b>Remarks:</b> These overloads shall only participate in overload
|
||||
resolution when <code>U</code> is of the form <code>T[]</code>.</p>
|
||||
</blockquote>
|
||||
<blockquote>
|
||||
<p><b>Examples:</b></p>
|
||||
<blockquote>
|
||||
<pre>boost::shared_ptr<int[]> a1 = boost::make_shared<int[]>(size, 1);
|
||||
boost::shared_ptr<int[][2]> a2 = boost::make_shared<int[][2]>(size, {1, 2});</pre>
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
<pre>template<typename U>
|
||||
shared_ptr<U> make_shared(const T& value);
|
||||
template<typename U, typename A>
|
||||
shared_ptr<U> allocate_shared(const A& allocator, const T& value);</pre>
|
||||
<blockquote>
|
||||
<p><b>Returns:</b> A <code>shared_ptr</code> to an object of type
|
||||
<code>T[N]</code>, where each array element of type <code>T</code> is
|
||||
initialized to <code>value</code>.</p>
|
||||
<p><b>Remarks:</b> These overloads shall only participate in overload
|
||||
resolution when <code>U</code> is of the form <code>T[N]</code>.</p>
|
||||
</blockquote>
|
||||
<blockquote>
|
||||
<p><b>Examples:</b></p>
|
||||
<blockquote>
|
||||
<pre>boost::shared_ptr<int[8]> a1 = boost::make_shared<int[8]>(1);
|
||||
boost::shared_ptr<int[4][2]> a2 = boost::make_shared<int[4][2]>({1, 2});</pre>
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
<pre>template<typename U>
|
||||
shared_ptr<U> make_shared_noinit(size_t size);
|
||||
template<typename U, typename A>
|
||||
shared_ptr<U> allocate_shared_noinit(const A& allocator, size_t size);</pre>
|
||||
<blockquote>
|
||||
<p><b>Returns:</b> A <code>shared_ptr</code> to a default-initialized
|
||||
object of type <code>T[size]</code>.</p>
|
||||
<p><b>Remarks:</b> These overloads shall only participate in overload
|
||||
resolution when <code>U</code> is of the form <code>T[]</code>.</p>
|
||||
</blockquote>
|
||||
<blockquote>
|
||||
<p><b>Examples:</b></p>
|
||||
<blockquote>
|
||||
<pre>boost::shared_ptr<int[]> a1 = boost::make_shared_noinit<int[]>(size);
|
||||
boost::shared_ptr<int[][2]> a2 = boost::make_shared_noinit<int[][2]>(size);</pre>
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
<pre>template<typename U>
|
||||
shared_ptr<U> make_shared_noinit();
|
||||
template<typename U, typename A>
|
||||
shared_ptr<U> allocate_shared_noinit(const A& allocator);</pre>
|
||||
<blockquote>
|
||||
<p><b>Returns:</b> A <code>shared_ptr</code> to a default-initialized
|
||||
object of type <code>T[N]</code>.</p>
|
||||
<p><b>Remarks:</b> These overloads shall only participate in overload
|
||||
resolution when <code>U</code> is of the form <code>T[N]</code>.</p>
|
||||
</blockquote>
|
||||
<blockquote>
|
||||
<p><b>Examples:</b></p>
|
||||
<blockquote>
|
||||
<pre>boost::shared_ptr<int[8]> a1 = boost::make_shared_noinit<int[8]>();
|
||||
boost::shared_ptr<int[4][2]> a2 = boost::make_shared_noinit<int[4][2]>();</pre>
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
<h2><a name="history">History</a></h2>
|
||||
<p>January 2014. Glen Fernandes reduced the overloads of make_shared and
|
||||
|
168
make_unique.html
168
make_unique.html
@ -7,16 +7,16 @@
|
||||
<body text="#000000" bgcolor="#ffffff" link="#0000ff" vlink="#0000ff">
|
||||
<h1><img height="86" alt="boost.png (6897 bytes)" src="../../boost.png"
|
||||
width="277" align="middle" border="0">make_unique</h1>
|
||||
<p><a href="#Introduction">Introduction</a><br>
|
||||
<a href="#Synopsis">Synopsis</a><br>
|
||||
<p><a href="#introduction">Introduction</a><br>
|
||||
<a href="#synopsis">Synopsis</a><br>
|
||||
<a href="#common">Common Requirements</a><br>
|
||||
<a href="#functions">Free Functions</a><br>
|
||||
<a href="#example">Examples</a><br>
|
||||
<a href="#history">History</a></p>
|
||||
<h2><a name="Introduction">Introduction</a></h2>
|
||||
<h2><a name="introduction">Introduction</a></h2>
|
||||
<p>The header file <boost/make_unique.hpp> provides overloaded
|
||||
function template <code>make_unique</code> for convenient creation of
|
||||
<code>unique_ptr</code> objects.</p>
|
||||
<h2><a name="Synopsis">Synopsis</a></h2>
|
||||
<h2><a name="synopsis">Synopsis</a></h2>
|
||||
<pre>namespace boost {
|
||||
template<typename U> // U is not array
|
||||
unique_ptr<U> <a href="#functions">make_unique</a>();
|
||||
@ -29,103 +29,127 @@
|
||||
template<typename U> // U is not array
|
||||
unique_ptr<U> <a href="#functions">make_unique</a>(U&& value);
|
||||
|
||||
template<typename U> // U is T[]
|
||||
unique_ptr<U> <a href="#functions">make_unique</a>(size_t size);
|
||||
|
||||
template<typename U> // U is not array
|
||||
unique_ptr<U> <a href="#functions">make_unique_noinit</a>();
|
||||
|
||||
template<typename U> // U is T[]
|
||||
unique_ptr<U> <a href="#functions">make_unique</a>(size_t size);
|
||||
|
||||
template<typename U> // U is T[]
|
||||
unique_ptr<U> <a href="#functions">make_unique_noinit</a>(size_t size);
|
||||
}</pre>
|
||||
<h2><a name="functions">Free Functions</a></h2>
|
||||
<pre>template<typename U> // U is not array
|
||||
unique_ptr<U> make_unique();</pre>
|
||||
<h2><a name="common">Common Requirements</a></h2>
|
||||
<pre>template<typename U>
|
||||
unique_ptr<U> make_unique(<em>args</em>);
|
||||
template<typename U>
|
||||
unique_ptr<U> make_unique_noinit(<em>args</em>);</pre>
|
||||
<blockquote>
|
||||
<p><b>Requires:</b> The expression <code>new U()</code> shall be
|
||||
well-formed.</p>
|
||||
<p><b>Effects:</b> Constructs an object of type <code>U</code> via the
|
||||
expression <code>new U()</code>.</p>
|
||||
<p><b>Effects:</b> Allocates memory for an object of type <code>U</code>
|
||||
(or <code>T[size]</code> when <code>U</code> is <code>T[]</code>,
|
||||
where <code>size</code> is determined from <code>args</code> as
|
||||
specified by the concrete overload). The object is initialized from
|
||||
<code>args</code> as specified by the concrete overload. If an
|
||||
exception is thrown, the functions have no effect.</p>
|
||||
<p><b>Returns:</b> A <code>unique_ptr</code> instance that stores and
|
||||
owns the address of the newly constructed object.</p>
|
||||
<p><b>Postconditions:</b> <code>get() != 0</code>.</p>
|
||||
<p><b>Postconditions:</b> <code>r.get() != 0</code>, where
|
||||
<code>r</code> is the return value.</p>
|
||||
<p><b>Throws:</b> <code>bad_alloc</code>, or an exception thrown from
|
||||
the constructor of <code>U</code>.</p>
|
||||
the initialization of the object.</p>
|
||||
</blockquote>
|
||||
<pre>template<typename U, typename... Args> // U is not array
|
||||
unique_ptr<U> make_unique(Args&&... args);</pre>
|
||||
<blockquote>
|
||||
<p><b>Requires:</b> The expression
|
||||
<code>new U(forward<Args>(args)...)</code> shall be
|
||||
well-formed.</p>
|
||||
<p><b>Effects:</b> Constructs an object of type <code>U</code> via the
|
||||
expression <code>new U(forward<Args>(args)...)</code>.</p>
|
||||
<p><b>Remarks:</b></p>
|
||||
<blockquote>
|
||||
<p>When an object of a non-array type <code>T</code> is specified to
|
||||
be initialized to a value <code>value</code>, or to
|
||||
<code>T(list...)</code>, where <code>list...</code> is a list of
|
||||
constructor arguments, <code>make_unique</code> shall perform this
|
||||
initialization via the expression <code>new T(value)</code> or
|
||||
<code>new T(list...)</code> respectively.</p>
|
||||
<p>When an object of type <code>T</code> is specified to be
|
||||
value-initialized, <code>make_unique</code> shall perform this
|
||||
initialization via the expression <code>new T()</code>.</p>
|
||||
<p>When an object of type <code>T</code> is specified to be
|
||||
default-initialized, <code>make_unique_noinit</code> shall perform
|
||||
this initialization via the expression <code>new T</code>.</p>
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
<pre>template<typename U> // U is not array
|
||||
<h2><a name="functions">Free Functions</a></h2>
|
||||
<pre>template<typename U, typename... Args>
|
||||
unique_ptr<U> make_unique(Args&&... args);</pre>
|
||||
<blockquote>
|
||||
<p><b>Returns:</b> A unique_ptr to an object of type <code>U</code>,
|
||||
initialized to <code>U(forward<Args>(args)...)</code>.</p>
|
||||
<p><b>Remarks:</b> This overload shall only participate in overload
|
||||
resolution when <code>U</code> is not an array type.</p>
|
||||
</blockquote>
|
||||
<blockquote>
|
||||
<p><b>Examples:</b></p>
|
||||
<blockquote>
|
||||
<pre>unique_ptr<float> p1 = boost::make_unique<float>();
|
||||
unique_ptr<point> p2 = boost::make_unique<point>(x, y);</pre>
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
<pre>template<typename U>
|
||||
unique_ptr<U> make_unique(U&& value);</pre>
|
||||
<blockquote>
|
||||
<p><b>Requires:</b> The expression <code>new U(move(value))</code> shall
|
||||
be well-formed.</p>
|
||||
<p><b>Effects:</b> Constructs an object of type <code>U</code> via the
|
||||
expression <code>new U(move(value))</code>.</p>
|
||||
<p><b>Returns:</b> A unique_ptr to an object of type <code>U</code>,
|
||||
initialized to <code>move(value)</code>.</p>
|
||||
<p><b>Remarks:</b> This overload shall only participate in overload
|
||||
resolution when <code>U</code> is not an array type.</p>
|
||||
</blockquote>
|
||||
<pre>template<typename U> // U is not array
|
||||
unique_ptr<U> make_unique_noinit();</pre>
|
||||
<blockquote>
|
||||
<p><b>Requires:</b> The expression <code>new U</code> shall be
|
||||
well-formed.</p>
|
||||
<p><b>Effects:</b> Constructs an object of type <code>U</code> via the
|
||||
expression <code>new U</code>.</p>
|
||||
<p><b>Examples:</b></p>
|
||||
<blockquote>
|
||||
<pre>unique_ptr<string> p1 = boost::make_unique<string>({'a', 'b'});
|
||||
unique_ptr<point> p2 = boost::make_unique<point>({-10, 25});</pre>
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
<pre>template<typename U> // U is T[]
|
||||
unique_ptr<U> make_unique(size_t size);</pre>
|
||||
<pre>template<typename U>
|
||||
unique_ptr<U> make_unique(size_t size);</pre>
|
||||
<blockquote>
|
||||
<p><b>Requires:</b> The expression <code>new T[size]()</code> shall be
|
||||
well-formed.</p>
|
||||
<p><b>Effects:</b> Constructs an array of objects of type
|
||||
<code>U</code> and size <code>size</code> via the expression
|
||||
<code>new T[size]()</code>.</p>
|
||||
<p><b>Returns:</b> A unique_ptr to a value-initialized object of type
|
||||
<code>T[size]</code>.</p>
|
||||
<p><b>Remarks:</b> This overload shall only participate in overload
|
||||
resolution when <code>U</code> is of the form <code>T[]</code>.</p>
|
||||
</blockquote>
|
||||
<pre>template<typename U> // U is T[]
|
||||
unique_ptr<U> make_unique_noinit(size_t size);</pre>
|
||||
<blockquote>
|
||||
<p><b>Requires:</b> The expression <code>new T[size]</code> shall be
|
||||
well-formed.</p>
|
||||
<p><b>Effects:</b> Constructs an array of objects of type
|
||||
<code>U</code> and size <code>size</code> via the expression
|
||||
<code>new T[size]</code>.</p>
|
||||
</blockquote>
|
||||
<h2><a name="example">Examples</a></h2>
|
||||
<p>For objects with value-initialization.</p>
|
||||
<blockquote>
|
||||
<pre>unique_ptr<float> p1 = boost::make_unique<float>();
|
||||
unique_ptr<point> p2 = boost::make_unique<point>();</pre>
|
||||
<p><b>Examples:</b></p>
|
||||
<blockquote>
|
||||
<pre>unique_ptr<double[]> p1 = boost::make_unique<double[]>(4);
|
||||
unique_ptr<int[][2]> p2 = boost::make_unique<int[][2]>(2);</pre>
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
<p>For objects with construction arguments.</p>
|
||||
<pre>template<typename U>
|
||||
unique_ptr<U> make_unique_noinit();</pre>
|
||||
<blockquote>
|
||||
<pre>unique_ptr<float> p3 = boost::make_unique<float>(1.0f);
|
||||
unique_ptr<point> p4 = boost::make_unique<point>(x, y);</pre>
|
||||
<p><b>Returns:</b> A unique_ptr to a default-initialized object of
|
||||
type <code>U</code>.</p>
|
||||
<p><b>Remarks:</b> This overload shall only participate in overload
|
||||
resolution when <code>U</code> is not an array type.</p>
|
||||
</blockquote>
|
||||
<p>For objects with given value.</p>
|
||||
<blockquote>
|
||||
<pre>unique_ptr<string> p4 = boost::make_unique<string>({'a', 'b'});
|
||||
unique_ptr<type> p5 = boost::make_unique<type>({3, 5, 4});</pre>
|
||||
<p><b>Examples:</b></p>
|
||||
<blockquote>
|
||||
<pre>unique_ptr<float> p1 = boost::make_unique_noinit<float>();
|
||||
unique_ptr<point> p2 = boost::make_unique_noinit<point>();</pre>
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
<p>For objects with default-initialization.</p>
|
||||
<pre>template<typename U>
|
||||
unique_ptr<U> make_unique_noinit(size_t size);</pre>
|
||||
<blockquote>
|
||||
<pre>unique_ptr<float> p6 = boost::make_unique_noinit<float>();
|
||||
unique_ptr<point> p7 = boost::make_unique_noinit<point>();</pre>
|
||||
<p><b>Returns:</b> A unique_ptr to a default-initialized object of
|
||||
type <code>T[size]</code>.</p>
|
||||
<p><b>Remarks:</b> This overload shall only participate in overload
|
||||
resolution when <code>U</code> is of the form <code>T[]</code>.</p>
|
||||
</blockquote>
|
||||
<p>For arrays with value-initialization.</p>
|
||||
<blockquote>
|
||||
<pre>unique_ptr<double[]> a1 = boost::make_unique<double[]>();
|
||||
unique_ptr<int[][4]> a2 = boost::make_unique<int[][4]>();</pre>
|
||||
<p><b>Examples:</b></p>
|
||||
<blockquote>
|
||||
<pre>unique_ptr<double[]> p1 = boost::make_unique_noinit<double[]>(4);
|
||||
unique_ptr<int[][2]> p2 = boost::make_unique_noinit<int[][2]>(2);</pre>
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
<p>For arrays with default-initialization.</p>
|
||||
<blockquote>
|
||||
<pre>unique_ptr<double[]> a3 = boost::make_unique_noinit<double[]>();
|
||||
unique_ptr<int[][4]> a4 = boost::make_unique_noinit<int[][4]>();</pre>
|
||||
</blockquote>
|
||||
<h2><a name="history">History</a></h2>
|
||||
<p>January 2014. Glen Fernandes contributed implementations of
|
||||
make_unique for objects and arrays.</p>
|
||||
|
Reference in New Issue
Block a user