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