forked from boostorg/smart_ptr
Add fourth form of make_unique for objects
To support initialization syntax that Args&&... cannot forward perfectly.
This commit is contained in:
1 parent
f91e7e9ce7
commit
72e5fb6fd7
7 files changed
+95
-37
No files matched your search
+26
-10
@@ -26,6 +26,9 @@
|
||||
unique_ptr<U> <a href="#functions">make_unique</a>(Args&&... args);
|
||||
#endif
|
||||
|
||||
template<typename U> // U is not array
|
||||
unique_ptr<U> <a href="#functions">make_unique</a>(U&& value);
|
||||
|
||||
template<typename U> // U is not array
|
||||
unique_ptr<U> <a href="#functions">make_unique_noinit</a>();
|
||||
|
||||
@@ -59,6 +62,14 @@ unique_ptr<U> make_unique(Args&&... args);</pre>
|
||||
expression <code>new U(forward<Args>(args)...)</code>.</p>
|
||||
</blockquote>
|
||||
<pre>template<typename U> // U is not array
|
||||
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>
|
||||
</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
|
||||
@@ -87,28 +98,33 @@ unique_ptr<U> make_unique_noinit(size_t size);</pre>
|
||||
<h2><a name="example">Examples</a></h2>
|
||||
<p>For objects with value-initialization.</p>
|
||||
<blockquote>
|
||||
<pre>std::unique_ptr<float> p1 = boost::make_unique<float>();
|
||||
std::unique_ptr<point> p2 = boost::make_unique<point>();</pre>
|
||||
<pre>unique_ptr<float> p1 = boost::make_unique<float>();
|
||||
unique_ptr<point> p2 = boost::make_unique<point>();</pre>
|
||||
</blockquote>
|
||||
<p>For objects with construction arguments.</p>
|
||||
<blockquote>
|
||||
<pre>std::unique_ptr<float> p3 = boost::make_unique<float>(1.5);
|
||||
std::unique_ptr<point> p4 = boost::make_unique<point>(x, y);</pre>
|
||||
<pre>unique_ptr<float> p3 = boost::make_unique<float>(1.0f);
|
||||
unique_ptr<point> p4 = boost::make_unique<point>(x, y);</pre>
|
||||
</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>
|
||||
</blockquote>
|
||||
<p>For objects with default-initialization.</p>
|
||||
<blockquote>
|
||||
<pre>std::unique_ptr<float> p4 = boost::make_unique_noinit<float>();
|
||||
std::unique_ptr<point> p5 = boost::make_unique_noinit<point>();</pre>
|
||||
<pre>unique_ptr<float> p6 = boost::make_unique_noinit<float>();
|
||||
unique_ptr<point> p7 = boost::make_unique_noinit<point>();</pre>
|
||||
</blockquote>
|
||||
<p>For arrays with value-initialization.</p>
|
||||
<blockquote>
|
||||
<pre>std::unique_ptr<double[]> a1 = boost::make_unique<double[]>();
|
||||
std::unique_ptr<int[][4]> a2 = boost::make_unique<int[][4]>();</pre>
|
||||
<pre>unique_ptr<double[]> a1 = boost::make_unique<double[]>();
|
||||
unique_ptr<int[][4]> a2 = boost::make_unique<int[][4]>();</pre>
|
||||
</blockquote>
|
||||
<p>For arrays with default-initialization.</p>
|
||||
<blockquote>
|
||||
<pre>std::unique_ptr<double[]> a3 = boost::make_unique_noinit<double[]>();
|
||||
std::unique_ptr<int[][4]> a4 = boost::make_unique_noinit<int[][4]>();</pre>
|
||||
<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
|
||||
|
||||
Reference in new issue
Block a user