-
Notifications
You must be signed in to change notification settings - Fork 29
/
func.html
203 lines (158 loc) · 8.05 KB
/
func.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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<cxx-clause id="func">
<h1>Function objects</h1>
<cxx-section id="functional.syn">
<h1>Header <code><experimental/functional></code> synopsis</h1>
<pre><code>#include <functional>
namespace std {
namespace experimental::inline fundamentals_v3 {
<cxx-ref insynopsis="" to="func.wrap.func"></cxx-ref>
template<class> class function; <i>// not defined</i>
template<class R, class... ArgTypes> class function<R(ArgTypes...)>;
template<class R, class... ArgTypes>
void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&);
template<class R, class... ArgTypes>
bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
} // namespace experimental::inline fundamentals_v3
} // namespace std</code></pre>
</cxx-section>
<cxx-section id="func.wrap.func">
<h1>Class template <code>function</code></h1>
<cxx-section id="func.wrap.func.overview">
<h1>Overview</h1>
<p>
The specification of all declarations within subclause <cxx-ref to="func.wrap.func"></cxx-ref>
are the same as the corresponding declarations, as specified in <cxx-ref in="cxx" to="func.wrap.func"></cxx-ref>,
unless explicitly specified otherwise. <cxx-note><code>std::experimental::function</code> uses
<code>std::bad_function_call</code>, there is no additional type <code>std::experimental::bad_function_call</code></cxx-note>.
</p>
<pre><code>namespace std {
namespace experimental::inline fundamentals_v3 {
template<class> class function; <i>// undefined</i>
template<class R, class... ArgTypes>
class function<R(ArgTypes...)> {
public:
using result_type = R;
using allocator_type = std::pmr::polymorphic_allocator<>;
function() noexcept;
function(nullptr_t) noexcept;
function(const function&);
function(function&&);
template<class F> function(F);
function(allocator_arg_t, const allocator_type&) noexcept;
function(allocator_arg_t, const allocator_type&, nullptr_t) noexcept;
function(allocator_arg_t, const allocator_type&, const function&);
function(allocator_arg_t, const allocator_type&, function&&);
template<class F> function(allocator_arg_t, const allocator_type&, F);
function& operator=(const function&);
function& operator=(function&&);
function& operator=(nullptr_t) noexcept;
template<class F> function& operator=(F&&);
template<class F> function& operator=(reference_wrapper<F>);
~function();
void swap(function&);
explicit operator bool() const noexcept;
R operator()(ArgTypes...) const;
const type_info& target_type() const noexcept;
template<class T> T* target() noexcept;
template<class T> const T* target() const noexcept;
allocator_type get_allocator() const noexcept;
};
template <class R, class... ArgTypes>
function(R(*)(ArgTypes...)) -> function<R(ArgTypes...)>;
template<class F>
function(F) -> function<<em>see below</em>>;
} // namespace experimental::inline fundamentals_v3
} // namespace std</code></pre>
</cxx-section>
<cxx-section id="func.wrap.func.con">
<h1>Construct/copy/destroy</h1>
<p>
A function object stores an allocator object of type <code>std::pmr::polymorphic_allocator<></code>,
which it uses to allocate memory for its internal data structures.
In the <code>function</code> constructors, the allocator is initialized
(before the target object, if any) as follows:
</p>
<ul>
<li>
For the move constructor, the allocator is initialized
from <code>f.get_allocator()</code>, where <code>f</code> is the
parameter of the constructor.
</li>
<li>
For constructors having a first parameter of type <code>allocator_arg_t</code>,
the allocator is initialized from the second parameter.
</li>
<li>
For all other constructors, the allocator is value-initialized.
</li>
</ul>
<p>
In all cases, the allocator of a parameter having type <code>function&&</code> is unchanged.
If the constructor creates a target object, that target object is initialized
by uses-allocator construction with the allocator and other target object constructor arguments.
<cxx-note>
If a constructor parameter of type <code>experimental::function&&</code>
has an allocator equal to that of the object being constructed,
the implementation can often transfer ownership of the target rather than constructing a new one.
</cxx-note>
</p>
<p>
The deduction guide <code>template<class F> function(F) -> function<<em>see below</em>>;</code>
is specified in <cxx-ref in="cxx" to="func.wrap.func"></cxx-ref>.
</p>
<cxx-function>
<cxx-signature>function& operator=(const function& f);</cxx-signature>
<cxx-effects><code>function(allocator_arg, get_allocator(), f).swap(*this);</code></cxx-effects>
<cxx-returns><code>*this</code>.</cxx-returns>
</cxx-function>
<cxx-function>
<cxx-signature>function& operator=(function&& f);</cxx-signature>
<cxx-effects><code>function(allocator_arg, get_allocator(), std::move(f)).swap(*this);</code></cxx-effects>
<cxx-returns><code>*this</code>.</cxx-returns>
</cxx-function>
<cxx-function>
<cxx-signature>function& operator=(nullptr_t) noexcept;</cxx-signature>
<cxx-effects>If <code>*this != nullptr</code>, destroys the target of <code>this</code>.</cxx-effects>
<cxx-postconditions>
<code>!(*this)</code>.
<cxx-note>The stored allocator is unchanged.</cxx-note>
</cxx-postconditions>
<cxx-returns><code>*this</code>.</cxx-returns>
</cxx-function>
<cxx-function>
<cxx-signature>template<class F> function& operator=(F&& f);</cxx-signature>
<cxx-constraints>
<code>declval<decay_t<F>&>()</code> is <cxx-17concept>Lvalue-Callable</cxx-17concept> (<cxx-ref in="cxx" to="func.wrap.func"></cxx-ref>)
for argument types <code>ArgTypes...</code> and return type <code>R</code>.
</cxx-constraints>
<cxx-effects><code>function(allocator_arg, get_allocator(), std::forward<F>(f)).swap(*this);</code></cxx-effects>
<cxx-returns><code>*this</code>.</cxx-returns>
</cxx-function>
<cxx-function>
<cxx-signature>template<class F> function& operator=(reference_wrapper<F> f) noexcept;</cxx-signature>
<cxx-effects><code>function(allocator_arg, get_allocator(), f).swap(*this);</code></cxx-effects>
<cxx-returns><code>*this</code>.</cxx-returns>
</cxx-function>
</cxx-section>
<cxx-section id="func.wrap.func.mod">
<h1>Modifiers</h1>
<cxx-function>
<cxx-signature>void swap(function& other);</cxx-signature>
<cxx-preconditions><code>this->get_allocator() == other.get_allocator()</code>.</cxx-preconditions>
<cxx-effects>Interchanges the targets of <code>*this</code> and <code>other</code>.</cxx-effects>
<cxx-throws>Nothing.</cxx-throws>
<cxx-remarks>The allocators of <code>*this</code> and <code>other</code> are not interchanged.</cxx-remarks>
</cxx-function>
</cxx-section>
<cxx-section id="func.wrap.func.obs">
<h1>Observers</h1>
<cxx-function>
<cxx-signature>allocator_type get_allocator() const noexcept;</cxx-signature>
<cxx-returns>
A copy of the allocator initialized during construction
(<cxx-ref to="func.wrap.func.con"></cxx-ref>) of this object.
</cxx-returns>
</cxx-function>
</cxx-section>
</cxx-section>
</cxx-clause>