forked from boostorg/smart_ptr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_unique.html
184 lines (184 loc) · 6.41 KB
/
make_unique.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<!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> make_unique(<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>
<dt><strong>Example:</strong></dt>
<dd><code>boost::make_unique<double>(1.0);</code></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>
<dt><strong>Example:</strong></dt>
<dd><code>boost::make_unique<point>({1.0, -1.0});</code></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>
<dt><strong>Example:</strong></dt>
<dd><code>boost::make_unique<int[]>(8);</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>
<dt><strong>Example:</strong></dt>
<dd><code>boost::make_unique_noinit<std::tm>();</code></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>
<dt><strong>Example:</strong></dt>
<dd><code>boost::make_unique_noinit<char[]>(64);</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>