mirror of
https://github.com/boostorg/smart_ptr.git
synced 2025-07-31 21:24:40 +02:00
Merge pull request #36 from boostorg/develop
Merge documentation changes
This commit is contained in:
@@ -1,278 +1,365 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
<html>
|
||||
<head>
|
||||
<title>make_shared and allocate_shared for arrays</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
</head>
|
||||
<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_shared and allocate_shared
|
||||
for arrays</h1>
|
||||
<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="#history">History</a><br>
|
||||
<a href="#references">References</a></p>
|
||||
<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
|
||||
shared arrays. One criticism of class template <code>shared_array</code>
|
||||
was always the lack of a <a href="make_shared.html">make_shared</a>
|
||||
utility which ensures only a single allocation.</p>
|
||||
<p>The header files <boost/smart_ptr/make_shared_array.hpp> and
|
||||
<boost/smart_ptr/allocate_shared_array.hpp> provide function
|
||||
templates, overloads of <code>make_shared</code> and
|
||||
<code>allocate_shared</code> for array types, to address this need.
|
||||
<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>
|
||||
<pre>namespace boost {
|
||||
template<class U> // U is T[]
|
||||
shared_ptr<U> <a href="#functions">make_shared</a>(size_t size);
|
||||
|
||||
template<class U, class A> // U is T[]
|
||||
shared_ptr<U> <a href="#functions">allocate_shared</a>(const A& allocator, size_t size);
|
||||
|
||||
template<class U> // U is T[N]
|
||||
shared_ptr<U> <a href="#functions">make_shared</a>();
|
||||
|
||||
template<class U, class A> // U is T[N]
|
||||
shared_ptr<U> <a href="#functions">allocate_shared</a>(const A& allocator);
|
||||
|
||||
template<class U> // U is T[]
|
||||
shared_ptr<U> <a href="#functions">make_shared</a>(size_t size, const T& value);
|
||||
|
||||
template<class U, class A> // U is T[]
|
||||
shared_ptr<U> <a href="#functions">allocate_shared</a>(const A& allocator, size_t size, const T& value);
|
||||
|
||||
template<class U> // U is T[N]
|
||||
shared_ptr<U> <a href="#functions">make_shared</a>(const T& value);
|
||||
|
||||
template<class U, class A> // U is T[N]
|
||||
shared_ptr<U> <a href="#functions">allocate_shared</a>(const A& allocator, const T& value);
|
||||
|
||||
template<class U> // U is T[]
|
||||
shared_ptr<U> <a href="#functions">make_shared_noinit</a>(size_t size);
|
||||
|
||||
template<class U, class A> // U is T[]
|
||||
shared_ptr<U> <a href="#functions">allocate_shared_noinit</a>(const A& allocator, size_t size);
|
||||
|
||||
template<class U> // U is T[N]
|
||||
shared_ptr<U> <a href="#functions">make_shared_noinit</a>();
|
||||
|
||||
template<class U, class A> // U is T[N]
|
||||
shared_ptr<U> <a href="#functions">allocate_shared_noinit</a>(const A& allocator);
|
||||
}</pre>
|
||||
<h2><a name="common">Common Requirements</a></h2>
|
||||
<pre>template<class U>
|
||||
shared_ptr<U> make_shared(<em>args</em>);</pre>
|
||||
<pre>template<class U, class A>
|
||||
shared_ptr<U> allocate_shared(const A& allocator, <em>args</em>);</pre>
|
||||
<pre>template<class U>
|
||||
shared_ptr<U> make_shared_noinit(<em>args</em>);</pre>
|
||||
<pre>template<class U, class A>
|
||||
shared_ptr<U> allocate_shared_noinit(const A& allocator, <em>args</em>);</pre>
|
||||
<blockquote>
|
||||
<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 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>
|
||||
<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>,
|
||||
<code>make_shared</code> shall perform this initialization via the
|
||||
expression <code>::new(ptr) T(value)</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 initialized to a value <code>value</code>,
|
||||
<code>allocate_shared</code> shall perform this initialization via
|
||||
the expression <code>allocator_traits<A2>::construct(a2, ptr,
|
||||
value)</code>, where <code>ptr</code> points to storage suitable to
|
||||
hold an object of type <code>T</code> and <code>a2</code> of type A2
|
||||
is a rebound copy of the allocator <code>allocator</code> passed to
|
||||
<code>allocate_shared</code> such that its <code>value_type</code>
|
||||
is <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 value-initialized, <code>allocate_shared</code> shall perform
|
||||
this initialization via the expression
|
||||
<code>allocator_traits<A2>::construct(a2, ptr)</code>, where
|
||||
<code>ptr</code> points to storage suitable to hold an object
|
||||
of type <code>T</code> and <code>a2</code> of type A2 is a rebound
|
||||
copy of the allocator <code>allocator</code> passed to
|
||||
<code>allocate_shared</code> such that its <code>value_type</code>
|
||||
is <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>
|
||||
<p><b>Notes:</b> These functions will typically allocate more memory
|
||||
than <code>sizeof(U)</code> to allow for internal bookkeeping
|
||||
structures such as the reference counts.</p>
|
||||
</blockquote>
|
||||
<h2><a name="functions">Free Functions</a></h2>
|
||||
<pre>template<class U>
|
||||
shared_ptr<U> make_shared(size_t size);</pre>
|
||||
<pre>template<class U, class A>
|
||||
shared_ptr<U> allocate_shared(const A& allocator, size_t size);</pre>
|
||||
<blockquote>
|
||||
<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>
|
||||
<p><b>Examples:</b></p>
|
||||
<blockquote>
|
||||
<pre>boost::shared_ptr<int[]> a1 = boost::make_shared<int[]>(size);</pre>
|
||||
<pre>boost::shared_ptr<int[][2]> a2 = boost::make_shared<int[][2]>(size);</pre>
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
<pre>template<class U>
|
||||
shared_ptr<U> make_shared();</pre>
|
||||
<pre>template<class U, class 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>
|
||||
<p><b>Examples:</b></p>
|
||||
<blockquote>
|
||||
<pre>boost::shared_ptr<int[8]> a1 = boost::make_shared<int[8]>();</pre>
|
||||
<pre>boost::shared_ptr<int[4][2]> a2 = boost::make_shared<int[4][2]>();</pre>
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
<pre>template<class U>
|
||||
shared_ptr<U> make_shared(size_t size, const T& value);</pre>
|
||||
<pre>template<class U, class 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>
|
||||
<p><b>Examples:</b></p>
|
||||
<blockquote>
|
||||
<pre>boost::shared_ptr<int[]> a1 = boost::make_shared<int[]>(size, 1);</pre>
|
||||
<pre>boost::shared_ptr<int[][2]> a2 = boost::make_shared<int[][2]>(size, {1, 2});</pre>
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
<pre>template<class U>
|
||||
shared_ptr<U> make_shared(const T& value);</pre>
|
||||
<pre>template<class U, class 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>
|
||||
<p><b>Examples:</b></p>
|
||||
<blockquote>
|
||||
<pre>boost::shared_ptr<int[8]> a1 = boost::make_shared<int[8]>(1);</pre>
|
||||
<pre>boost::shared_ptr<int[4][2]> a2 = boost::make_shared<int[4][2]>({1, 2});</pre>
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
<pre>template<class U>
|
||||
shared_ptr<U> make_shared_noinit(size_t size);</pre>
|
||||
<pre>template<class U, class 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>
|
||||
<p><b>Examples:</b></p>
|
||||
<blockquote>
|
||||
<pre>boost::shared_ptr<int[]> a1 = boost::make_shared_noinit<int[]>(size);</pre>
|
||||
<pre>boost::shared_ptr<int[][2]> a2 = boost::make_shared_noinit<int[][2]>(size);</pre>
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
<pre>template<class U>
|
||||
shared_ptr<U> make_shared_noinit();</pre>
|
||||
<pre>template<class U, class 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>
|
||||
<p><b>Examples:</b></p>
|
||||
<blockquote>
|
||||
<pre>boost::shared_ptr<int[8]> a1 = boost::make_shared_noinit<int[8]>();</pre>
|
||||
<pre>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>February 2017. Glen Fernandes rewrote allocate_shared and make_shared
|
||||
for a more optimal and more maintainable implementation.</p>
|
||||
<p>February 2014. Glen Fernandes updated overloads of make_shared and
|
||||
allocate_shared to conform to the specification in C++ standard paper
|
||||
<a href="#N3870">N3870</a>, including resolving C++ standard library
|
||||
defect report <a href="#2070">DR2070</a>.</p>
|
||||
<p>November 2012. Glen Fernandes contributed implementations of
|
||||
make_shared and allocate_shared for arrays.</p>
|
||||
<h2><a name="references">References</a></h2>
|
||||
<p><a name="N3870">N3870</a>,
|
||||
<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n3870.html">
|
||||
Extending make_shared to Support Arrays, Revision 1</a>, Peter Dimov
|
||||
& Glen Fernandes, January, 2014.</p>
|
||||
<p><a name="DR2070">DR2070</a>,
|
||||
<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-active.html">
|
||||
allocate_shared should use allocator_traits<A>::construct</a>,
|
||||
Jonathan Wakely, July, 2011.</p>
|
||||
<hr>
|
||||
<p>$Date$</p>
|
||||
<p><small>Copyright 2012-2014 Glen Fernandes. Distributed under the
|
||||
Boost Software License, Version 1.0. See accompanying file
|
||||
<a href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or copy at
|
||||
<a href="http://www.boost.org/LICENSE_1_0.txt">
|
||||
http://www.boost.org/LICENSE_1_0.txt</a>.</small></p>
|
||||
</body>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>allocate_shared and make_shared for arrays</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>allocate_shared and make_shared for arrays</h1>
|
||||
<div id="navigation">
|
||||
<ul>
|
||||
<li><a href="#introduction">Introduction</a></li>
|
||||
<li><a href="#synopsis">Synopsis</a></li>
|
||||
<li><a href="#requirements">Common Requirements</a></li>
|
||||
<li><a href="#functions">Free Functions</a></li>
|
||||
<li><a href="#history">History</a></li>
|
||||
<li><a href="#references">References</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div id="introduction">
|
||||
<h2>Introduction</h2>
|
||||
<p>
|
||||
Originally the Boost function templates <code>allocate_shared</code> and
|
||||
<code>make_shared</code> were for efficient allocation of shared scalar
|
||||
objects only. There was a need to have efficient allocation of shared
|
||||
arrays. One criticism of class template <code>shared_array</code>
|
||||
was always the lack of a utility like <code>make_shared</code> that
|
||||
uses only a single allocation.
|
||||
</p>
|
||||
<p>
|
||||
The header files <boost/smart_ptr/allocate_shared_array.hpp> and
|
||||
<boost/smart_ptr/make_shared_array.hpp> provide function
|
||||
templates, overloads of <code>allocate_shared</code> and
|
||||
<code>make_shared</code> for array types, to address this need.
|
||||
<code>allocate_shared</code> uses a user-supplied allocator for
|
||||
allocation, while <code>make_shared</code> uses
|
||||
<code>allocate_shared</code> with the Default Allocator.
|
||||
</p>
|
||||
</div>
|
||||
<div id="synopsis">
|
||||
<h2>Synopsis</h2>
|
||||
<div>
|
||||
<h3>Header <boost/smart_ptr/allocate_shared_array.hpp></h3>
|
||||
<code>namespace boost {</code>
|
||||
<blockquote>
|
||||
<code>template<class T, class A><br>shared_ptr<T>
|
||||
<a href="#functions">allocate_shared</a>(const A& a,
|
||||
std::size_t n);</code>
|
||||
</blockquote>
|
||||
<blockquote>
|
||||
<code>template<class T, class A><br>shared_ptr<T>
|
||||
<a href="#functions">allocate_shared</a>(const A& a);</code>
|
||||
</blockquote>
|
||||
<blockquote>
|
||||
<code>template<class T, class A><br>shared_ptr<T>
|
||||
<a href="#functions">allocate_shared</a>(const A& a, std::size_t n,
|
||||
const <em>E</em>& v);</code>
|
||||
</blockquote>
|
||||
<blockquote>
|
||||
<code>template<class T, class A><br>shared_ptr<T>
|
||||
<a href="#functions">allocate_shared</a>(const A& a,
|
||||
const <em>E</em>& v);</code>
|
||||
</blockquote>
|
||||
<blockquote>
|
||||
<code>template<class T, class A><br>shared_ptr<T>
|
||||
<a href="#functions">allocate_shared_noinit</a>(const A& a,
|
||||
std::size_t n);</code>
|
||||
</blockquote>
|
||||
<blockquote>
|
||||
<code>template<class T, class A><br>shared_ptr<T>
|
||||
<a href="#functions">allocate_shared_noinit</a>(const A& a);</code>
|
||||
</blockquote>
|
||||
<code>}</code>
|
||||
</div>
|
||||
<div>
|
||||
<h3>Header <boost/smart_ptr/make_shared_array.hpp></h3>
|
||||
<code>namespace boost {</code>
|
||||
<blockquote>
|
||||
<code>template<class T, class A><br>shared_ptr<T>
|
||||
<a href="#functions">make_shared</a>(std::size_t n);</code>
|
||||
</blockquote>
|
||||
<blockquote>
|
||||
<code>template<class T, class A><br>shared_ptr<T>
|
||||
<a href="#functions">make_shared</a>();</code>
|
||||
</blockquote>
|
||||
<blockquote>
|
||||
<code>template<class T, class A><br>shared_ptr<T>
|
||||
<a href="#functions">make_shared</a>(std::size_t n,
|
||||
const <em>E</em>& v);</code>
|
||||
</blockquote>
|
||||
<blockquote>
|
||||
<code>template<class T, class A><br>shared_ptr<T>
|
||||
<a href="#functions">make_shared</a>(const <em>E</em>& v);</code>
|
||||
</blockquote>
|
||||
<blockquote>
|
||||
<code>template<class T, class A><br>shared_ptr<T>
|
||||
<a href="#functions">make_shared_noinit</a>(std::size_t n);</code>
|
||||
</blockquote>
|
||||
<blockquote>
|
||||
<code>template<class T, class A><br>shared_ptr<T>
|
||||
<a href="#functions">make_shared_noinit</a>();</code>
|
||||
</blockquote>
|
||||
<code>}</code>
|
||||
</div>
|
||||
</div>
|
||||
<div id="requirements">
|
||||
<h2>Common Requirements</h2>
|
||||
<h3><code>template<class T, class A><br>shared_ptr<T>
|
||||
<a href="#functions">allocate_shared</a>(const A& a,
|
||||
<em>args</em>);</code></h3>
|
||||
<dl>
|
||||
<dt><strong>Requires:</strong></dt>
|
||||
<dd><code>T</code> is of the form <code>E[N]</code> or
|
||||
<code>E[]</code>. <code>A</code> shall be an <em>Allocator</em>, as
|
||||
described in section 17.6.3.5 [Allocator requirements] of the C++
|
||||
Standard. The copy constructor and destructor of <code>A</code> shall
|
||||
not throw exceptions.</dd>
|
||||
<dt><strong>Effects:</strong></dt>
|
||||
<dd>Allocates storage for an object of type <code>E</code> (or
|
||||
<code>E[size]</code> when <code>T</code> is <code>E[]</code>, where
|
||||
<code>size</code> is determined from <code>args</code> as specified by
|
||||
the concrete overload). A copy of the allocator is used to allocate
|
||||
storage. The storage is initialized as specified by the concrete
|
||||
overload. If an exception is thrown, the functions have no effect.</dd>
|
||||
<dt><strong>Returns:</strong></dt>
|
||||
<dd>A <code>shared_ptr</code> instance that stores and owns the address
|
||||
of the newly allocated and constructed object.</dd>
|
||||
<dt><strong>Postconditions:</strong></dt>
|
||||
<dd><code>r.get() != 0</code> and <code>r.use_count() == 1</code>,
|
||||
where <code>r</code> is the return value.</dd>
|
||||
<dt><strong>Throws:</strong></dt>
|
||||
<dd>An exception thrown from <code>A::allocate()</code>, or from the
|
||||
initialization of the object.</dd>
|
||||
<dt><strong>Remarks:</strong></dt>
|
||||
<dd>
|
||||
<ul>
|
||||
<li>This implementation performs no more than one memory allocation.
|
||||
This provides efficiency to equivalent to an intrusive smart
|
||||
pointer.</li>
|
||||
<li>When an object of an array type <code>T</code> is specified to be
|
||||
initialized to a value of the same type <code>v</code>, this shall be
|
||||
interpreted to mean that each array element of the object is initialized
|
||||
to the corresponding element from <code>v</code>.</li>
|
||||
<li>When an object of an array type <code>T</code> is specified to be
|
||||
value-initialized, this shall be interpreted to mean that each array
|
||||
element of the object is value-initialized.</li>
|
||||
<li>Array elements are initialized in ascending order of their
|
||||
addresses.</li>
|
||||
<li>When a subobject of a scalar type <code>S</code> is specified to
|
||||
be initialized to a value <code>v</code>, <code>allocate_shared</code>
|
||||
shall perform this initialization via the expression
|
||||
<code>std::allocator_traits<A>::construct(b, p, v)</code>, where
|
||||
<code>p</code> points to storage suitable to hold an object of type
|
||||
<code>S</code> and <code>b</code> of is a copy of the allocator
|
||||
<code>a</code> passed to <code>allocate_shared</code> such that its
|
||||
<code>value_type</code> is <code>S</code>.</li>
|
||||
<li>When a subobject of scalar type <code>S</code> is specified to be
|
||||
value-initialized, <code>allocate_shared</code> shall perform this
|
||||
initialization via the expression
|
||||
<code>std::allocator_traits<A>::construct(b, p)</code>, where
|
||||
<code>p</code> points to storage suitable to hold an object
|
||||
of type <code>S</code> and <code>b</code> is a copy of the allocator
|
||||
<code>a</code> passed to <code>allocate_shared</code> such that its
|
||||
<code>value_type</code> is <code>S</code>.</li>
|
||||
<li>When a subobject of scalar type <code>S</code> is specified to be
|
||||
default-initialized, <code>allocate_shared_noinit</code> shall perform
|
||||
this initialization via the expression <code>::new(p) S</code>, where
|
||||
<code>p</code> has type <code>void*</code> and points to storage
|
||||
suitable to hold an object of type <code>S</code>.</li>
|
||||
<li>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.</li>
|
||||
</ul>
|
||||
</dd>
|
||||
<dt><strong>Notes:</strong></dt>
|
||||
<dd>These functions will typically allocate more memory than the size of
|
||||
<code>sizeof(E)</code> to allow for internal bookkeeping structures such
|
||||
as the reference counts.</dd>
|
||||
</dl>
|
||||
</div>
|
||||
<div id="functions">
|
||||
<h2>Free Functions</h2>
|
||||
<div>
|
||||
<h3><code>template<class T, class A><br>shared_ptr<T>
|
||||
allocate_shared(const A& a, std::size_t n);</code></h3>
|
||||
<dl>
|
||||
<dt><strong>Returns:</strong></dt>
|
||||
<dd>A <code>shared_ptr</code> to a value-initialized object of type
|
||||
<code>E[size]</code>.</dd>
|
||||
<dt><strong>Remarks:</strong></dt>
|
||||
<dd>This overload shall only participate in overload resolution when
|
||||
<code>T</code> is of the form <code>E[]</code>.</dd>
|
||||
</dl>
|
||||
</div>
|
||||
<div>
|
||||
<h3><code>template<class T, class A><br>shared_ptr<T>
|
||||
allocate_shared(const A& a);</code></h3>
|
||||
<dl>
|
||||
<dt><strong>Returns:</strong></dt>
|
||||
<dd>A <code>shared_ptr</code> to a value-initialized object of type
|
||||
<code>E[N]</code>.</dd>
|
||||
<dt><strong>Remarks:</strong></dt>
|
||||
<dd>This overload shall only participate in overload resolution when
|
||||
<code>T</code> is of the form <code>E[N]</code>.</dd>
|
||||
</dl>
|
||||
</div>
|
||||
<div>
|
||||
<h3><code>template<class T, class A><br>shared_ptr<T>
|
||||
allocate_shared(const A& a, std::size_t n,
|
||||
const <em>E</em>& v);</code></h3>
|
||||
<dl>
|
||||
<dt><strong>Returns:</strong></dt>
|
||||
<dd>A <code>shared_ptr</code> to an object of type
|
||||
<code>E[size]</code>, where each array element of type <code>E</code> is
|
||||
initialized to <code>v</code>.</dd>
|
||||
<dt><strong>Remarks:</strong></dt>
|
||||
<dd>This overload shall only participate in overload resolution when
|
||||
<code>T</code> is of the form <code>E[]</code>.</dd>
|
||||
</dl>
|
||||
</div>
|
||||
<div>
|
||||
<h3><code>template<class T, class A><br>shared_ptr<T>
|
||||
allocate_shared(const A& a, const <em>E</em>& v);</code></h3>
|
||||
<dl>
|
||||
<dt><strong>Returns:</strong></dt>
|
||||
<dd>A <code>shared_ptr</code> to an object of type <code>E[N]</code>,
|
||||
where each array element of type <code>E</code> is initialized to
|
||||
<code>v</code>.</dd>
|
||||
<dt><strong>Remarks:</strong></dt>
|
||||
<dd>This overload shall only participate in overload resolution when
|
||||
<code>T</code> is of the form <code>E[N]</code>.</dd>
|
||||
</dl>
|
||||
</div>
|
||||
<div>
|
||||
<h3><code>template<class T, class A><br>shared_ptr<T>
|
||||
allocate_shared_noinit(const A& a, std::size_t n);</code></h3>
|
||||
<dl>
|
||||
<dt><strong>Returns:</strong></dt>
|
||||
<dd>A <code>shared_ptr</code> to a default-initialized object of type
|
||||
<code>E[size]</code>.</dd>
|
||||
<dt><strong>Remarks:</strong></dt>
|
||||
<dd>This overload shall only participate in overload resolution when
|
||||
<code>T</code> is of the form <code>E[]</code>.</dd>
|
||||
</dl>
|
||||
</div>
|
||||
<div>
|
||||
<h3><code>template<class T, class A><br>shared_ptr<T>
|
||||
allocate_shared_noinit(const A& a);</code></h3>
|
||||
<dl>
|
||||
<dt><strong>Returns:</strong></dt>
|
||||
<dd>A <code>shared_ptr</code> to a default-initialized object of type
|
||||
<code>E[N]</code>.</dd>
|
||||
<dt><strong>Remarks:</strong></dt>
|
||||
<dd>This overload shall only participate in overload resolution when
|
||||
<code>T</code> is of the form <code>E[N]</code>.</dd>
|
||||
</dl>
|
||||
</div>
|
||||
<div>
|
||||
<h3><code>template<class T><br>shared_ptr<T>
|
||||
make_shared(std::size_t n);</code></h3>
|
||||
<dl>
|
||||
<dt><strong>Returns:</strong></dt>
|
||||
<dd><code>allocate_shared<T>(std::allocator<<em>S<!--
|
||||
--></em>>(), n);</code></dd>
|
||||
<dt><strong>Remarks:</strong></dt>
|
||||
<dd>This overload shall only participate in overload resolution when
|
||||
<code>T</code> is of the form <code>E[]</code>.</dd>
|
||||
</dl>
|
||||
</div>
|
||||
<div>
|
||||
<h3><code>template<class T><br>shared_ptr<T>
|
||||
make_shared();</code></h3>
|
||||
<dl>
|
||||
<dt><strong>Returns:</strong></dt>
|
||||
<dd><code>allocate_shared<T>(std::allocator<<em>S<!--
|
||||
--></em>>());</code></dd>
|
||||
<dt><strong>Remarks:</strong></dt>
|
||||
<dd>This overload shall only participate in overload resolution when
|
||||
<code>T</code> is of the form <code>E[N]</code>.</dd>
|
||||
</dl>
|
||||
</div>
|
||||
<div>
|
||||
<h3><code>template<class T><br>shared_ptr<T>
|
||||
make_shared(std::size_t n, const <em>E</em>& v);</code></h3>
|
||||
<dl>
|
||||
<dt><strong>Returns:</strong></dt>
|
||||
<dd><code>allocate_shared<T>(std::allocator<<em>S<!--
|
||||
--></em>>(), n, v);</code></dd>
|
||||
<dt><strong>Remarks:</strong></dt>
|
||||
<dd>This overload shall only participate in overload resolution when
|
||||
<code>T</code> is of the form <code>E[]</code>.</dd>
|
||||
</dl>
|
||||
</div>
|
||||
<div>
|
||||
<h3><code>template<class T><br>shared_ptr<T>
|
||||
make_shared(const <em>E</em>& v);</code></h3>
|
||||
<dl>
|
||||
<dt><strong>Returns:</strong></dt>
|
||||
<dd><code>allocate_shared<T>(std::allocator<<em>S<!--
|
||||
--></em>>(), v);</code></dd>
|
||||
<dt><strong>Remarks:</strong></dt>
|
||||
<dd>This overload shall only participate in overload resolution when
|
||||
<code>T</code> is of the form <code>E[N].</code></dd>
|
||||
</dl>
|
||||
</div>
|
||||
<div>
|
||||
<h3><code>template<class T><br>shared_ptr<T>
|
||||
make_shared_noinit(std::size_t n);</code></h3>
|
||||
<dl>
|
||||
<dt><strong>Returns:</strong></dt>
|
||||
<dd><code>allocate_shared_noinit<T>(std::allocator<<em>S<!--
|
||||
--></em>>(), n);</code></dd>
|
||||
<dt><strong>Remarks:</strong></dt>
|
||||
<dd>This overload shall only participate in overload resolution when
|
||||
<code>T</code> is of the form <code>E[]</code>.</dd>
|
||||
</dl>
|
||||
</div>
|
||||
<div>
|
||||
<h3><code>template<class T><br>shared_ptr<T>
|
||||
make_shared_noinit();</code></h3>
|
||||
<dl>
|
||||
<dt><strong>Returns:</strong></dt>
|
||||
<dd><code>allocate_shared_noinit<T>(std::allocator<<em>S<!--
|
||||
--></em>>());</code></dd>
|
||||
<dt><strong>Remarks:</strong></dt>
|
||||
<dd>This overload shall only participate in overload resolution when
|
||||
<code>T</code> is of the form <code>E[N]</code>.</dd>
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
<div id="history">
|
||||
<h2>History</h2>
|
||||
<dl>
|
||||
<dt><strong>Boost 1.64</strong></dt>
|
||||
<dd>Glen Fernandes rewrote allocate_shared and make_shared for a more
|
||||
optimal and more maintainable implementation.</dd>
|
||||
<dt><strong>Boost 1.56</strong></dt>
|
||||
<dd>Glen Fernandes updated overloads of make_shared and allocate_shared
|
||||
to conform to the specification in C++ standard paper
|
||||
<a href="#N3870">N3870</a>, including resolving C++ standard library
|
||||
defect report <a href="#dr2070">DR 2070</a>.</dd>
|
||||
<dt><strong>Boost 1.53</strong></dt>
|
||||
<dd>Glen Fernandes contributed implementations of make_shared and
|
||||
allocate_shared for arrays.</dd>
|
||||
</dl>
|
||||
</div>
|
||||
<div id="references">
|
||||
<h2>References</h2>
|
||||
<ol>
|
||||
<li id="N3870"><strong>N3870</strong>, <a href=
|
||||
"http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n3870.html">
|
||||
Extending make_shared to Support Arrays, Revision 1</a>, Peter Dimov
|
||||
& Glen Fernandes, January, 2014.</li>
|
||||
<li id="dr2070"><strong>DR 2070</strong>,
|
||||
<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-active.html">
|
||||
allocate_shared should use allocator_traits<A>::construct</a>,
|
||||
Jonathan Wakely, July, 2011.</li>
|
||||
</ol>
|
||||
</div>
|
||||
<hr>
|
||||
Copyright 2012-2017 Glen Fernandes. Distributed under the
|
||||
<a href="http://www.boost.org/LICENSE_1_0.txt">Boost Software License,
|
||||
Version 1.0</a>.
|
||||
</body>
|
||||
</html>
|
||||
|
324
make_unique.html
324
make_unique.html
@@ -1,150 +1,176 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
<html>
|
||||
<head>
|
||||
<title>make_unique</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
</head>
|
||||
<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>
|
||||
<a href="#common">Common Requirements</a><br>
|
||||
<a href="#functions">Free Functions</a><br>
|
||||
<a href="#history">History</a></p>
|
||||
<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>
|
||||
<pre>namespace boost {
|
||||
template<class U> // U is not array
|
||||
unique_ptr<U> <a href="#functions">make_unique</a>();
|
||||
|
||||
template<class U, class... Args> // U is not array
|
||||
unique_ptr<U> <a href="#functions">make_unique</a>(Args&&... args);
|
||||
|
||||
template<class U> // U is not array
|
||||
unique_ptr<U> <a href="#functions">make_unique</a>(U&& value);
|
||||
|
||||
template<class U> // U is T[]
|
||||
unique_ptr<U> <a href="#functions">make_unique</a>(size_t size);
|
||||
|
||||
template<class U> // U is not array
|
||||
unique_ptr<U> <a href="#functions">make_unique_noinit</a>();
|
||||
|
||||
template<class U> // U is T[]
|
||||
unique_ptr<U> <a href="#functions">make_unique_noinit</a>(size_t size);
|
||||
}</pre>
|
||||
<h2><a name="common">Common Requirements</a></h2>
|
||||
<pre>template<class U>
|
||||
unique_ptr<U> make_unique(<em>args</em>);</pre>
|
||||
<pre>template<class U>
|
||||
unique_ptr<U> make_unique_noinit(<em>args</em>);</pre>
|
||||
<blockquote>
|
||||
<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>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 initialization of the object.</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>
|
||||
<h2><a name="functions">Free Functions</a></h2>
|
||||
<pre>template<class U, class... 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>
|
||||
<p><b>Examples:</b></p>
|
||||
<blockquote>
|
||||
<pre>unique_ptr<float> p1 = boost::make_unique<float>();</pre>
|
||||
<pre>unique_ptr<point> p2 = boost::make_unique<point>(x, y);</pre>
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
<pre>template<class U>
|
||||
unique_ptr<U> make_unique(U&& value);</pre>
|
||||
<blockquote>
|
||||
<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>
|
||||
<p><b>Examples:</b></p>
|
||||
<blockquote>
|
||||
<pre>unique_ptr<string> p1 = boost::make_unique<string>({'a', 'b'});</pre>
|
||||
<pre>unique_ptr<point> p2 = boost::make_unique<point>({-10, 25});</pre>
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
<pre>template<class U>
|
||||
unique_ptr<U> make_unique(size_t size);</pre>
|
||||
<blockquote>
|
||||
<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>
|
||||
<p><b>Examples:</b></p>
|
||||
<blockquote>
|
||||
<pre>unique_ptr<double[]> p1 = boost::make_unique<double[]>(4);</pre>
|
||||
<pre>unique_ptr<int[][2]> p2 = boost::make_unique<int[][2]>(2);</pre>
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
<pre>template<class U>
|
||||
unique_ptr<U> make_unique_noinit();</pre>
|
||||
<blockquote>
|
||||
<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>
|
||||
<p><b>Examples:</b></p>
|
||||
<blockquote>
|
||||
<pre>unique_ptr<float> p1 = boost::make_unique_noinit<float>();</pre>
|
||||
<pre>unique_ptr<point> p2 = boost::make_unique_noinit<point>();</pre>
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
<pre>template<class U>
|
||||
unique_ptr<U> make_unique_noinit(size_t size);</pre>
|
||||
<blockquote>
|
||||
<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>
|
||||
<p><b>Examples:</b></p>
|
||||
<blockquote>
|
||||
<pre>unique_ptr<double[]> p1 = boost::make_unique_noinit<double[]>(4);</pre>
|
||||
<pre>unique_ptr<int[][2]> p2 = boost::make_unique_noinit<int[][2]>(2);</pre>
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
<h2><a name="history">History</a></h2>
|
||||
<p>January 2014. Glen Fernandes contributed implementations of
|
||||
make_unique for objects and arrays.</p>
|
||||
<hr>
|
||||
<p>$Date$</p>
|
||||
<p><small>Copyright 2012-2014 Glen Fernandes. Distributed under the
|
||||
Boost Software License, Version 1.0. See accompanying file
|
||||
<a href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or copy at
|
||||
<a href="http://www.boost.org/LICENSE_1_0.txt">
|
||||
http://www.boost.org/LICENSE_1_0.txt</a>.</small></p>
|
||||
</body>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>make_unique</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>make_unique</h1>
|
||||
<div id="navigation">
|
||||
<ul>
|
||||
<li><a href="#introduction">Introduction</a></li>
|
||||
<li><a href="#synopsis">Synopsis</a></li>
|
||||
<li><a href="#requirements">Common Requirements</a></li>
|
||||
<li><a href="#functions">Free Functions</a></li>
|
||||
<li><a href="#history">History</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div id="introduction">
|
||||
<h2>Introduction</h2>
|
||||
<p>
|
||||
The header file <boost/make_unique.hpp> provides overloads of
|
||||
function template <code>make_unique</code> for convenient creation of
|
||||
<code>std::unique_ptr</code> objects.
|
||||
</p>
|
||||
</div>
|
||||
<div id="synopsis">
|
||||
<h2>Synopsis</h2>
|
||||
<div>
|
||||
<h3>Header <boost/smart_ptr/make_unique.hpp></h3>
|
||||
<code>namespace boost {</code>
|
||||
<blockquote>
|
||||
<code>template<class T><br>std::unique_ptr<T>
|
||||
<a href="#functions">make_unique</a>();</code>
|
||||
</blockquote>
|
||||
<blockquote>
|
||||
<code>template<class T, class... Args><br>std::unique_ptr<T>
|
||||
<a href="#functions">make_unique</a>(Args&&... args);</code>
|
||||
</blockquote>
|
||||
<blockquote>
|
||||
<code>template<class T><br>std::unique_ptr<T>
|
||||
<a href="#functions">make_unique</a>(<em>T</em>&& value);</code>
|
||||
</blockquote>
|
||||
<blockquote>
|
||||
<code>template<class T><br>std::unique_ptr<T>
|
||||
<a href="#functions">make_unique</a>(std::size_t size);</code>
|
||||
</blockquote>
|
||||
<blockquote>
|
||||
<code>template<class T><br>std::unique_ptr<T>
|
||||
<a href="#functions">make_unique_noinit</a>();</code>
|
||||
</blockquote>
|
||||
<blockquote>
|
||||
<code>template<class T><br>std::unique_ptr<T>
|
||||
<a href="#functions">make_unique_noinit</a>(std::size_t size);</code>
|
||||
</blockquote>
|
||||
<code>}</code>
|
||||
</div>
|
||||
</div>
|
||||
<div id="requirements">
|
||||
<h2>Common Requirements</h2>
|
||||
<h3><code>template<class T, <em>Args</em>><br>
|
||||
std::unique_ptr<T>
|
||||
<a href="#functions">make_unique</a>(<em>args</em>);</code></h3>
|
||||
<dl>
|
||||
<dt><strong>Effects:</strong></dt>
|
||||
<dd>Allocates storage for an object of type <code>T</code> (or
|
||||
<code>E[size]</code> when <code>T</code> is <code>E[]</code>, where
|
||||
<code>size</code> is determined from <code>args</code> as specified by
|
||||
the concrete overload). The storage is initialized from
|
||||
<code>args</code> as specified by the concrete overload. If an exception
|
||||
is thrown, the functions have no effect.</dd>
|
||||
<dt><strong>Returns:</strong></dt>
|
||||
<dd>A <code>std::unique_ptr</code> instance that stores and owns the
|
||||
address of the newly allocated and constructed object.</dd>
|
||||
<dt><strong>Postconditions:</strong></dt>
|
||||
<dd><code>r.get() != 0</code>, where <code>r</code> is the return
|
||||
value.</dd>
|
||||
<dt><strong>Throws:</strong></dt>
|
||||
<dd><code>std::bad_alloc</code>, or an exception thrown from the
|
||||
initialization of the object.</dd>
|
||||
<dt><strong>Remarks:</strong></dt>
|
||||
<dd>
|
||||
<ul>
|
||||
<li>When an object of a scalar type T is specified to be initialized to
|
||||
a value <code>value</code>, or to <code>T(args...)</code>, where
|
||||
<code>args...</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(args...)</code>
|
||||
respectively.</li>
|
||||
<li>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>.</li>
|
||||
<li>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>.</li>
|
||||
</ul>
|
||||
</dd>
|
||||
</dl>
|
||||
</div>
|
||||
<div id="functions">
|
||||
<h2>Free functions</h2>
|
||||
<div>
|
||||
<h3><code>template<class T, class... Args><br>
|
||||
std::unique_ptr<T>
|
||||
make_unique(Args&&... args);</code></h3>
|
||||
<dl>
|
||||
<dt><strong>Returns:</strong></dt>
|
||||
<dd>A <code>std::unique_ptr</code> to an object of type <code>T</code>,
|
||||
initialized to <code>std::forward<Args>(args)...</code>.</dd>
|
||||
<dt><strong>Remarks:</strong></dt>
|
||||
<dd>This overload shall only participate in overload resolution when
|
||||
<code>T</code> is not an array type.</dd>
|
||||
</dl>
|
||||
</div>
|
||||
<div>
|
||||
<h3><code>template<class T><br>std::unique_ptr<T>
|
||||
make_unique(<em>T</em>&& value);</code></h3>
|
||||
<dl>
|
||||
<dt><strong>Returns:</strong></dt>
|
||||
<dd>A <code>std::unique_ptr</code> to an object of type <code>T</code>,
|
||||
initialized to <code>std::move(value)</code>.</dd>
|
||||
<dt><strong>Remarks:</strong></dt>
|
||||
<dd>This overload shall only participate in overload resolution when
|
||||
<code>T</code> is not an array type.</dd>
|
||||
</dl>
|
||||
</div>
|
||||
<div>
|
||||
<h3><code>template<class T><br>std::unique_ptr<T>
|
||||
make_unique(std::size_t size);</code></h3>
|
||||
<dl>
|
||||
<dt><strong>Returns:</strong></dt>
|
||||
<dd>A <code>std::unique_ptr</code> to a value-initialized object of type
|
||||
<code>E[size]</code>.</dd>
|
||||
<dt><strong>Remarks:</strong></dt>
|
||||
<dd>This overload shall only participate in overload resolution when
|
||||
<code>T</code> is of the form <code>E[]</code>.</dd>
|
||||
</dl>
|
||||
</div>
|
||||
<div>
|
||||
<h3><code>template<class T><br>std::unique_ptr<T>
|
||||
make_unique_noinit();</code></h3>
|
||||
<dl>
|
||||
<dt><strong>Returns:</strong></dt>
|
||||
<dd>A <code>std::unique_ptr</code> to a default-initialized object of
|
||||
type <code>T</code>.</dd>
|
||||
<dt><strong>Remarks:</strong></dt>
|
||||
<dd>This overload shall only participate in overload resolution when
|
||||
<code>T</code> is not an array type.</dd>
|
||||
</dl>
|
||||
</div>
|
||||
<div>
|
||||
<h3><code>template<class T><br>std::unique_ptr<T>
|
||||
make_unique_noinit(std::size_t size);</code></h3>
|
||||
<dl>
|
||||
<dt><strong>Returns:</strong></dt>
|
||||
<dd>A <code>std::unique_ptr</code> to a default-initialized object of
|
||||
type <code>E[size]</code>.</dd>
|
||||
<dt><strong>Remarks:</strong></dt>
|
||||
<dd>This overload shall only participate in overload resolution when
|
||||
<code>T</code> is of the form <code>E[]</code>.</dd>
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
<div id="history">
|
||||
<h2>History</h2>
|
||||
<dl>
|
||||
<dt><strong>Boost 1.56</strong></dt>
|
||||
<dd>Glen Fernandes contributed implementations of make_unique for
|
||||
scalars and arrays</dd>
|
||||
</dl>
|
||||
</div>
|
||||
<hr>
|
||||
Copyright 2012-2014 Glen Fernandes. Distributed under the
|
||||
<a href="http://www.boost.org/LICENSE_1_0.txt">Boost Software License,
|
||||
Version 1.0</a>.
|
||||
</body>
|
||||
</html>
|
||||
|
Reference in New Issue
Block a user