forked from boostorg/smart_ptr
Merged revision(s) 81368, 81399, 81407-81409, 81419, 81430-81431, 81437 from trunk:
Apply BOOST_NOEXCEPT patch. Refs #7523. ........ Replace std::forward with detail::sp_forward. ........ Cosmetic changes in make_shared_array.hpp and allocate_shared_array.hpp ........ Documentation of make_shared_array: Minor corrections ........ Make make_shared_array.hpp and allocate_shared_array.hpp consistent with namespace qualification in rest of smart_ptr. ........ Update smart_ptr.htm with link to make_shared_array.htm which lists the many overloads of make_shared and allocate_shared for arrays. ........ Update documentation for make_shared and allocate_shared array forms. ........ Minor corrections in make_shared_array.html documentation. ........ Borland fixes. ........ [SVN r81457]
This commit is contained in:
+83
-23
@@ -12,12 +12,14 @@
|
||||
<A href="#Synopsis">Synopsis</A><br>
|
||||
<A href="#functions">Free Functions</A><br>
|
||||
<A href="#example">Example</A><br>
|
||||
<A href="#history">History</A><br>
|
||||
<h2><a name="Introduction">Introduction</a></h2>
|
||||
<p>One criticism of Boost <a href="shared_array.htm">shared_array</a> is
|
||||
the lack of utility similar to <a href="make_shared.htm">make_shared</a>
|
||||
which ensures only a single allocation for an array. A second criticism
|
||||
is Boost <code>shared_array</code> does not support custom allocators
|
||||
and so also lacks an <code>allocate_shared</code> utility.</p>
|
||||
<p>Originally the Boost function templates <code>make_shared</code> and
|
||||
<code>allocate_shared</code> were for efficient allocation of single
|
||||
objects only. There was a need to have efficient, single, allocation of
|
||||
arrays. One criticism of <a href="shared_array.htm">shared_array</a> was
|
||||
always the lack of a <a href="make_shared.htm">make_shared</a> utility
|
||||
which ensures only a single allocation for an array.</p>
|
||||
<p>The header files <boost/smart_ptr/make_shared_array.hpp> and
|
||||
<boost/smart_ptr/allocate_shared_array.hpp> provide new function
|
||||
templates, <code>make_shared</code> and <code>allocate_shared</code>,
|
||||
@@ -32,17 +34,17 @@
|
||||
|
||||
template<typename T, typename A>
|
||||
shared_ptr<T[]> <a href="#functions">allocate_shared</a>(const A& allocator, size_t size);
|
||||
|
||||
|
||||
#if defined(BOOST_HAS_VARIADIC_TMPL) && defined(BOOST_HAS_RVALUE_REFS)
|
||||
template<typename T, typename... Args>
|
||||
shared_ptr<T[]> <a href="#functions">make_shared</a>(size_t size, Args&&... args);
|
||||
|
||||
|
||||
template<typename T, typename... Args>
|
||||
shared_ptr<T[N]> <a href="#functions">make_shared</a>(Args&&... args);
|
||||
|
||||
|
||||
template<typename T, typename A, typename... Args>
|
||||
shared_ptr<T> <a href="#functions">allocate_shared</a>(const A& allocator, size_t size, Args&&... args);
|
||||
|
||||
shared_ptr<T[]> <a href="#functions">allocate_shared</a>(const A& allocator, size_t size, Args&&... args);
|
||||
|
||||
template<typename T, typename A, typename... Args>
|
||||
shared_ptr<T[N]> <a href="#functions">allocate_shared</a>(const A& allocator, Args&&... args);
|
||||
#endif
|
||||
@@ -50,40 +52,40 @@
|
||||
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
|
||||
template<typename T, typename... Args>
|
||||
shared_ptr<T[]> <a href="#functions">make_shared</a>(initializer_list<T> list);
|
||||
|
||||
|
||||
template<typename T, typename... Args>
|
||||
shared_ptr<T[N]> <a href="#functions">make_shared</a>(initializer_list<T> list);
|
||||
|
||||
|
||||
template<typename T, typename... Args>
|
||||
shared_ptr<T[][N]> <a href="#functions">make_shared</a>(size_t size, initializer_list<T> list);
|
||||
|
||||
|
||||
template<typename T, typename... Args>
|
||||
shared_ptr<T[M][N]> <a href="#functions">make_shared</a>(initializer_list<T> list);
|
||||
|
||||
template<typename T, typename A, typename... Args>
|
||||
shared_ptr<T[]> <a href="#functions">allocate_shared</a>(const A& allocator, initializer_list<T> list);
|
||||
|
||||
|
||||
template<typename T, typename A, typename... Args>
|
||||
shared_ptr<T[N]> <a href="#functions">allocate_shared</a>(const A& allocator, initializer_list<T> list);
|
||||
|
||||
|
||||
template<typename T, typename A, typename... Args>
|
||||
shared_ptr<T[][N]> <a href="#functions">allocate_shared</a>(const A& allocator, size_t size, initializer_list<T> list);
|
||||
|
||||
|
||||
template<typename T, typename A, typename... Args>
|
||||
shared_ptr<T[M][N]> <a href="#functions">allocate_shared</a>(const A& allocator, initializer_list<T> list);
|
||||
#endif
|
||||
|
||||
template<typename T>
|
||||
shared_ptr<T> <a href="#functions">make_shared_noinit</a>(size_t size);
|
||||
|
||||
shared_ptr<T[]> <a href="#functions">make_shared_noinit</a>(size_t size);
|
||||
|
||||
template<typename T>
|
||||
shared_ptr<T[N]> <a href="#functions">make_shared_noinit</a>();
|
||||
}</pre>
|
||||
<h2><a name="functions">Free Functions</a></h2>
|
||||
<pre>template<typename T, typename... Args>
|
||||
shared_ptr<T> make_shared(size_t size, Args&&... args);
|
||||
shared_ptr<T[]> make_shared(size_t size, Args&&... args);
|
||||
template<typename T, typename A, typename... Args>
|
||||
shared_ptr<T> allocate_shared(const A& allocator, size_t size, Args&&... args);</pre>
|
||||
shared_ptr<T[]> allocate_shared(const A& allocator, size_t size, Args&&... args);</pre>
|
||||
<blockquote>
|
||||
<p><b>Requires:</b> The expression
|
||||
<code>new(pointer) T(forward<Args>(args)...)</code>, where
|
||||
@@ -122,16 +124,74 @@ template<typename T, typename A, typename... Args>
|
||||
take any constructor arguments. These overloads invoke the default
|
||||
constructor of <code>T</code> for each array element.</p>
|
||||
</blockquote>
|
||||
<pre>template<typename T, typename... Args>
|
||||
shared_ptr<T[N]> make_shared(Args&&... args);
|
||||
template<typename T, typename A, typename... Args>
|
||||
shared_ptr<T[N]> allocate_shared(const A& allocator, Args&&... args);</pre>
|
||||
<blockquote>
|
||||
<p><b>Description:</b> These overloads of the utilities above are for a
|
||||
fixed size array.</p>
|
||||
</blockquote>
|
||||
<pre>template<typename T, typename... Args>
|
||||
shared_ptr<T[]> make_shared(initializer_list<T> list);
|
||||
template<typename T, typename A, typename... Args>
|
||||
shared_ptr<T[]> allocate_shared(const A& allocator, initializer_list<T> list);</pre>
|
||||
<blockquote>
|
||||
<p><b>Description:</b> These overloads initialize the array elements
|
||||
from the initializer list.</p>
|
||||
</blockquote>
|
||||
<pre>template<typename T, typename... Args>
|
||||
shared_ptr<T[N]> make_shared(initializer_list<T> list);
|
||||
template<typename T, typename A, typename... Args>
|
||||
shared_ptr<T[N]> allocate_shared(const A& allocator, initializer_list<T> list);</pre>
|
||||
<blockquote>
|
||||
<p><b>Description:</b> These overloads of the utilities above are for a
|
||||
fixed size array.</p>
|
||||
</blockquote>
|
||||
<pre>template<typename T, typename... Args>
|
||||
shared_ptr<T[][N]> make_shared(size_t size, initializer_list<T> list);
|
||||
template<typename T, typename A, typename... Args>
|
||||
shared_ptr<T[][N]> allocate_shared(const A& allocator, size_t size, initializer_list<T> list);</pre>
|
||||
<blockquote>
|
||||
<p><b>Description:</b> These overloads initialize inner array elements
|
||||
from the initializer list.</p>
|
||||
</blockquote>
|
||||
<pre>template<typename T, typename... Args>
|
||||
shared_ptr<T[M][N]> make_shared(initializer_list<T> list);
|
||||
template<typename T, typename A, typename... Args>
|
||||
shared_ptr<T[M][N]> allocate_shared(const A& allocator, initializer_list<T> list);</pre>
|
||||
<blockquote>
|
||||
<p><b>Description:</b> These overloads of the utilities above are for a
|
||||
fixed size array.</p>
|
||||
</blockquote>
|
||||
<pre>template<typename T>
|
||||
shared_ptr<T[]> make_shared_noinit(size_t size);</pre>
|
||||
<blockquote>
|
||||
<p><b>Description:</b> This overload does not perform value
|
||||
initialization of elements.</p>
|
||||
</blockquote>
|
||||
<pre>template<typename T>
|
||||
shared_ptr<T[N]> make_shared_noinit();</pre>
|
||||
<blockquote>
|
||||
<p><b>Description:</b> This overload of the utility above is used for a
|
||||
fixed size array.</p>
|
||||
</blockquote>
|
||||
<h2><a name="example">Example</a></h2>
|
||||
<pre>boost::shared_ptr<int[]> a1 = boost::make_shared<int[]>(size);
|
||||
boost::shared_ptr<point[5]> a2 = boost::make_shared<point[5]>(x, y);
|
||||
boost::shared_ptr<int[5]> a3 = boost::make_shared<int[5]>();
|
||||
<p>An example of each overload of make_shared for arrays:</p>
|
||||
<blockquote>
|
||||
<pre>boost::shared_ptr<point[]> a1 = boost::make_shared<point[]>(size);
|
||||
boost::shared_ptr<point[]> a2 = boost::make_shared<point[]>(size, x, y);
|
||||
boost::shared_ptr<point[5]> a3 = boost::make_shared<point[5]>(x, y);
|
||||
boost::shared_ptr<int[]> a4 = boost::make_shared<int[]>({1, 2, 3});
|
||||
boost::shared_ptr<int[3]> a5 = boost::make_shared<int[3]>({1, 2, 3});
|
||||
boost::shared_ptr<int[][3]> a6 = boost::make_shared<int[][3]>(size, {1, 2, 3});
|
||||
boost::shared_ptr<int[5][3]> a7 = boost::make_shared<int[5][3]>({1, 2, 3});
|
||||
boost::shared_ptr<int[]> a8 = boost::make_shared_noinit<int[]>(size);
|
||||
boost::shared_ptr<int[5]> a9 = boost::make_shared_noinit<int[5]>();</pre>
|
||||
</blockquote>
|
||||
<h2><a name="history">History</a></h2>
|
||||
<p>November 2012. Glen Fernandes contributed implementations of
|
||||
make_shared and allocate_shared for arrays.</p>
|
||||
<hr>
|
||||
<p>$Date: 2012-10-30 10:12:25 -0800 (Tue, 30 Oct 2012) $</p>
|
||||
<p><small>Copyright 2012 Glen Fernandes. Distributed under the Boost
|
||||
|
||||
Reference in New Issue
Block a user