From Jason Turner

[function.objects]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpnetxtfsh/{from.md → to.md} +593 -401
tmp/tmpnetxtfsh/{from.md → to.md} RENAMED
@@ -1,36 +1,35 @@
1
  ## Function objects <a id="function.objects">[[function.objects]]</a>
2
 
3
- A *function object type* is an object type ([[basic.types]]) that can
4
- be the type of the *postfix-expression* in a function call (
5
- [[expr.call]],  [[over.match.call]]).[^2] A *function object* is an
6
- object of a function object type. In the places where one would expect
7
- to pass a pointer to a function to an algorithmic template (Clause 
8
- [[algorithms]]), the interface is specified to accept a function object.
9
- This not only makes algorithmic templates work with pointers to
10
- functions, but also enables them to work with arbitrary function
11
- objects.
12
 
13
  ### Header `<functional>` synopsis <a id="functional.syn">[[functional.syn]]</a>
14
 
15
  ``` cpp
16
  namespace std {
17
  // [func.invoke], invoke
18
  template<class F, class... Args>
19
- invoke_result_t<F, Args...> invoke(F&& f, Args&&... args)
20
  noexcept(is_nothrow_invocable_v<F, Args...>);
21
 
22
  // [refwrap], reference_wrapper
23
  template<class T> class reference_wrapper;
24
 
25
- template <class T> reference_wrapper<T> ref(T&) noexcept;
26
- template <class T> reference_wrapper<const T> cref(const T&) noexcept;
27
  template<class T> void ref(const T&&) = delete;
28
  template<class T> void cref(const T&&) = delete;
29
 
30
- template <class T> reference_wrapper<T> ref(reference_wrapper<T>) noexcept;
31
- template <class T> reference_wrapper<const T> cref(reference_wrapper<T>) noexcept;
32
 
33
  // [arithmetic.operations], arithmetic operations
34
  template<class T = void> struct plus;
35
  template<class T = void> struct minus;
36
  template<class T = void> struct multiplies;
@@ -56,10 +55,13 @@ namespace std {
56
  template<> struct greater<void>;
57
  template<> struct less<void>;
58
  template<> struct greater_equal<void>;
59
  template<> struct less_equal<void>;
60
 
 
 
 
61
  // [logical.operations], logical operations
62
  template<class T = void> struct logical_and;
63
  template<class T = void> struct logical_or;
64
  template<class T = void> struct logical_not;
65
  template<> struct logical_and<void>;
@@ -74,22 +76,31 @@ namespace std {
74
  template<> struct bit_and<void>;
75
  template<> struct bit_or<void>;
76
  template<> struct bit_xor<void>;
77
  template<> struct bit_not<void>;
78
 
79
- // [func.not_fn], function template not_fn
80
- template <class F>
81
- unspecified not_fn(F&& f);
 
 
 
 
 
82
 
83
  // [func.bind], bind
84
  template<class T> struct is_bind_expression;
 
 
85
  template<class T> struct is_placeholder;
 
 
86
 
87
  template<class F, class... BoundArgs>
88
- unspecified bind(F&&, BoundArgs&&...);
89
  template<class R, class F, class... BoundArgs>
90
- unspecified bind(F&&, BoundArgs&&...);
91
 
92
  namespace placeholders {
93
  // M is the implementation-defined number of placeholders
94
  see belownc _1;
95
  see belownc _2;
@@ -99,11 +110,11 @@ namespace std {
99
  see belownc _M;
100
  }
101
 
102
  // [func.memfn], member function adaptors
103
  template<class R, class T>
104
- unspecified mem_fn(R T::*) noexcept;
105
 
106
  // [func.wrap], polymorphic function wrappers
107
  class bad_function_call;
108
 
109
  template<class> class function; // not defined
@@ -112,16 +123,10 @@ namespace std {
112
  template<class R, class... ArgTypes>
113
  void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&) noexcept;
114
 
115
  template<class R, class... ArgTypes>
116
  bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
117
- template<class R, class... ArgTypes>
118
- bool operator==(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
119
- template<class R, class... ArgTypes>
120
- bool operator!=(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
121
- template<class R, class... ArgTypes>
122
- bool operator!=(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
123
 
124
  // [func.search], searchers
125
  template<class ForwardIterator, class BinaryPredicate = equal_to<>>
126
  class default_searcher;
127
 
@@ -133,19 +138,23 @@ namespace std {
133
  template<class RandomAccessIterator,
134
  class Hash = hash<typename iterator_traits<RandomAccessIterator>::value_type>,
135
  class BinaryPredicate = equal_to<>>
136
  class boyer_moore_horspool_searcher;
137
 
138
- // [unord.hash], hash function primary template
139
  template<class T>
140
  struct hash;
141
 
142
- // [func.bind], function object binders
143
- template <class T>
144
- inline constexpr bool is_bind_expression_v = is_bind_expression<T>::value;
145
- template <class T>
146
- inline constexpr int is_placeholder_v = is_placeholder<T>::value;
 
 
 
 
147
  }
148
  ```
149
 
150
  [*Example 1*:
151
 
@@ -173,11 +182,11 @@ transform(a.begin(), a.end(), a.begin(), negate<double>());
173
  The following definitions apply to this Clause:
174
 
175
  A *call signature* is the name of a return type followed by a
176
  parenthesized comma-separated list of zero or more argument types.
177
 
178
- A *callable type* is a function object type ([[function.objects]]) or a
179
  pointer to member.
180
 
181
  A *callable object* is an object of a callable type.
182
 
183
  A *call wrapper type* is a type that holds a callable object and
@@ -185,66 +194,104 @@ supports a call operation that forwards to that object.
185
 
186
  A *call wrapper* is an object of a call wrapper type.
187
 
188
  A *target object* is the callable object held by a call wrapper.
189
 
 
 
 
 
 
 
 
190
  ### Requirements <a id="func.require">[[func.require]]</a>
191
 
192
- Define `INVOKE(f, t1, t2, ..., tN)` as follows:
193
 
194
- - `(t1.*f)(t2, ..., tN)` when `f` is a pointer to a member function of a
195
- class `T` and `is_base_of_v<T, decay_t<decltype(t1)>>` is `true`;
196
- - `(t1.get().*f)(t2, ..., tN)` when `f` is a pointer to a member
197
- function of a class `T` and `decay_t<decltype(t1)>` is a
198
- specialization of `reference_wrapper`;
199
- - `((*t1).*f)(t2, ..., tN)` when `f` is a pointer to a member function
200
- of a class `T` and `t1` does not satisfy the previous two items;
201
- - `t1.*f` when `N == 1` and `f` is a pointer to data member of a class
202
- `T` and `is_base_of_v<T, decay_t<decltype(t1)>>` is `true`;
203
- - `t1.get().*f` when `N == 1` and `f` is a pointer to data member of a
204
- class `T` and `decay_t<decltype(t1)>` is a specialization of
 
205
  `reference_wrapper`;
206
- - `(*t1).*f` when `N == 1` and `f` is a pointer to data member of a
207
- class `T` and `t1` does not satisfy the previous two items;
208
- - `f(t1, t2, ..., tN)` in all other cases.
209
 
210
- Define `INVOKE<R>(f, t1, t2, ..., tN)` as
211
- `static_cast<void>(INVOKE(f, t1, t2, ..., tN))` if `R` is cv `void`,
212
- otherwise `INVOKE(f, t1, t2, ..., tN)` implicitly converted to `R`.
213
 
214
- Every call wrapper ([[func.def]]) shall be `MoveConstructible`. A
215
- *forwarding call wrapper* is a call wrapper that can be called with an
216
- arbitrary argument list and delivers the arguments to the wrapped
217
- callable object as references. This forwarding step shall ensure that
218
- rvalue arguments are delivered as rvalue references and lvalue arguments
219
- are delivered as lvalue references. A *simple call wrapper* is a
220
- forwarding call wrapper that is `CopyConstructible` and `CopyAssignable`
221
- and whose copy constructor, move constructor, and assignment operator do
222
- not throw exceptions.
223
 
224
  [*Note 1*:
225
 
226
- In a typical implementation forwarding call wrappers have an overloaded
227
- function call operator of the form
228
 
229
  ``` cpp
230
  template<class... UnBoundArgs>
231
- R operator()(UnBoundArgs&&... unbound_args) cv-qual;
232
  ```
233
 
234
  — *end note*]
235
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
236
  ### Function template `invoke` <a id="func.invoke">[[func.invoke]]</a>
237
 
238
  ``` cpp
239
  template<class F, class... Args>
240
- invoke_result_t<F, Args...> invoke(F&& f, Args&&... args)
241
  noexcept(is_nothrow_invocable_v<F, Args...>);
242
  ```
243
 
244
  *Returns:* *INVOKE*(std::forward\<F\>(f),
245
- std::forward\<Args\>(args)...) ([[func.require]]).
246
 
247
  ### Class template `reference_wrapper` <a id="refwrap">[[refwrap]]</a>
248
 
249
  ``` cpp
250
  namespace std {
@@ -252,109 +299,130 @@ namespace std {
252
  public:
253
  // types
254
  using type = T;
255
 
256
  // construct/copy/destroy
257
- reference_wrapper(T&) noexcept;
258
- reference_wrapper(T&&) = delete; // do not bind to temporary objects
259
- reference_wrapper(const reference_wrapper& x) noexcept;
260
 
261
  // assignment
262
- reference_wrapper& operator=(const reference_wrapper& x) noexcept;
263
 
264
  // access
265
- operator T& () const noexcept;
266
- T& get() const noexcept;
267
 
268
  // invocation
269
  template<class... ArgTypes>
270
- invoke_result_t<T&, ArgTypes...>
271
- operator() (ArgTypes&&...) const;
272
  };
273
-
274
  template<class T>
275
- reference_wrapper(reference_wrapper<T>) -> reference_wrapper<T>;
276
  }
277
  ```
278
 
279
- `reference_wrapper<T>` is a `CopyConstructible` and `CopyAssignable`
280
- wrapper around a reference to an object or function of type `T`.
 
281
 
282
- `reference_wrapper<T>` shall be a trivially copyable type (
283
- [[basic.types]]).
284
 
285
- #### `reference_wrapper` construct/copy/destroy <a id="refwrap.const">[[refwrap.const]]</a>
 
 
 
286
 
287
  ``` cpp
288
- reference_wrapper(T& t) noexcept;
 
289
  ```
290
 
291
- *Effects:* Constructs a `reference_wrapper` object that stores a
292
- reference to `t`.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
293
 
294
  ``` cpp
295
- reference_wrapper(const reference_wrapper& x) noexcept;
296
  ```
297
 
298
  *Effects:* Constructs a `reference_wrapper` object that stores a
299
  reference to `x.get()`.
300
 
301
- #### `reference_wrapper` assignment <a id="refwrap.assign">[[refwrap.assign]]</a>
302
 
303
  ``` cpp
304
- reference_wrapper& operator=(const reference_wrapper& x) noexcept;
305
  ```
306
 
307
- *Postconditions:* `*this` stores a reference to `x.get()`.
308
 
309
- #### `reference_wrapper` access <a id="refwrap.access">[[refwrap.access]]</a>
310
 
311
  ``` cpp
312
- operator T& () const noexcept;
313
  ```
314
 
315
  *Returns:* The stored reference.
316
 
317
  ``` cpp
318
- T& get() const noexcept;
319
  ```
320
 
321
  *Returns:* The stored reference.
322
 
323
- #### `reference_wrapper` invocation <a id="refwrap.invoke">[[refwrap.invoke]]</a>
324
 
325
  ``` cpp
326
  template<class... ArgTypes>
327
- invoke_result_t<T&, ArgTypes...>
328
  operator()(ArgTypes&&... args) const;
329
  ```
330
 
 
 
331
  *Returns:* *INVOKE*(get(),
332
- std::forward\<ArgTypes\>(args)...). ([[func.require]])
333
 
334
- #### `reference_wrapper` helper functions <a id="refwrap.helpers">[[refwrap.helpers]]</a>
 
 
 
335
 
336
  ``` cpp
337
- template <class T> reference_wrapper<T> ref(T& t) noexcept;
338
  ```
339
 
340
  *Returns:* `reference_wrapper<T>(t)`.
341
 
342
  ``` cpp
343
- template <class T> reference_wrapper<T> ref(reference_wrapper<T> t) noexcept;
344
  ```
345
 
346
  *Returns:* `ref(t.get())`.
347
 
348
  ``` cpp
349
- template <class T> reference_wrapper<const T> cref(const T& t) noexcept;
350
  ```
351
 
352
  *Returns:* `reference_wrapper <const T>(t)`.
353
 
354
  ``` cpp
355
- template <class T> reference_wrapper<const T> cref(reference_wrapper<T> t) noexcept;
356
  ```
357
 
358
  *Returns:* `cref(t.get())`.
359
 
360
  ### Arithmetic operations <a id="arithmetic.operations">[[arithmetic.operations]]</a>
@@ -546,26 +614,25 @@ template <class T> constexpr auto operator()(T&& t) const
546
 
547
  The library provides basic function object classes for all of the
548
  comparison operators in the language ([[expr.rel]], [[expr.eq]]).
549
 
550
  For templates `less`, `greater`, `less_equal`, and `greater_equal`, the
551
- specializations for any pointer type yield a strict total order that is
552
- consistent among those specializations and is also consistent with the
553
- partial order imposed by the built-in operators `<`, `>`, `<=`, `>=`.
554
 
555
- [*Note 1*: When `a < b` is well-defined for pointers `a` and `b` of
556
- type `P`, this implies `(a < b) == less<P>(a, b)`,
557
- `(a > b) == greater<P>(a, b)`, and so forth. — *end note*]
558
 
559
  For template specializations `less<void>`, `greater<void>`,
560
  `less_equal<void>`, and `greater_equal<void>`, if the call operator
561
  calls a built-in operator comparing pointers, the call operator yields a
562
- strict total order that is consistent among those specializations and is
563
- also consistent with the partial order imposed by those built-in
564
- operators.
565
 
566
- #### Class template `equal_to` <a id="comparisons.equal_to">[[comparisons.equal_to]]</a>
567
 
568
  ``` cpp
569
  template<class T = void> struct equal_to {
570
  constexpr bool operator()(const T& x, const T& y) const;
571
  };
@@ -591,11 +658,11 @@ template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
591
  -> decltype(std::forward<T>(t) == std::forward<U>(u));
592
  ```
593
 
594
  *Returns:* `std::forward<T>(t) == std::forward<U>(u)`.
595
 
596
- #### Class template `not_equal_to` <a id="comparisons.not_equal_to">[[comparisons.not_equal_to]]</a>
597
 
598
  ``` cpp
599
  template<class T = void> struct not_equal_to {
600
  constexpr bool operator()(const T& x, const T& y) const;
601
  };
@@ -681,11 +748,11 @@ template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
681
  -> decltype(std::forward<T>(t) < std::forward<U>(u));
682
  ```
683
 
684
  *Returns:* `std::forward<T>(t) < std::forward<U>(u)`.
685
 
686
- #### Class template `greater_equal` <a id="comparisons.greater_equal">[[comparisons.greater_equal]]</a>
687
 
688
  ``` cpp
689
  template<class T = void> struct greater_equal {
690
  constexpr bool operator()(const T& x, const T& y) const;
691
  };
@@ -711,11 +778,11 @@ template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
711
  -> decltype(std::forward<T>(t) >= std::forward<U>(u));
712
  ```
713
 
714
  *Returns:* `std::forward<T>(t) >= std::forward<U>(u)`.
715
 
716
- #### Class template `less_equal` <a id="comparisons.less_equal">[[comparisons.less_equal]]</a>
717
 
718
  ``` cpp
719
  template<class T = void> struct less_equal {
720
  constexpr bool operator()(const T& x, const T& y) const;
721
  };
@@ -741,10 +808,182 @@ template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
741
  -> decltype(std::forward<T>(t) <= std::forward<U>(u));
742
  ```
743
 
744
  *Returns:* `std::forward<T>(t) <= std::forward<U>(u)`.
745
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
746
  ### Logical operations <a id="logical.operations">[[logical.operations]]</a>
747
 
748
  The library provides basic function object classes for all of the
749
  logical operators in the language ([[expr.log.and]], [[expr.log.or]],
750
  [[expr.unary.op]]).
@@ -963,91 +1202,92 @@ template <class T> constexpr auto operator()(T&&) const
963
  -> decltype(~std::forward<T>(t));
964
  ```
965
 
966
  *Returns:* `~std::forward<T>(t)`.
967
 
968
- ### Function template `not_fn` <a id="func.not_fn">[[func.not_fn]]</a>
969
 
970
  ``` cpp
971
- template <class F> unspecified not_fn(F&& f);
972
- ```
 
973
 
974
- *Effects:* Equivalent to
975
- `return `*`call_wrapper`*`(std::forward<F>(f));` where *`call_wrapper`*
976
- is an exposition only class defined as follows:
977
-
978
- ``` cpp
979
- class call_wrapper {
980
- using FD = decay_t<F>;
981
- FD fd;
982
-
983
- explicit call_wrapper(F&& f);
984
-
985
- public:
986
- call_wrapper(call_wrapper&&) = default;
987
- call_wrapper(const call_wrapper&) = default;
988
-
989
- template<class... Args>
990
- auto operator()(Args&&...) &
991
- -> decltype(!declval<invoke_result_t<FD&, Args...>>());
992
-
993
- template<class... Args>
994
- auto operator()(Args&&...) const&
995
- -> decltype(!declval<invoke_result_t<const FD&, Args...>>());
996
-
997
- template<class... Args>
998
- auto operator()(Args&&...) &&
999
- -> decltype(!declval<invoke_result_t<FD, Args...>>());
1000
-
1001
- template<class... Args>
1002
- auto operator()(Args&&...) const&&
1003
- -> decltype(!declval<invoke_result_t<const FD, Args...>>());
1004
  };
 
 
 
1005
  ```
1006
 
 
 
 
 
1007
  ``` cpp
1008
- explicit call_wrapper(F&& f);
1009
  ```
1010
 
1011
- *Requires:* `FD` shall satisfy the requirements of `MoveConstructible`.
1012
- `is_constructible_v<FD, F>` shall be `true`. `fd` shall be a callable
1013
- object ([[func.def]]).
1014
 
1015
- *Effects:* Initializes `fd` from `std::forward<F>(f)`.
 
 
 
 
 
1016
 
1017
- *Throws:* Any exception thrown by construction of `fd`.
 
1018
 
1019
- ``` cpp
1020
- template<class... Args>
1021
- auto operator()(Args&&... args) &
1022
- -> decltype(!declval<invoke_result_t<FD&, Args...>>());
1023
- template<class... Args>
1024
- auto operator()(Args&&... args) const&
1025
- -> decltype(!declval<invoke_result_t<const FD&, Args...>>());
1026
- ```
1027
 
1028
- *Effects:* Equivalent to:
 
1029
 
1030
- ``` cpp
1031
- return !INVOKE(fd, std::forward<Args>(args)...); // see [func.require]
1032
- ```
1033
 
1034
  ``` cpp
1035
- template<class... Args>
1036
- auto operator()(Args&&... args) &&
1037
- -> decltype(!declval<invoke_result_t<FD, Args...>>());
1038
- template<class... Args>
1039
- auto operator()(Args&&... args) const&&
1040
- -> decltype(!declval<invoke_result_t<const FD, Args...>>());
1041
  ```
1042
 
1043
- *Effects:* Equivalent to:
 
 
 
 
 
 
 
 
 
 
 
 
 
1044
 
1045
  ``` cpp
1046
- return !INVOKE(std::move(fd), std::forward<Args>(args)...); // see [func.require]
 
 
 
1047
  ```
1048
 
 
 
 
 
 
 
 
 
 
 
 
 
1049
  ### Function object binders <a id="func.bind">[[func.bind]]</a>
1050
 
1051
  This subclause describes a uniform mechanism for binding arguments of
1052
  callable objects.
1053
 
@@ -1061,18 +1301,18 @@ namespace std {
1061
 
1062
  The class template `is_bind_expression` can be used to detect function
1063
  objects generated by `bind`. The function template `bind` uses
1064
  `is_bind_expression` to detect subexpressions.
1065
 
1066
- Instantiations of the `is_bind_expression` template shall meet the
1067
- `UnaryTypeTrait` requirements ([[meta.rqmts]]). The implementation
1068
- shall provide a definition that has a base characteristic of `true_type`
1069
- if `T` is a type returned from `bind`, otherwise it shall have a base
1070
  characteristic of `false_type`. A program may specialize this template
1071
- for a user-defined type `T` to have a base characteristic of `true_type`
1072
- to indicate that `T` should be treated as a subexpression in a `bind`
1073
- call.
1074
 
1075
  #### Class template `is_placeholder` <a id="func.bind.isplace">[[func.bind.isplace]]</a>
1076
 
1077
  ``` cpp
1078
  namespace std {
@@ -1082,120 +1322,100 @@ namespace std {
1082
 
1083
  The class template `is_placeholder` can be used to detect the standard
1084
  placeholders `_1`, `_2`, and so on. The function template `bind` uses
1085
  `is_placeholder` to detect placeholders.
1086
 
1087
- Instantiations of the `is_placeholder` template shall meet the
1088
- `UnaryTypeTrait` requirements ([[meta.rqmts]]). The implementation
1089
- shall provide a definition that has the base characteristic of
1090
  `integral_constant<int, J>` if `T` is the type of
1091
- `std::placeholders::_J`, otherwise it shall have a base characteristic
1092
- of `integral_constant<int, 0>`. A program may specialize this template
1093
- for a user-defined type `T` to have a base characteristic of
1094
  `integral_constant<int, N>` with `N > 0` to indicate that `T` should be
1095
  treated as a placeholder type.
1096
 
1097
  #### Function template `bind` <a id="func.bind.bind">[[func.bind.bind]]</a>
1098
 
1099
  In the text that follows:
1100
 
 
1101
  - `FD` is the type `decay_t<F>`,
1102
- - `fd` is an lvalue of type `FD` constructed from `std::forward<F>(f)`,
 
1103
  - `Tᵢ` is the iᵗʰ type in the template parameter pack `BoundArgs`,
1104
  - `TDᵢ` is the type `decay_t<Tᵢ>`,
1105
  - `tᵢ` is the iᵗʰ argument in the function parameter pack `bound_args`,
1106
- - `tdᵢ` is an lvalue of type `TDᵢ` constructed from
1107
- `std::forward<Tᵢ>(tᵢ)`,
1108
  - `Uⱼ` is the jᵗʰ deduced type of the `UnBoundArgs&&...` parameter of
1109
- the forwarding call wrapper, and
1110
  - `uⱼ` is the jᵗʰ argument associated with `Uⱼ`.
1111
 
1112
  ``` cpp
1113
  template<class F, class... BoundArgs>
1114
- unspecified bind(F&& f, BoundArgs&&... bound_args);
1115
- ```
1116
-
1117
- *Requires:* `is_constructible_v<FD, F>` shall be `true`. For each `Tᵢ`
1118
- in `BoundArgs`, `is_constructible_v<``TDᵢ``, ``Tᵢ``>` shall be `true`.
1119
- *INVOKE*(fd, w₁, w₂, …, $w_N$) ([[func.require]]) shall be a valid
1120
- expression for some values `w₁`, `w₂`, …, `w_N`, where N has the value
1121
- `sizeof...(bound_args)`. The cv-qualifiers cv of the call wrapper `g`,
1122
- as specified below, shall be neither `volatile` nor `const volatile`.
1123
-
1124
- *Returns:* A forwarding call wrapper `g` ([[func.require]]). The effect
1125
- of `g(``u₁``, ``u₂``, …, ``u_M``)` shall be
1126
-
1127
- ``` cpp
1128
- INVOKE(fd, std::forward<$V_1$>($v_1$), std::forward<$V_2$>($v_2$), … , std::forward<$V_N$>($v_N$))
1129
- ```
1130
-
1131
- where the values and types of the bound arguments `v₁`, `v₂`, …, `v_N`
1132
- are determined as specified below. The copy constructor and move
1133
- constructor of the forwarding call wrapper shall throw an exception if
1134
- and only if the corresponding constructor of `FD` or of any of the types
1135
- `TDᵢ` throws an exception.
1136
-
1137
- *Throws:* Nothing unless the construction of `fd` or of one of the
1138
- values `tdᵢ` throws an exception.
1139
-
1140
- *Remarks:* The return type shall satisfy the requirements of
1141
- `MoveConstructible`. If all of `FD` and `TDᵢ` satisfy the requirements
1142
- of `CopyConstructible`, then the return type shall satisfy the
1143
- requirements of `CopyConstructible`.
1144
-
1145
- [*Note 1*: This implies that all of `FD` and `TDᵢ` are
1146
- `MoveConstructible`. — *end note*]
1147
-
1148
- ``` cpp
1149
  template<class R, class F, class... BoundArgs>
1150
- unspecified bind(F&& f, BoundArgs&&... bound_args);
1151
  ```
1152
 
1153
- *Requires:* `is_constructible_v<FD, F>` shall be `true`. For each `Tᵢ`
1154
- in `BoundArgs`, `is_constructible_v<``TDᵢ``, ``Tᵢ``>` shall be `true`.
1155
- *INVOKE*(fd, w₁, w₂, …, $w_N$) shall be a valid expression for some
1156
- values `w₁`, `w₂`, …, `w_N`, where N has the value
1157
- `sizeof...(bound_args)`. The cv-qualifiers cv of the call wrapper `g`,
1158
- as specified below, shall be neither `volatile` nor `const volatile`.
1159
 
1160
- *Returns:* A forwarding call wrapper `g` ([[func.require]]). The effect
1161
- of `g(``u``, ``u``, …, ``u_M``)` shall be
 
 
 
 
 
 
 
 
1162
 
1163
  ``` cpp
1164
- INVOKE<R>(fd, std::forward<$V_1$>($v_1$), std::forward<$V_2$>($v_2$), … , std::forward<$V_N$>($v_N$))
 
1165
  ```
1166
 
1167
- where the values and types of the bound arguments `v₁`, `v₂`, …, `v_N`
1168
- are determined as specified below. The copy constructor and move
1169
- constructor of the forwarding call wrapper shall throw an exception if
1170
- and only if the corresponding constructor of `FD` or of any of the types
1171
- `TDᵢ` throws an exception.
 
1172
 
1173
- *Throws:* Nothing unless the construction of `fd` or of one of the
1174
- values `tdᵢ` throws an exception.
 
1175
 
1176
- *Remarks:* The return type shall satisfy the requirements of
1177
- `MoveConstructible`. If all of `FD` and `TDᵢ` satisfy the requirements
1178
- of `CopyConstructible`, then the return type shall satisfy the
1179
- requirements of `CopyConstructible`.
1180
 
1181
- [*Note 2*: This implies that all of `FD` and `TDᵢ` are
1182
- `MoveConstructible`. *end note*]
 
1183
 
1184
  The values of the *bound arguments* `v₁`, `v₂`, …, `v_N` and their
1185
  corresponding types `V₁`, `V₂`, …, `V_N` depend on the types `TDᵢ`
1186
  derived from the call to `bind` and the cv-qualifiers cv of the call
1187
  wrapper `g` as follows:
1188
 
1189
  - if `TDᵢ` is `reference_wrapper<T>`, the argument is `tdᵢ.get()` and
1190
  its type `Vᵢ` is `T&`;
1191
  - if the value of `is_bind_expression_v<TDᵢ>` is `true`, the argument is
1192
- `tdᵢ(std::forward<Uⱼ>(uⱼ)...)` and its type `Vᵢ` is
1193
- `invoke_result_t<TDᵢ cv &, Uⱼ...>&&`;
 
 
 
1194
  - if the value `j` of `is_placeholder_v<TDᵢ>` is not zero, the argument
1195
  is `std::forward<Uⱼ>(uⱼ)` and its type `Vᵢ` is `Uⱼ&&`;
1196
- - otherwise, the value is `tdᵢ` and its type `Vᵢ` is `TDᵢ cv &`.
 
 
 
1197
 
1198
  #### Placeholders <a id="func.bind.place">[[func.bind.place]]</a>
1199
 
1200
  ``` cpp
1201
  namespace std::placeholders {
@@ -1207,68 +1427,68 @@ namespace std::placeholders {
1207
  .
1208
  see below _M;
1209
  }
1210
  ```
1211
 
1212
- All placeholder types shall be `DefaultConstructible` and
1213
- `CopyConstructible`, and their default constructors and copy/move
1214
- constructors shall not throw exceptions. It is *implementation-defined*
1215
- whether placeholder types are `CopyAssignable`. `CopyAssignable`
1216
- placeholders’ copy assignment operators shall not throw exceptions.
 
 
1217
 
1218
  Placeholders should be defined as:
1219
 
1220
  ``` cpp
1221
  inline constexpr unspecified _1{};
1222
  ```
1223
 
1224
- If they are not, they shall be declared as:
1225
 
1226
  ``` cpp
1227
  extern unspecified _1;
1228
  ```
1229
 
1230
  ### Function template `mem_fn` <a id="func.memfn">[[func.memfn]]</a>
1231
 
1232
  ``` cpp
1233
- template<class R, class T> unspecified mem_fn(R T::* pm) noexcept;
1234
  ```
1235
 
1236
- *Returns:* A simple call wrapper ([[func.def]]) `fn` such that the
1237
- expression `fn(t, a2, ..., aN)` is equivalent to *INVOKE*(pm, t, a2,
1238
- ..., aN) ([[func.require]]).
 
 
1239
 
1240
  ### Polymorphic function wrappers <a id="func.wrap">[[func.wrap]]</a>
1241
 
1242
  This subclause describes a polymorphic wrapper class that encapsulates
1243
  arbitrary callable objects.
1244
 
1245
  #### Class `bad_function_call` <a id="func.wrap.badcall">[[func.wrap.badcall]]</a>
1246
 
1247
  An exception of type `bad_function_call` is thrown by
1248
- `function::operator()` ([[func.wrap.func.inv]]) when the function
1249
- wrapper object has no target.
1250
 
1251
  ``` cpp
1252
  namespace std {
1253
  class bad_function_call : public exception {
1254
  public:
1255
- // [func.wrap.badcall.const], constructor
1256
- bad_function_call() noexcept;
1257
  };
1258
  }
1259
  ```
1260
 
1261
- ##### `bad_function_call` constructor <a id="func.wrap.badcall.const">[[func.wrap.badcall.const]]</a>
1262
-
1263
  ``` cpp
1264
- bad_function_call() noexcept;
1265
  ```
1266
 
1267
- *Effects:* Constructs a `bad_function_call` object.
1268
-
1269
- *Postconditions:* `what()` returns an *implementation-defined* NTBS.
1270
 
1271
  #### Class template `function` <a id="func.wrap.func">[[func.wrap.func]]</a>
1272
 
1273
  ``` cpp
1274
  namespace std {
@@ -1281,11 +1501,11 @@ namespace std {
1281
 
1282
  // [func.wrap.func.con], construct/copy/destroy
1283
  function() noexcept;
1284
  function(nullptr_t) noexcept;
1285
  function(const function&);
1286
- function(function&&);
1287
  template<class F> function(F);
1288
 
1289
  function& operator=(const function&);
1290
  function& operator=(function&&);
1291
  function& operator=(nullptr_t) noexcept;
@@ -1312,132 +1532,116 @@ namespace std {
1312
  template<class R, class... ArgTypes>
1313
  function(R(*)(ArgTypes...)) -> function<R(ArgTypes...)>;
1314
 
1315
  template<class F> function(F) -> function<see below>;
1316
 
1317
- // [func.wrap.func.nullptr], Null pointer comparisons
1318
  template<class R, class... ArgTypes>
1319
  bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
1320
 
1321
- template <class R, class... ArgTypes>
1322
- bool operator==(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
1323
-
1324
- template <class R, class... ArgTypes>
1325
- bool operator!=(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
1326
-
1327
- template <class R, class... ArgTypes>
1328
- bool operator!=(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
1329
-
1330
  // [func.wrap.func.alg], specialized algorithms
1331
  template<class R, class... ArgTypes>
1332
  void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&) noexcept;
1333
  }
1334
  ```
1335
 
1336
  The `function` class template provides polymorphic wrappers that
1337
  generalize the notion of a function pointer. Wrappers can store, copy,
1338
- and call arbitrary callable objects ([[func.def]]), given a call
1339
- signature ([[func.def]]), allowing functions to be first-class objects.
1340
 
1341
- A callable type ([[func.def]]) `F` is *Lvalue-Callable* for argument
1342
- types `ArgTypes` and return type `R` if the expression
1343
  `INVOKE<R>(declval<F&>(), declval<ArgTypes>()...)`, considered as an
1344
- unevaluated operand (Clause  [[expr]]), is well formed (
1345
- [[func.require]]).
1346
 
1347
- The `function` class template is a call wrapper ([[func.def]]) whose
1348
- call signature ([[func.def]]) is `R(ArgTypes...)`.
1349
 
1350
  [*Note 1*: The types deduced by the deduction guides for `function` may
1351
  change in future versions of this International Standard. — *end note*]
1352
 
1353
- ##### `function` construct/copy/destroy <a id="func.wrap.func.con">[[func.wrap.func.con]]</a>
1354
 
1355
  ``` cpp
1356
  function() noexcept;
1357
  ```
1358
 
1359
- *Postconditions:* `!*this`.
1360
 
1361
  ``` cpp
1362
  function(nullptr_t) noexcept;
1363
  ```
1364
 
1365
- *Postconditions:* `!*this`.
1366
 
1367
  ``` cpp
1368
  function(const function& f);
1369
  ```
1370
 
1371
- *Postconditions:* `!*this` if `!f`; otherwise, `*this` targets a copy of
1372
  `f.target()`.
1373
 
1374
- *Throws:* shall not throw exceptions if `f`’s target is a specialization
1375
- of `reference_wrapper` or a function pointer. Otherwise, may throw
1376
  `bad_alloc` or any exception thrown by the copy constructor of the
1377
  stored callable object.
1378
 
1379
- [*Note 1*: Implementations are encouraged to avoid the use of
1380
- dynamically allocated memory for small callable objects, for example,
1381
- where `f`’s target is an object holding only a pointer or reference to
1382
- an object and a member function pointer. — *end note*]
1383
 
1384
  ``` cpp
1385
- function(function&& f);
1386
  ```
1387
 
1388
- *Postconditions:* If `!f`, `*this` has no target; otherwise, the target
1389
- of `*this` is equivalent to the target of `f` before the construction,
1390
- and `f` is in a valid state with an unspecified value.
1391
 
1392
- *Throws:* shall not throw exceptions if `f`’s target is a specialization
1393
- of `reference_wrapper` or a function pointer. Otherwise, may throw
1394
- `bad_alloc` or any exception thrown by the copy or move constructor of
1395
- the stored callable object.
1396
-
1397
- [*Note 2*: Implementations are encouraged to avoid the use of
1398
- dynamically allocated memory for small callable objects, for example,
1399
- where `f`’s target is an object holding only a pointer or reference to
1400
- an object and a member function pointer. — *end note*]
1401
 
1402
  ``` cpp
1403
  template<class F> function(F f);
1404
  ```
1405
 
1406
- *Requires:* `F` shall be `CopyConstructible`.
 
1407
 
1408
- *Remarks:* This constructor template shall not participate in overload
1409
- resolution unless `F` is Lvalue-Callable ([[func.wrap.func]]) for
1410
- argument types `ArgTypes...` and return type `R`.
1411
 
1412
- *Postconditions:* `!*this` if any of the following hold:
1413
 
1414
  - `f` is a null function pointer value.
1415
  - `f` is a null member pointer value.
1416
  - `F` is an instance of the `function` class template, and `!f`.
1417
 
1418
  Otherwise, `*this` targets a copy of `f` initialized with
1419
  `std::move(f)`.
1420
 
1421
- [*Note 3*: Implementations are encouraged to avoid the use of
1422
- dynamically allocated memory for small callable objects, for example,
1423
- where `f` is an object holding only a pointer or reference to an object
1424
- and a member function pointer. — *end note*]
1425
 
1426
- *Throws:* shall not throw exceptions when `f` is a function pointer or a
1427
- `reference_wrapper<T>` for some `T`. Otherwise, may throw `bad_alloc` or
1428
- any exception thrown by `F`’s copy or move constructor.
1429
 
1430
  ``` cpp
1431
  template<class F> function(F) -> function<see below>;
1432
  ```
1433
 
1434
- *Remarks:* This deduction guide participates in overload resolution only
1435
- if `&F::operator()` is well-formed when treated as an unevaluated
1436
- operand. In that case, if `decltype(&F::operator())` is of the form
1437
- `R(G::*)(A...)` cv `&`ₒₚₜ ` noexcept` for a class type `G`, then the
1438
- deduced type is `function<R(A...)>`.
1439
 
1440
  [*Example 1*:
1441
 
1442
  ``` cpp
1443
  void f() {
@@ -1468,26 +1672,25 @@ function& operator=(function&& f);
1468
  function& operator=(nullptr_t) noexcept;
1469
  ```
1470
 
1471
  *Effects:* If `*this != nullptr`, destroys the target of `this`.
1472
 
1473
- *Postconditions:* `!(*this)`.
1474
 
1475
  *Returns:* `*this`.
1476
 
1477
  ``` cpp
1478
  template<class F> function& operator=(F&& f);
1479
  ```
1480
 
 
 
 
1481
  *Effects:* As if by: `function(std::forward<F>(f)).swap(*this);`
1482
 
1483
  *Returns:* `*this`.
1484
 
1485
- *Remarks:* This assignment operator shall not participate in overload
1486
- resolution unless `decay_t<F>` is Lvalue-Callable ([[func.wrap.func]])
1487
- for argument types `ArgTypes...` and return type `R`.
1488
-
1489
  ``` cpp
1490
  template<class F> function& operator=(reference_wrapper<F> f) noexcept;
1491
  ```
1492
 
1493
  *Effects:* As if by: `function(f).swap(*this);`
@@ -1498,40 +1701,40 @@ template<class F> function& operator=(reference_wrapper<F> f) noexcept;
1498
  ~function();
1499
  ```
1500
 
1501
  *Effects:* If `*this != nullptr`, destroys the target of `this`.
1502
 
1503
- ##### `function` modifiers <a id="func.wrap.func.mod">[[func.wrap.func.mod]]</a>
1504
 
1505
  ``` cpp
1506
  void swap(function& other) noexcept;
1507
  ```
1508
 
1509
- *Effects:* interchanges the targets of `*this` and `other`.
1510
 
1511
- ##### `function` capacity <a id="func.wrap.func.cap">[[func.wrap.func.cap]]</a>
1512
 
1513
  ``` cpp
1514
  explicit operator bool() const noexcept;
1515
  ```
1516
 
1517
  *Returns:* `true` if `*this` has a target, otherwise `false`.
1518
 
1519
- ##### `function` invocation <a id="func.wrap.func.inv">[[func.wrap.func.inv]]</a>
1520
 
1521
  ``` cpp
1522
  R operator()(ArgTypes... args) const;
1523
  ```
1524
 
1525
  *Returns:* *INVOKE*\<R\>(f,
1526
- std::forward\<ArgTypes\>(args)...) ([[func.require]]), where `f` is the
1527
- target object ([[func.def]]) of `*this`.
1528
 
1529
  *Throws:* `bad_function_call` if `!*this`; otherwise, any exception
1530
  thrown by the wrapped callable object.
1531
 
1532
- ##### `function` target access <a id="func.wrap.func.targ">[[func.wrap.func.targ]]</a>
1533
 
1534
  ``` cpp
1535
  const type_info& target_type() const noexcept;
1536
  ```
1537
 
@@ -1544,51 +1747,40 @@ template<class T> const T* target() const noexcept;
1544
  ```
1545
 
1546
  *Returns:* If `target_type() == typeid(T)` a pointer to the stored
1547
  function target; otherwise a null pointer.
1548
 
1549
- ##### null pointer comparison functions <a id="func.wrap.func.nullptr">[[func.wrap.func.nullptr]]</a>
1550
 
1551
  ``` cpp
1552
  template<class R, class... ArgTypes>
1553
  bool operator==(const function<R(ArgTypes...)>& f, nullptr_t) noexcept;
1554
- template <class R, class... ArgTypes>
1555
- bool operator==(nullptr_t, const function<R(ArgTypes...)>& f) noexcept;
1556
  ```
1557
 
1558
  *Returns:* `!f`.
1559
 
1560
- ``` cpp
1561
- template <class R, class... ArgTypes>
1562
- bool operator!=(const function<R(ArgTypes...)>& f, nullptr_t) noexcept;
1563
- template <class R, class... ArgTypes>
1564
- bool operator!=(nullptr_t, const function<R(ArgTypes...)>& f) noexcept;
1565
- ```
1566
-
1567
- *Returns:* `(bool)f`.
1568
-
1569
- ##### specialized algorithms <a id="func.wrap.func.alg">[[func.wrap.func.alg]]</a>
1570
 
1571
  ``` cpp
1572
  template<class R, class... ArgTypes>
1573
  void swap(function<R(ArgTypes...)>& f1, function<R(ArgTypes...)>& f2) noexcept;
1574
  ```
1575
 
1576
  *Effects:* As if by: `f1.swap(f2);`
1577
 
1578
  ### Searchers <a id="func.search">[[func.search]]</a>
1579
 
1580
- This subclause provides function object types ([[function.objects]])
1581
- for operations that search for a sequence \[`pat``first`, `pat_last`) in
1582
  another sequence \[`first`, `last`) that is provided to the object’s
1583
  function call operator. The first sequence (the pattern to be searched
1584
  for) is provided to the object’s constructor, and the second (the
1585
  sequence to be searched) is provided to the function call operator.
1586
 
1587
  Each specialization of a class template specified in this subclause
1588
- [[func.search]] shall meet the `CopyConstructible` and `CopyAssignable`
1589
- requirements. Template parameters named
1590
 
1591
  - `ForwardIterator`,
1592
  - `ForwardIterator1`,
1593
  - `ForwardIterator2`,
1594
  - `RandomAccessIterator`,
@@ -1596,12 +1788,12 @@ requirements. Template parameters named
1596
  - `RandomAccessIterator2`, and
1597
  - `BinaryPredicate`
1598
 
1599
  of templates specified in this subclause [[func.search]] shall meet the
1600
  same requirements and semantics as specified in [[algorithms.general]].
1601
- Template parameters named `Hash` shall meet the requirements as
1602
- specified in [[hash.requirements]].
1603
 
1604
  The Boyer-Moore searcher implements the Boyer-Moore search algorithm.
1605
  The Boyer-Moore-Horspool searcher implements the Boyer-Moore-Horspool
1606
  search algorithm. In general, the Boyer-Moore searcher will use more
1607
  memory and give better runtime performance than Boyer-Moore-Horspool.
@@ -1610,26 +1802,26 @@ memory and give better runtime performance than Boyer-Moore-Horspool.
1610
 
1611
  ``` cpp
1612
  template<class ForwardIterator1, class BinaryPredicate = equal_to<>>
1613
  class default_searcher {
1614
  public:
1615
- default_searcher(ForwardIterator1 pat_first, ForwardIterator1 pat_last,
1616
  BinaryPredicate pred = BinaryPredicate());
1617
 
1618
  template<class ForwardIterator2>
1619
- pair<ForwardIterator2, ForwardIterator2>
1620
  operator()(ForwardIterator2 first, ForwardIterator2 last) const;
1621
 
1622
  private:
1623
  ForwardIterator1 pat_first_; // exposition only
1624
  ForwardIterator1 pat_last_; // exposition only
1625
  BinaryPredicate pred_; // exposition only
1626
  };
1627
  ```
1628
 
1629
  ``` cpp
1630
- default_searcher(ForwardIterator pat_first, ForwardIterator pat_last,
1631
  BinaryPredicate pred = BinaryPredicate());
1632
  ```
1633
 
1634
  *Effects:* Constructs a `default_searcher` object, initializing
1635
  `pat_first_` with `pat_first`, \texttt{pat_last\_} with `pat_last`, and
@@ -1638,11 +1830,11 @@ default_searcher(ForwardIterator pat_first, ForwardIterator pat_last,
1638
  *Throws:* Any exception thrown by the copy constructor of
1639
  `BinaryPredicate` or `ForwardIterator1`.
1640
 
1641
  ``` cpp
1642
  template<class ForwardIterator2>
1643
- pair<ForwardIterator2, ForwardIterator2>
1644
  operator()(ForwardIterator2 first, ForwardIterator2 last) const;
1645
  ```
1646
 
1647
  *Effects:* Returns a pair of iterators `i` and `j` such that
1648
 
@@ -1680,21 +1872,21 @@ boyer_moore_searcher(RandomAccessIterator1 pat_first,
1680
  RandomAccessIterator1 pat_last,
1681
  Hash hf = Hash(),
1682
  BinaryPredicate pred = BinaryPredicate());
1683
  ```
1684
 
1685
- *Requires:* The value type of `RandomAccessIterator1` shall meet the
1686
- `DefaultConstructible` requirements, the `CopyConstructible`
1687
- requirements, and the `CopyAssignable` requirements.
1688
 
1689
- *Requires:* For any two values `A` and `B` of the type
1690
- `iterator_traits<RandomAccessIterator1>::value_type`, if
1691
- `pred(A, B) == true`, then `hf(A) == hf(B)` shall be `true`.
 
1692
 
1693
- *Effects:* Constructs a `boyer_moore_searcher` object, initializing
1694
- `pat_first_` with `pat_first`, `pat_last_` with `pat_last`, `hash_` with
1695
- `hf`, and `pred_` with `pred`.
1696
 
1697
  *Throws:* Any exception thrown by the copy constructor of
1698
  `RandomAccessIterator1`, or by the default constructor, copy
1699
  constructor, or the copy assignment operator of the value type of
1700
  `RandomAccessIterator1`, or the copy constructor or `operator()` of
@@ -1705,12 +1897,12 @@ needed for internal data structures cannot be allocated.
1705
  template<class RandomAccessIterator2>
1706
  pair<RandomAccessIterator2, RandomAccessIterator2>
1707
  operator()(RandomAccessIterator2 first, RandomAccessIterator2 last) const;
1708
  ```
1709
 
1710
- *Requires:* `RandomAccessIterator1` and `RandomAccessIterator2` shall
1711
- have the same value type.
1712
 
1713
  *Effects:* Finds a subsequence of equal values in a sequence.
1714
 
1715
  *Returns:* A pair of iterators `i` and `j` such that
1716
 
@@ -1757,21 +1949,21 @@ boyer_moore_horspool_searcher(RandomAccessIterator1 pat_first,
1757
  RandomAccessIterator1 pat_last,
1758
  Hash hf = Hash(),
1759
  BinaryPredicate pred = BinaryPredicate());
1760
  ```
1761
 
1762
- *Requires:* The value type of `RandomAccessIterator1` shall meet the
1763
- `DefaultConstructible`, `CopyConstructible`, and `CopyAssignable`
1764
- requirements.
1765
 
1766
- *Requires:* For any two values `A` and `B` of the type
1767
- `iterator_traits<RandomAccessIterator1>::value_type`, if
1768
- `pred(A, B) == true`, then `hf(A) == hf(B)` shall be `true`.
 
1769
 
1770
- *Effects:* Constructs a `boyer_moore_horspool_searcher` object,
1771
- initializing `pat_first_` with `pat_first`, `pat_last_` with `pat_last`,
1772
- `hash_` with `hf`, and `pred_` with `pred`.
1773
 
1774
  *Throws:* Any exception thrown by the copy constructor of
1775
  `RandomAccessIterator1`, or by the default constructor, copy
1776
  constructor, or the copy assignment operator of the value type of
1777
  `RandomAccessIterator1` or the copy constructor or `operator()` of
@@ -1782,12 +1974,12 @@ needed for internal data structures cannot be allocated.
1782
  template<class RandomAccessIterator2>
1783
  pair<RandomAccessIterator2, RandomAccessIterator2>
1784
  operator()(RandomAccessIterator2 first, RandomAccessIterator2 last) const;
1785
  ```
1786
 
1787
- *Requires:* `RandomAccessIterator1` and `RandomAccessIterator2` shall
1788
- have the same value type.
1789
 
1790
  *Effects:* Finds a subsequence of equal values in a sequence.
1791
 
1792
  *Returns:* A pair of iterators `i` and `j` such that
1793
 
@@ -1805,18 +1997,18 @@ found.
1805
  applications of the predicate.
1806
 
1807
  ### Class template `hash` <a id="unord.hash">[[unord.hash]]</a>
1808
 
1809
  The unordered associative containers defined in [[unord]] use
1810
- specializations of the class template `hash` ([[functional.syn]]) as
1811
- the default hash function.
1812
 
1813
  Each specialization of `hash` is either enabled or disabled, as
1814
  described below.
1815
 
1816
- [*Note 1*: Enabled specializations meet the requirements of `Hash`, and
1817
- disabled specializations do not. — *end note*]
1818
 
1819
  Each header that declares the template `hash` provides enabled
1820
  specializations of `hash` for `nullptr_t` and all cv-unqualified
1821
  arithmetic, enumeration, and pointer types. For any type `Key` for which
1822
  neither the library nor the user provides an explicit or partial
@@ -1828,25 +2020,25 @@ and its member functions are `noexcept` except as noted otherwise.
1828
 
1829
  If `H` is a disabled specialization of `hash`, these values are `false`:
1830
  `is_default_constructible_v<H>`, `is_copy_constructible_v<H>`,
1831
  `is_move_constructible_v<H>`, `is_copy_assignable_v<H>`, and
1832
  `is_move_assignable_v<H>`. Disabled specializations of `hash` are not
1833
- function object types ([[function.objects]]).
1834
 
1835
  [*Note 2*: This means that the specialization of `hash` exists, but any
1836
- attempts to use it as a `Hash` will be ill-formed. — *end note*]
1837
 
1838
  An enabled specialization `hash<Key>` will:
1839
 
1840
- - satisfy the `Hash` requirements ([[hash.requirements]]), with `Key`
1841
- as the function call argument type, the `DefaultConstructible`
1842
- requirements (Table  [[tab:defaultconstructible]]), the
1843
- `CopyAssignable` requirements (Table  [[tab:copyassignable]]),
1844
- - be swappable ([[swappable.requirements]]) for lvalues,
1845
- - satisfy the requirement that if `k1 == k2` is `true`, `h(k1) == h(k2)`
1846
- is also `true`, where `h` is an object of type `hash<Key>` and `k1`
1847
- and `k2` are objects of type `Key`;
1848
- - satisfy the requirement that the expression `h(k)`, where `h` is an
1849
  object of type `hash<Key>` and `k` is an object of type `Key`, shall
1850
- not throw an exception unless `hash<Key>` is a user-defined
1851
- specialization that depends on at least one user-defined type.
1852
 
 
1
  ## Function objects <a id="function.objects">[[function.objects]]</a>
2
 
3
+ A *function object type* is an object type [[basic.types]] that can be
4
+ the type of the *postfix-expression* in a function call ([[expr.call]],
5
+ [[over.match.call]]).[^2] A *function object* is an object of a function
6
+ object type. In the places where one would expect to pass a pointer to a
7
+ function to an algorithmic template [[algorithms]], the interface is
8
+ specified to accept a function object. This not only makes algorithmic
9
+ templates work with pointers to functions, but also enables them to work
10
+ with arbitrary function objects.
 
11
 
12
  ### Header `<functional>` synopsis <a id="functional.syn">[[functional.syn]]</a>
13
 
14
  ``` cpp
15
  namespace std {
16
  // [func.invoke], invoke
17
  template<class F, class... Args>
18
+ constexpr invoke_result_t<F, Args...> invoke(F&& f, Args&&... args)
19
  noexcept(is_nothrow_invocable_v<F, Args...>);
20
 
21
  // [refwrap], reference_wrapper
22
  template<class T> class reference_wrapper;
23
 
24
+ template<class T> constexpr reference_wrapper<T> ref(T&) noexcept;
25
+ template<class T> constexpr reference_wrapper<const T> cref(const T&) noexcept;
26
  template<class T> void ref(const T&&) = delete;
27
  template<class T> void cref(const T&&) = delete;
28
 
29
+ template<class T> constexpr reference_wrapper<T> ref(reference_wrapper<T>) noexcept;
30
+ template<class T> constexpr reference_wrapper<const T> cref(reference_wrapper<T>) noexcept;
31
 
32
  // [arithmetic.operations], arithmetic operations
33
  template<class T = void> struct plus;
34
  template<class T = void> struct minus;
35
  template<class T = void> struct multiplies;
 
55
  template<> struct greater<void>;
56
  template<> struct less<void>;
57
  template<> struct greater_equal<void>;
58
  template<> struct less_equal<void>;
59
 
60
+ // [comparisons.three.way], class compare_three_way
61
+ struct compare_three_way;
62
+
63
  // [logical.operations], logical operations
64
  template<class T = void> struct logical_and;
65
  template<class T = void> struct logical_or;
66
  template<class T = void> struct logical_not;
67
  template<> struct logical_and<void>;
 
76
  template<> struct bit_and<void>;
77
  template<> struct bit_or<void>;
78
  template<> struct bit_xor<void>;
79
  template<> struct bit_not<void>;
80
 
81
+ // [func.identity], identity
82
+ struct identity;
83
+
84
+ // [func.not.fn], function template not_fn
85
+ template<class F> constexpr unspecified not_fn(F&& f);
86
+
87
+ // [func.bind.front], function template bind_front
88
+ template<class F, class... Args> constexpr unspecified bind_front(F&&, Args&&...);
89
 
90
  // [func.bind], bind
91
  template<class T> struct is_bind_expression;
92
+ template<class T>
93
+ inline constexpr bool is_bind_expression_v = is_bind_expression<T>::value;
94
  template<class T> struct is_placeholder;
95
+ template<class T>
96
+ inline constexpr int is_placeholder_v = is_placeholder<T>::value;
97
 
98
  template<class F, class... BoundArgs>
99
+ constexpr unspecified bind(F&&, BoundArgs&&...);
100
  template<class R, class F, class... BoundArgs>
101
+ constexpr unspecified bind(F&&, BoundArgs&&...);
102
 
103
  namespace placeholders {
104
  // M is the implementation-defined number of placeholders
105
  see belownc _1;
106
  see belownc _2;
 
110
  see belownc _M;
111
  }
112
 
113
  // [func.memfn], member function adaptors
114
  template<class R, class T>
115
+ constexpr unspecified mem_fn(R T::*) noexcept;
116
 
117
  // [func.wrap], polymorphic function wrappers
118
  class bad_function_call;
119
 
120
  template<class> class function; // not defined
 
123
  template<class R, class... ArgTypes>
124
  void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&) noexcept;
125
 
126
  template<class R, class... ArgTypes>
127
  bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
 
 
 
 
 
 
128
 
129
  // [func.search], searchers
130
  template<class ForwardIterator, class BinaryPredicate = equal_to<>>
131
  class default_searcher;
132
 
 
138
  template<class RandomAccessIterator,
139
  class Hash = hash<typename iterator_traits<RandomAccessIterator>::value_type>,
140
  class BinaryPredicate = equal_to<>>
141
  class boyer_moore_horspool_searcher;
142
 
143
+ // [unord.hash], class template hash
144
  template<class T>
145
  struct hash;
146
 
147
+ namespace ranges {
148
+ // [range.cmp], concept-constrained comparisons
149
+ struct equal_to;
150
+ struct not_equal_to;
151
+ struct greater;
152
+ struct less;
153
+ struct greater_equal;
154
+ struct less_equal;
155
+ }
156
  }
157
  ```
158
 
159
  [*Example 1*:
160
 
 
182
  The following definitions apply to this Clause:
183
 
184
  A *call signature* is the name of a return type followed by a
185
  parenthesized comma-separated list of zero or more argument types.
186
 
187
+ A *callable type* is a function object type [[function.objects]] or a
188
  pointer to member.
189
 
190
  A *callable object* is an object of a callable type.
191
 
192
  A *call wrapper type* is a type that holds a callable object and
 
194
 
195
  A *call wrapper* is an object of a call wrapper type.
196
 
197
  A *target object* is the callable object held by a call wrapper.
198
 
199
+ A call wrapper type may additionally hold a sequence of objects and
200
+ references that may be passed as arguments to the target object. These
201
+ entities are collectively referred to as *bound argument entities*.
202
+
203
+ The target object and bound argument entities of the call wrapper are
204
+ collectively referred to as *state entities*.
205
+
206
  ### Requirements <a id="func.require">[[func.require]]</a>
207
 
208
+ Define `INVOKE(f, t₁, t₂, , t_N)` as follows:
209
 
210
+ - `(t₁.*f)(t₂, , t_N)` when `f` is a pointer to a member function of a
211
+ class `T` and `is_base_of_v<T, remove_reference_t<decltype(t₁)>>` is
212
+ `true`;
213
+ - `(t₁.get().*f)(t₂, …, t_N)` when `f` is a pointer to a member function
214
+ of a class `T` and `remove_cvref_t<decltype(t₁)>` is a specialization
215
+ of `reference_wrapper`;
216
+ - `((*t₁).*f)(t₂, …, t_N)` when `f` is a pointer to a member function of
217
+ a class `T` and `t₁` does not satisfy the previous two items;
218
+ - `t₁.*f` when `N == 1` and `f` is a pointer to data member of a class
219
+ `T` and `is_base_of_v<T, remove_reference_t<decltype(t₁)>>` is `true`;
220
+ - `t₁.get().*f` when `N == 1` and `f` is a pointer to data member of a
221
+ class `T` and `remove_cvref_t<decltype(t₁)>` is a specialization of
222
  `reference_wrapper`;
223
+ - `(*t₁).*f` when `N == 1` and `f` is a pointer to data member of a
224
+ class `T` and `t₁` does not satisfy the previous two items;
225
+ - `f(t₁, t₂, , t_N)` in all other cases.
226
 
227
+ Define `INVOKE<R>(f, t₁, t₂, , t_N)` as
228
+ `static_cast<void>(INVOKE(f, t₁, t₂, , t_N))` if `R` is cv `void`,
229
+ otherwise `INVOKE(f, t₁, t₂, , t_N)` implicitly converted to `R`.
230
 
231
+ Every call wrapper [[func.def]] meets the *Cpp17MoveConstructible* and
232
+ *Cpp17Destructible* requirements. An *argument forwarding call wrapper*
233
+ is a call wrapper that can be called with an arbitrary argument list and
234
+ delivers the arguments to the wrapped callable object as references.
235
+ This forwarding step delivers rvalue arguments as rvalue references and
236
+ lvalue arguments as lvalue references.
 
 
 
237
 
238
  [*Note 1*:
239
 
240
+ In a typical implementation, argument forwarding call wrappers have an
241
+ overloaded function call operator of the form
242
 
243
  ``` cpp
244
  template<class... UnBoundArgs>
245
+ constexpr R operator()(UnBoundArgs&&... unbound_args) cv-qual;
246
  ```
247
 
248
  — *end note*]
249
 
250
+ A *perfect forwarding call wrapper* is an argument forwarding call
251
+ wrapper that forwards its state entities to the underlying call
252
+ expression. This forwarding step delivers a state entity of type `T` as
253
+ cv `T&` when the call is performed on an lvalue of the call wrapper type
254
+ and as cv `T&&` otherwise, where cv represents the cv-qualifiers of the
255
+ call wrapper and where cv shall be neither `volatile` nor
256
+ `const volatile`.
257
+
258
+ A *call pattern* defines the semantics of invoking a perfect forwarding
259
+ call wrapper. A postfix call performed on a perfect forwarding call
260
+ wrapper is expression-equivalent [[defns.expression-equivalent]] to an
261
+ expression `e` determined from its call pattern `cp` by replacing all
262
+ occurrences of the arguments of the call wrapper and its state entities
263
+ with references as described in the corresponding forwarding steps.
264
+
265
+ A *simple call wrapper* is a perfect forwarding call wrapper that meets
266
+ the *Cpp17CopyConstructible* and *Cpp17CopyAssignable* requirements and
267
+ whose copy constructor, move constructor, and assignment operators are
268
+ constexpr functions that do not throw exceptions.
269
+
270
+ The copy/move constructor of an argument forwarding call wrapper has the
271
+ same apparent semantics as if memberwise copy/move of its state entities
272
+ were performed [[class.copy.ctor]].
273
+
274
+ [*Note 2*: This implies that each of the copy/move constructors has the
275
+ same exception-specification as the corresponding implicit definition
276
+ and is declared as `constexpr` if the corresponding implicit definition
277
+ would be considered to be constexpr. — *end note*]
278
+
279
+ Argument forwarding call wrappers returned by a given standard library
280
+ function template have the same type if the types of their corresponding
281
+ state entities are the same.
282
+
283
  ### Function template `invoke` <a id="func.invoke">[[func.invoke]]</a>
284
 
285
  ``` cpp
286
  template<class F, class... Args>
287
+ constexpr invoke_result_t<F, Args...> invoke(F&& f, Args&&... args)
288
  noexcept(is_nothrow_invocable_v<F, Args...>);
289
  ```
290
 
291
  *Returns:* *INVOKE*(std::forward\<F\>(f),
292
+ std::forward\<Args\>(args)...) [[func.require]].
293
 
294
  ### Class template `reference_wrapper` <a id="refwrap">[[refwrap]]</a>
295
 
296
  ``` cpp
297
  namespace std {
 
299
  public:
300
  // types
301
  using type = T;
302
 
303
  // construct/copy/destroy
304
+ template<class U>
305
+ constexpr reference_wrapper(U&&) noexcept(see below);
306
+ constexpr reference_wrapper(const reference_wrapper& x) noexcept;
307
 
308
  // assignment
309
+ constexpr reference_wrapper& operator=(const reference_wrapper& x) noexcept;
310
 
311
  // access
312
+ constexpr operator T& () const noexcept;
313
+ constexpr T& get() const noexcept;
314
 
315
  // invocation
316
  template<class... ArgTypes>
317
+ constexpr invoke_result_t<T&, ArgTypes...> operator()(ArgTypes&&...) const;
 
318
  };
 
319
  template<class T>
320
+ reference_wrapper(T&) -> reference_wrapper<T>;
321
  }
322
  ```
323
 
324
+ `reference_wrapper<T>` is a *Cpp17CopyConstructible* and
325
+ *Cpp17CopyAssignable* wrapper around a reference to an object or
326
+ function of type `T`.
327
 
328
+ `reference_wrapper<T>` is a trivially copyable type [[basic.types]].
 
329
 
330
+ The template parameter `T` of `reference_wrapper` may be an incomplete
331
+ type.
332
+
333
+ #### Constructors and destructor <a id="refwrap.const">[[refwrap.const]]</a>
334
 
335
  ``` cpp
336
+ template<class U>
337
+ constexpr reference_wrapper(U&& u) noexcept(see below);
338
  ```
339
 
340
+ Let *FUN* denote the exposition-only functions
341
+
342
+ ``` cpp
343
+ void FUN(T&) noexcept;
344
+ void FUN(T&&) = delete;
345
+ ```
346
+
347
+ *Constraints:* The expression *FUN*(declval\<U\>()) is well-formed and
348
+ `is_same_v<remove_cvref_t<U>, reference_wrapper>` is `false`.
349
+
350
+ *Effects:* Creates a variable `r` as if by `T& r = std::forward<U>(u)`,
351
+ then constructs a `reference_wrapper` object that stores a reference to
352
+ `r`.
353
+
354
+ *Remarks:* The expression inside `noexcept` is equivalent to
355
+ `noexcept(`*`FUN`*`(declval<U>()))`.
356
 
357
  ``` cpp
358
+ constexpr reference_wrapper(const reference_wrapper& x) noexcept;
359
  ```
360
 
361
  *Effects:* Constructs a `reference_wrapper` object that stores a
362
  reference to `x.get()`.
363
 
364
+ #### Assignment <a id="refwrap.assign">[[refwrap.assign]]</a>
365
 
366
  ``` cpp
367
+ constexpr reference_wrapper& operator=(const reference_wrapper& x) noexcept;
368
  ```
369
 
370
+ *Ensures:* `*this` stores a reference to `x.get()`.
371
 
372
+ #### Access <a id="refwrap.access">[[refwrap.access]]</a>
373
 
374
  ``` cpp
375
+ constexpr operator T& () const noexcept;
376
  ```
377
 
378
  *Returns:* The stored reference.
379
 
380
  ``` cpp
381
+ constexpr T& get() const noexcept;
382
  ```
383
 
384
  *Returns:* The stored reference.
385
 
386
+ #### Invocation <a id="refwrap.invoke">[[refwrap.invoke]]</a>
387
 
388
  ``` cpp
389
  template<class... ArgTypes>
390
+ constexpr invoke_result_t<T&, ArgTypes...>
391
  operator()(ArgTypes&&... args) const;
392
  ```
393
 
394
+ *Mandates:* `T` is a complete type.
395
+
396
  *Returns:* *INVOKE*(get(),
397
+ std::forward\<ArgTypes\>(args)...). [[func.require]]
398
 
399
+ #### Helper functions <a id="refwrap.helpers">[[refwrap.helpers]]</a>
400
+
401
+ The template parameter `T` of the following `ref` and `cref` function
402
+ templates may be an incomplete type.
403
 
404
  ``` cpp
405
+ template<class T> constexpr reference_wrapper<T> ref(T& t) noexcept;
406
  ```
407
 
408
  *Returns:* `reference_wrapper<T>(t)`.
409
 
410
  ``` cpp
411
+ template<class T> constexpr reference_wrapper<T> ref(reference_wrapper<T> t) noexcept;
412
  ```
413
 
414
  *Returns:* `ref(t.get())`.
415
 
416
  ``` cpp
417
+ template<class T> constexpr reference_wrapper<const T> cref(const T& t) noexcept;
418
  ```
419
 
420
  *Returns:* `reference_wrapper <const T>(t)`.
421
 
422
  ``` cpp
423
+ template<class T> constexpr reference_wrapper<const T> cref(reference_wrapper<T> t) noexcept;
424
  ```
425
 
426
  *Returns:* `cref(t.get())`.
427
 
428
  ### Arithmetic operations <a id="arithmetic.operations">[[arithmetic.operations]]</a>
 
614
 
615
  The library provides basic function object classes for all of the
616
  comparison operators in the language ([[expr.rel]], [[expr.eq]]).
617
 
618
  For templates `less`, `greater`, `less_equal`, and `greater_equal`, the
619
+ specializations for any pointer type yield a result consistent with the
620
+ implementation-defined strict total order over pointers
621
+ [[defns.order.ptr]].
622
 
623
+ [*Note 1*: If `a < b` is well-defined for pointers `a` and `b` of type
624
+ `P`, then `(a < b) == less<P>()(a, b)`, `(a > b) == greater<P>()(a, b)`,
625
+ and so forth. — *end note*]
626
 
627
  For template specializations `less<void>`, `greater<void>`,
628
  `less_equal<void>`, and `greater_equal<void>`, if the call operator
629
  calls a built-in operator comparing pointers, the call operator yields a
630
+ result consistent with the implementation-defined strict total order
631
+ over pointers.
 
632
 
633
+ #### Class template `equal_to` <a id="comparisons.equal.to">[[comparisons.equal.to]]</a>
634
 
635
  ``` cpp
636
  template<class T = void> struct equal_to {
637
  constexpr bool operator()(const T& x, const T& y) const;
638
  };
 
658
  -> decltype(std::forward<T>(t) == std::forward<U>(u));
659
  ```
660
 
661
  *Returns:* `std::forward<T>(t) == std::forward<U>(u)`.
662
 
663
+ #### Class template `not_equal_to` <a id="comparisons.not.equal.to">[[comparisons.not.equal.to]]</a>
664
 
665
  ``` cpp
666
  template<class T = void> struct not_equal_to {
667
  constexpr bool operator()(const T& x, const T& y) const;
668
  };
 
748
  -> decltype(std::forward<T>(t) < std::forward<U>(u));
749
  ```
750
 
751
  *Returns:* `std::forward<T>(t) < std::forward<U>(u)`.
752
 
753
+ #### Class template `greater_equal` <a id="comparisons.greater.equal">[[comparisons.greater.equal]]</a>
754
 
755
  ``` cpp
756
  template<class T = void> struct greater_equal {
757
  constexpr bool operator()(const T& x, const T& y) const;
758
  };
 
778
  -> decltype(std::forward<T>(t) >= std::forward<U>(u));
779
  ```
780
 
781
  *Returns:* `std::forward<T>(t) >= std::forward<U>(u)`.
782
 
783
+ #### Class template `less_equal` <a id="comparisons.less.equal">[[comparisons.less.equal]]</a>
784
 
785
  ``` cpp
786
  template<class T = void> struct less_equal {
787
  constexpr bool operator()(const T& x, const T& y) const;
788
  };
 
808
  -> decltype(std::forward<T>(t) <= std::forward<U>(u));
809
  ```
810
 
811
  *Returns:* `std::forward<T>(t) <= std::forward<U>(u)`.
812
 
813
+ #### Class `compare_three_way` <a id="comparisons.three.way">[[comparisons.three.way]]</a>
814
+
815
+ In this subclause, `BUILTIN-PTR-THREE-WAY(T, U)` for types `T` and `U`
816
+ is a boolean constant expression. `BUILTIN-PTR-THREE-WAY(T, U)` is
817
+ `true` if and only if `<=>` in the expression
818
+
819
+ ``` cpp
820
+ declval<T>() <=> declval<U>()
821
+ ```
822
+
823
+ resolves to a built-in operator comparing pointers.
824
+
825
+ ``` cpp
826
+ struct compare_three_way {
827
+ template<class T, class U>
828
+ requires three_way_comparable_with<T, U> || BUILTIN-PTR-THREE-WAY(T, U)
829
+ constexpr auto operator()(T&& t, U&& u) const;
830
+
831
+ using is_transparent = unspecified;
832
+ };
833
+ ```
834
+
835
+ ``` cpp
836
+ template<class T, class U>
837
+ requires three_way_comparable_with<T, U> || BUILTIN-PTR-THREE-WAY(T, U)
838
+ constexpr auto operator()(T&& t, U&& u) const;
839
+ ```
840
+
841
+ *Preconditions:* If the expression
842
+ `std::forward<T>(t) <=> std::forward<U>(u)` results in a call to a
843
+ built-in operator `<=>` comparing pointers of type `P`, the conversion
844
+ sequences from both `T` and `U` to `P` are
845
+ equality-preserving [[concepts.equality]].
846
+
847
+ *Effects:*
848
+
849
+ - If the expression `std::forward<T>(t) <=> std::forward<U>(u)` results
850
+ in a call to a built-in operator `<=>` comparing pointers of type `P`,
851
+ returns `strong_ordering::less` if (the converted value of) `t`
852
+ precedes `u` in the implementation-defined strict total order over
853
+ pointers [[defns.order.ptr]], `strong_ordering::greater` if `u`
854
+ precedes `t`, and otherwise `strong_ordering::equal`.
855
+ - Otherwise, equivalent to:
856
+ `return std::forward<T>(t) <=> std::forward<U>(u);`
857
+
858
+ ### Concept-constrained comparisons <a id="range.cmp">[[range.cmp]]</a>
859
+
860
+ In this subclause, `BUILTIN-PTR-CMP(T, op, U)` for types `T` and `U` and
861
+ where op is an equality [[expr.eq]] or relational operator [[expr.rel]]
862
+ is a boolean constant expression. `BUILTIN-PTR-CMP(T, op, U)` is `true`
863
+ if and only if op in the expression `declval<T>() op declval<U>()`
864
+ resolves to a built-in operator comparing pointers.
865
+
866
+ ``` cpp
867
+ struct ranges::equal_to {
868
+ template<class T, class U>
869
+ requires equality_comparable_with<T, U> || BUILTIN-PTR-CMP(T, ==, U)
870
+ constexpr bool operator()(T&& t, U&& u) const;
871
+
872
+ using is_transparent = unspecified;
873
+ };
874
+ ```
875
+
876
+ *Preconditions:* If the expression
877
+ `std::forward<T>(t) == std::forward<U>(u)` results in a call to a
878
+ built-in operator `==` comparing pointers of type `P`, the conversion
879
+ sequences from both `T` and `U` to `P` are
880
+ equality-preserving [[concepts.equality]].
881
+
882
+ *Effects:*
883
+
884
+ - If the expression `std::forward<T>(t) == std::forward<U>(u)` results
885
+ in a call to a built-in operator `==` comparing pointers: returns
886
+ `false` if either (the converted value of) `t` precedes `u` or `u`
887
+ precedes `t` in the implementation-defined strict total order over
888
+ pointers [[defns.order.ptr]] and otherwise `true`.
889
+ - Otherwise, equivalent to:
890
+ `return std::forward<T>(t) == std::forward<U>(u);`
891
+
892
+ ``` cpp
893
+ struct ranges::not_equal_to {
894
+ template<class T, class U>
895
+ requires equality_comparable_with<T, U> || BUILTIN-PTR-CMP(T, ==, U)
896
+ constexpr bool operator()(T&& t, U&& u) const;
897
+
898
+ using is_transparent = unspecified;
899
+ };
900
+ ```
901
+
902
+ `operator()` has effects equivalent to:
903
+
904
+ ``` cpp
905
+ return !ranges::equal_to{}(std::forward<T>(t), std::forward<U>(u));
906
+ ```
907
+
908
+ ``` cpp
909
+ struct ranges::greater {
910
+ template<class T, class U>
911
+ requires totally_ordered_with<T, U> || BUILTIN-PTR-CMP(U, <, T)
912
+ constexpr bool operator()(T&& t, U&& u) const;
913
+
914
+ using is_transparent = unspecified;
915
+ };
916
+ ```
917
+
918
+ `operator()` has effects equivalent to:
919
+
920
+ ``` cpp
921
+ return ranges::less{}(std::forward<U>(u), std::forward<T>(t));
922
+ ```
923
+
924
+ ``` cpp
925
+ struct ranges::less {
926
+ template<class T, class U>
927
+ requires totally_ordered_with<T, U> || BUILTIN-PTR-CMP(T, <, U)
928
+ constexpr bool operator()(T&& t, U&& u) const;
929
+
930
+ using is_transparent = unspecified;
931
+ };
932
+ ```
933
+
934
+ *Preconditions:* If the expression
935
+ `std::forward<T>(t) < std::forward<U>(u)` results in a call to a
936
+ built-in operator `<` comparing pointers of type `P`, the conversion
937
+ sequences from both `T` and `U` to `P` are
938
+ equality-preserving [[concepts.equality]]. For any expressions `ET` and
939
+ `EU` such that `decltype((ET))` is `T` and `decltype((EU))` is `U`,
940
+ exactly one of `ranges::less{}(ET, EU)`, `ranges::less{}(EU, ET)`, or
941
+ `ranges::equal_to{}(ET, EU)` is `true`.
942
+
943
+ *Effects:*
944
+
945
+ - If the expression `std::forward<T>(t) < std::forward<U>(u)` results in
946
+ a call to a built-in operator `<` comparing pointers: returns `true`
947
+ if (the converted value of) `t` precedes `u` in the
948
+ implementation-defined strict total order over
949
+ pointers [[defns.order.ptr]] and otherwise `false`.
950
+ - Otherwise, equivalent to:
951
+ `return std::forward<T>(t) < std::forward<U>(u);`
952
+
953
+ ``` cpp
954
+ struct ranges::greater_equal {
955
+ template<class T, class U>
956
+ requires totally_ordered_with<T, U> || BUILTIN-PTR-CMP(T, <, U)
957
+ constexpr bool operator()(T&& t, U&& u) const;
958
+
959
+ using is_transparent = unspecified;
960
+ };
961
+ ```
962
+
963
+ `operator()` has effects equivalent to:
964
+
965
+ ``` cpp
966
+ return !ranges::less{}(std::forward<T>(t), std::forward<U>(u));
967
+ ```
968
+
969
+ ``` cpp
970
+ struct ranges::less_equal {
971
+ template<class T, class U>
972
+ requires totally_ordered_with<T, U> || BUILTIN-PTR-CMP(U, <, T)
973
+ constexpr bool operator()(T&& t, U&& u) const;
974
+
975
+ using is_transparent = unspecified;
976
+ };
977
+ ```
978
+
979
+ `operator()` has effects equivalent to:
980
+
981
+ ``` cpp
982
+ return !ranges::less{}(std::forward<U>(u), std::forward<T>(t));
983
+ ```
984
+
985
  ### Logical operations <a id="logical.operations">[[logical.operations]]</a>
986
 
987
  The library provides basic function object classes for all of the
988
  logical operators in the language ([[expr.log.and]], [[expr.log.or]],
989
  [[expr.unary.op]]).
 
1202
  -> decltype(~std::forward<T>(t));
1203
  ```
1204
 
1205
  *Returns:* `~std::forward<T>(t)`.
1206
 
1207
+ ### Class `identity` <a id="func.identity">[[func.identity]]</a>
1208
 
1209
  ``` cpp
1210
+ struct identity {
1211
+ template<class T>
1212
+ constexpr T&& operator()(T&& t) const noexcept;
1213
 
1214
+ using is_transparent = unspecified;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1215
  };
1216
+
1217
+ template<class T>
1218
+ constexpr T&& operator()(T&& t) const noexcept;
1219
  ```
1220
 
1221
+ *Effects:* Equivalent to: `return std::forward<T>(t);`
1222
+
1223
+ ### Function template `not_fn` <a id="func.not.fn">[[func.not.fn]]</a>
1224
+
1225
  ``` cpp
1226
+ template<class F> constexpr unspecified not_fn(F&& f);
1227
  ```
1228
 
1229
+ In the text that follows:
 
 
1230
 
1231
+ - `g` is a value of the result of a `not_fn` invocation,
1232
+ - `FD` is the type `decay_t<F>`,
1233
+ - `fd` is the target object of `g` [[func.def]] of type `FD`,
1234
+ direct-non-list-initialized with `std::forward<F>(f)`,
1235
+ - `call_args` is an argument pack used in a function call
1236
+ expression [[expr.call]] of `g`.
1237
 
1238
+ *Mandates:* `is_constructible_v<FD, F> && is_move_constructible_v<FD>`
1239
+ is `true`.
1240
 
1241
+ *Preconditions:* `FD` meets the *Cpp17MoveConstructible* requirements.
 
 
 
 
 
 
 
1242
 
1243
+ *Returns:* A perfect forwarding call wrapper `g` with call pattern
1244
+ `!invoke(fd, call_args...)`.
1245
 
1246
+ *Throws:* Any exception thrown by the initialization of `fd`.
1247
+
1248
+ ### Function template `bind_front` <a id="func.bind.front">[[func.bind.front]]</a>
1249
 
1250
  ``` cpp
1251
+ template<class F, class... Args>
1252
+ constexpr unspecified bind_front(F&& f, Args&&... args);
 
 
 
 
1253
  ```
1254
 
1255
+ In the text that follows:
1256
+
1257
+ - `g` is a value of the result of a `bind_front` invocation,
1258
+ - `FD` is the type `decay_t<F>`,
1259
+ - `fd` is the target object of `g` [[func.def]] of type `FD`,
1260
+ direct-non-list-initialized with `std::forward<F>(f)`,
1261
+ - `BoundArgs` is a pack that denotes `decay_t<Args>...`,
1262
+ - `bound_args` is a pack of bound argument entities of `g` [[func.def]]
1263
+ of types `BoundArgs...`, direct-non-list-initialized with
1264
+ `std::forward<Args>(args)...`, respectively, and
1265
+ - `call_args` is an argument pack used in a function call
1266
+ expression [[expr.call]] of `g`.
1267
+
1268
+ *Mandates:*
1269
 
1270
  ``` cpp
1271
+ is_constructible_v<FD, F> &&
1272
+ is_move_constructible_v<FD> &&
1273
+ (is_constructible_v<BoundArgs, Args> && ...) &&
1274
+ (is_move_constructible_v<BoundArgs> && ...)
1275
  ```
1276
 
1277
+ is `true`.
1278
+
1279
+ *Preconditions:* `FD` meets the *Cpp17MoveConstructible* requirements.
1280
+ For each `Tᵢ` in `BoundArgs`, if `Tᵢ` is an object type, `Tᵢ` meets the
1281
+ *Cpp17MoveConstructible* requirements.
1282
+
1283
+ *Returns:* A perfect forwarding call wrapper `g` with call pattern
1284
+ `invoke(fd, bound_args..., call_args...)`.
1285
+
1286
+ *Throws:* Any exception thrown by the initialization of the state
1287
+ entities of `g` [[func.def]].
1288
+
1289
  ### Function object binders <a id="func.bind">[[func.bind]]</a>
1290
 
1291
  This subclause describes a uniform mechanism for binding arguments of
1292
  callable objects.
1293
 
 
1301
 
1302
  The class template `is_bind_expression` can be used to detect function
1303
  objects generated by `bind`. The function template `bind` uses
1304
  `is_bind_expression` to detect subexpressions.
1305
 
1306
+ Specializations of the `is_bind_expression` template shall meet the
1307
+ *Cpp17UnaryTypeTrait* requirements [[meta.rqmts]]. The implementation
1308
+ provides a definition that has a base characteristic of `true_type` if
1309
+ `T` is a type returned from `bind`, otherwise it has a base
1310
  characteristic of `false_type`. A program may specialize this template
1311
+ for a program-defined type `T` to have a base characteristic of
1312
+ `true_type` to indicate that `T` should be treated as a subexpression in
1313
+ a `bind` call.
1314
 
1315
  #### Class template `is_placeholder` <a id="func.bind.isplace">[[func.bind.isplace]]</a>
1316
 
1317
  ``` cpp
1318
  namespace std {
 
1322
 
1323
  The class template `is_placeholder` can be used to detect the standard
1324
  placeholders `_1`, `_2`, and so on. The function template `bind` uses
1325
  `is_placeholder` to detect placeholders.
1326
 
1327
+ Specializations of the `is_placeholder` template shall meet the
1328
+ *Cpp17UnaryTypeTrait* requirements [[meta.rqmts]]. The implementation
1329
+ provides a definition that has the base characteristic of
1330
  `integral_constant<int, J>` if `T` is the type of
1331
+ `std::placeholders::_J`, otherwise it has a base characteristic of
1332
+ `integral_constant<int, 0>`. A program may specialize this template for
1333
+ a program-defined type `T` to have a base characteristic of
1334
  `integral_constant<int, N>` with `N > 0` to indicate that `T` should be
1335
  treated as a placeholder type.
1336
 
1337
  #### Function template `bind` <a id="func.bind.bind">[[func.bind.bind]]</a>
1338
 
1339
  In the text that follows:
1340
 
1341
+ - `g` is a value of the result of a `bind` invocation,
1342
  - `FD` is the type `decay_t<F>`,
1343
+ - `fd` is an lvalue that is a target object of `g` [[func.def]] of type
1344
+ `FD` direct-non-list-initialized with `std::forward<F>(f)`,
1345
  - `Tᵢ` is the iᵗʰ type in the template parameter pack `BoundArgs`,
1346
  - `TDᵢ` is the type `decay_t<Tᵢ>`,
1347
  - `tᵢ` is the iᵗʰ argument in the function parameter pack `bound_args`,
1348
+ - `tdᵢ` is a bound argument entity of `g` [[func.def]] of type `TDᵢ`
1349
+ direct-non-list-initialized with `std::forward<{}Tᵢ>(tᵢ)`,
1350
  - `Uⱼ` is the jᵗʰ deduced type of the `UnBoundArgs&&...` parameter of
1351
+ the argument forwarding call wrapper, and
1352
  - `uⱼ` is the jᵗʰ argument associated with `Uⱼ`.
1353
 
1354
  ``` cpp
1355
  template<class F, class... BoundArgs>
1356
+ constexpr unspecified bind(F&& f, BoundArgs&&... bound_args);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1357
  template<class R, class F, class... BoundArgs>
1358
+ constexpr unspecified bind(F&& f, BoundArgs&&... bound_args);
1359
  ```
1360
 
1361
+ *Mandates:* `is_constructible_v<FD, F>` is `true`. For each `Tᵢ` in
1362
+ `BoundArgs`, `is_constructible_v<``TDᵢ``, ``Tᵢ``>` is `true`.
 
 
 
 
1363
 
1364
+ *Preconditions:* `FD` and each `TDᵢ` meet the *Cpp17MoveConstructible*
1365
+ and *Cpp17Destructible* requirements. *INVOKE*(fd, w₁, w₂, …,
1366
+ $w_N$) [[func.require]] is a valid expression for some values `w₁`,
1367
+ `w₂`, …, `w_N`, where N has the value `sizeof...(bound_args)`.
1368
+
1369
+ *Returns:* An argument forwarding call wrapper `g` [[func.require]]. A
1370
+ program that attempts to invoke a volatile-qualified `g` is ill-formed.
1371
+ When `g` is not volatile-qualified, invocation of
1372
+ `g(``u₁``, ``u₂``, `…`, ``u_M``)` is
1373
+ expression-equivalent [[defns.expression-equivalent]] to
1374
 
1375
  ``` cpp
1376
+ INVOKE(static_cast<$V_fd$>($v_fd$),
1377
+ static_cast<$V_1$>($v_1$), static_cast<$V_2$>($v_2$), …, static_cast<$V_N$>($v_N$))
1378
  ```
1379
 
1380
+ for the first overload, and
1381
+
1382
+ ``` cpp
1383
+ INVOKE<R>(static_cast<$V_fd$>($v_fd$),
1384
+ static_cast<$V_1$>($v_1$), static_cast<$V_2$>($v_2$), …, static_cast<$V_N$>($v_N$))
1385
+ ```
1386
 
1387
+ for the second overload, where the values and types of the target
1388
+ argument `v`_`fd` and of the bound arguments `v₁`, `v₂`, …, `v_N` are
1389
+ determined as specified below.
1390
 
1391
+ *Throws:* Any exception thrown by the initialization of the state
1392
+ entities of `g`.
 
 
1393
 
1394
+ [*Note 1*: If all of `FD` and `TDᵢ` meet the requirements of
1395
+ *Cpp17CopyConstructible*, then the return type meets the requirements of
1396
+ *Cpp17CopyConstructible*. — *end note*]
1397
 
1398
  The values of the *bound arguments* `v₁`, `v₂`, …, `v_N` and their
1399
  corresponding types `V₁`, `V₂`, …, `V_N` depend on the types `TDᵢ`
1400
  derived from the call to `bind` and the cv-qualifiers cv of the call
1401
  wrapper `g` as follows:
1402
 
1403
  - if `TDᵢ` is `reference_wrapper<T>`, the argument is `tdᵢ.get()` and
1404
  its type `Vᵢ` is `T&`;
1405
  - if the value of `is_bind_expression_v<TDᵢ>` is `true`, the argument is
1406
+ ``` cpp
1407
+ static_cast<cv `TD`_i&>(td_i)(std::forward<U_j>(u_j)...)
1408
+ ```
1409
+
1410
+ and its type `Vᵢ` is `invoke_result_t<cv TDᵢ&, Uⱼ...>&&`;
1411
  - if the value `j` of `is_placeholder_v<TDᵢ>` is not zero, the argument
1412
  is `std::forward<Uⱼ>(uⱼ)` and its type `Vᵢ` is `Uⱼ&&`;
1413
+ - otherwise, the value is `tdᵢ` and its type `Vᵢ` is `cv TDᵢ&`.
1414
+
1415
+ The value of the target argument `v`_`fd` is `fd` and its corresponding
1416
+ type `V`_`fd` is `cv FD&`.
1417
 
1418
  #### Placeholders <a id="func.bind.place">[[func.bind.place]]</a>
1419
 
1420
  ``` cpp
1421
  namespace std::placeholders {
 
1427
  .
1428
  see below _M;
1429
  }
1430
  ```
1431
 
1432
+ All placeholder types meet the *Cpp17DefaultConstructible* and
1433
+ *Cpp17CopyConstructible* requirements, and their default constructors
1434
+ and copy/move constructors are constexpr functions that do not throw
1435
+ exceptions. It is *implementation-defined* whether placeholder types
1436
+ meet the *Cpp17CopyAssignable* requirements, but if so, their copy
1437
+ assignment operators are constexpr functions that do not throw
1438
+ exceptions.
1439
 
1440
  Placeholders should be defined as:
1441
 
1442
  ``` cpp
1443
  inline constexpr unspecified _1{};
1444
  ```
1445
 
1446
+ If they are not, they are declared as:
1447
 
1448
  ``` cpp
1449
  extern unspecified _1;
1450
  ```
1451
 
1452
  ### Function template `mem_fn` <a id="func.memfn">[[func.memfn]]</a>
1453
 
1454
  ``` cpp
1455
+ template<class R, class T> constexpr unspecified mem_fn(R T::* pm) noexcept;
1456
  ```
1457
 
1458
+ *Returns:* A simple call wrapper [[func.def]] `fn` with call pattern
1459
+ `invoke(pmd, call_args...)`, where `pmd` is the target object of `fn` of
1460
+ type `R T::*` direct-non-list-initialized with `pm`, and `call_args` is
1461
+ an argument pack used in a function call expression [[expr.call]] of
1462
+ `pm`.
1463
 
1464
  ### Polymorphic function wrappers <a id="func.wrap">[[func.wrap]]</a>
1465
 
1466
  This subclause describes a polymorphic wrapper class that encapsulates
1467
  arbitrary callable objects.
1468
 
1469
  #### Class `bad_function_call` <a id="func.wrap.badcall">[[func.wrap.badcall]]</a>
1470
 
1471
  An exception of type `bad_function_call` is thrown by
1472
+ `function::operator()` [[func.wrap.func.inv]] when the function wrapper
1473
+ object has no target.
1474
 
1475
  ``` cpp
1476
  namespace std {
1477
  class bad_function_call : public exception {
1478
  public:
1479
+ // see [exception] for the specification of the special member functions
1480
+ const char* what() const noexcept override;
1481
  };
1482
  }
1483
  ```
1484
 
 
 
1485
  ``` cpp
1486
+ const char* what() const noexcept override;
1487
  ```
1488
 
1489
+ *Returns:* An *implementation-defined* NTBS.
 
 
1490
 
1491
  #### Class template `function` <a id="func.wrap.func">[[func.wrap.func]]</a>
1492
 
1493
  ``` cpp
1494
  namespace std {
 
1501
 
1502
  // [func.wrap.func.con], construct/copy/destroy
1503
  function() noexcept;
1504
  function(nullptr_t) noexcept;
1505
  function(const function&);
1506
+ function(function&&) noexcept;
1507
  template<class F> function(F);
1508
 
1509
  function& operator=(const function&);
1510
  function& operator=(function&&);
1511
  function& operator=(nullptr_t) noexcept;
 
1532
  template<class R, class... ArgTypes>
1533
  function(R(*)(ArgTypes...)) -> function<R(ArgTypes...)>;
1534
 
1535
  template<class F> function(F) -> function<see below>;
1536
 
1537
+ // [func.wrap.func.nullptr], null pointer comparison functions
1538
  template<class R, class... ArgTypes>
1539
  bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
1540
 
 
 
 
 
 
 
 
 
 
1541
  // [func.wrap.func.alg], specialized algorithms
1542
  template<class R, class... ArgTypes>
1543
  void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&) noexcept;
1544
  }
1545
  ```
1546
 
1547
  The `function` class template provides polymorphic wrappers that
1548
  generalize the notion of a function pointer. Wrappers can store, copy,
1549
+ and call arbitrary callable objects [[func.def]], given a call signature
1550
+ [[func.def]], allowing functions to be first-class objects.
1551
 
1552
+ A callable type [[func.def]] `F` is *Lvalue-Callable* for argument types
1553
+ `ArgTypes` and return type `R` if the expression
1554
  `INVOKE<R>(declval<F&>(), declval<ArgTypes>()...)`, considered as an
1555
+ unevaluated operand [[expr.prop]], is well-formed [[func.require]].
 
1556
 
1557
+ The `function` class template is a call wrapper [[func.def]] whose call
1558
+ signature [[func.def]] is `R(ArgTypes...)`.
1559
 
1560
  [*Note 1*: The types deduced by the deduction guides for `function` may
1561
  change in future versions of this International Standard. — *end note*]
1562
 
1563
+ ##### Constructors and destructor <a id="func.wrap.func.con">[[func.wrap.func.con]]</a>
1564
 
1565
  ``` cpp
1566
  function() noexcept;
1567
  ```
1568
 
1569
+ *Ensures:* `!*this`.
1570
 
1571
  ``` cpp
1572
  function(nullptr_t) noexcept;
1573
  ```
1574
 
1575
+ *Ensures:* `!*this`.
1576
 
1577
  ``` cpp
1578
  function(const function& f);
1579
  ```
1580
 
1581
+ *Ensures:* `!*this` if `!f`; otherwise, `*this` targets a copy of
1582
  `f.target()`.
1583
 
1584
+ *Throws:* Nothing if `f`’s target is a specialization of
1585
+ `reference_wrapper` or a function pointer. Otherwise, may throw
1586
  `bad_alloc` or any exception thrown by the copy constructor of the
1587
  stored callable object.
1588
 
1589
+ [*Note 1*: Implementations should avoid the use of dynamically
1590
+ allocated memory for small callable objects, for example, where `f`’s
1591
+ target is an object holding only a pointer or reference to an object and
1592
+ a member function pointer. — *end note*]
1593
 
1594
  ``` cpp
1595
+ function(function&& f) noexcept;
1596
  ```
1597
 
1598
+ *Ensures:* If `!f`, `*this` has no target; otherwise, the target of
1599
+ `*this` is equivalent to the target of `f` before the construction, and
1600
+ `f` is in a valid state with an unspecified value.
1601
 
1602
+ [*Note 2*: Implementations should avoid the use of dynamically
1603
+ allocated memory for small callable objects, for example, where `f`’s
1604
+ target is an object holding only a pointer or reference to an object and
1605
+ a member function pointer. — *end note*]
 
 
 
 
 
1606
 
1607
  ``` cpp
1608
  template<class F> function(F f);
1609
  ```
1610
 
1611
+ *Constraints:* `F` is Lvalue-Callable [[func.wrap.func]] for argument
1612
+ types `ArgTypes...` and return type `R`.
1613
 
1614
+ *Preconditions:* `F` meets the *Cpp17CopyConstructible* requirements.
 
 
1615
 
1616
+ *Ensures:* `!*this` if any of the following hold:
1617
 
1618
  - `f` is a null function pointer value.
1619
  - `f` is a null member pointer value.
1620
  - `F` is an instance of the `function` class template, and `!f`.
1621
 
1622
  Otherwise, `*this` targets a copy of `f` initialized with
1623
  `std::move(f)`.
1624
 
1625
+ [*Note 3*: Implementations should avoid the use of dynamically
1626
+ allocated memory for small callable objects, for example, where `f` is
1627
+ an object holding only a pointer or reference to an object and a member
1628
+ function pointer. — *end note*]
1629
 
1630
+ *Throws:* Nothing if `f` is a specialization of `reference_wrapper` or a
1631
+ function pointer. Otherwise, may throw `bad_alloc` or any exception
1632
+ thrown by `F`’s copy or move constructor.
1633
 
1634
  ``` cpp
1635
  template<class F> function(F) -> function<see below>;
1636
  ```
1637
 
1638
+ *Constraints:* `&F::operator()` is well-formed when treated as an
1639
+ unevaluated operand and `decltype(&F::operator())` is of the form
1640
+ `R(G::*)(A...)` cv \\ₒₚₜ ` `noexceptₒₚₜ for a class type `G`.
1641
+
1642
+ *Remarks:* The deduced type is `function<R(A...)>`.
1643
 
1644
  [*Example 1*:
1645
 
1646
  ``` cpp
1647
  void f() {
 
1672
  function& operator=(nullptr_t) noexcept;
1673
  ```
1674
 
1675
  *Effects:* If `*this != nullptr`, destroys the target of `this`.
1676
 
1677
+ *Ensures:* `!(*this)`.
1678
 
1679
  *Returns:* `*this`.
1680
 
1681
  ``` cpp
1682
  template<class F> function& operator=(F&& f);
1683
  ```
1684
 
1685
+ *Constraints:* `decay_t<F>` is Lvalue-Callable [[func.wrap.func]] for
1686
+ argument types `ArgTypes...` and return type `R`.
1687
+
1688
  *Effects:* As if by: `function(std::forward<F>(f)).swap(*this);`
1689
 
1690
  *Returns:* `*this`.
1691
 
 
 
 
 
1692
  ``` cpp
1693
  template<class F> function& operator=(reference_wrapper<F> f) noexcept;
1694
  ```
1695
 
1696
  *Effects:* As if by: `function(f).swap(*this);`
 
1701
  ~function();
1702
  ```
1703
 
1704
  *Effects:* If `*this != nullptr`, destroys the target of `this`.
1705
 
1706
+ ##### Modifiers <a id="func.wrap.func.mod">[[func.wrap.func.mod]]</a>
1707
 
1708
  ``` cpp
1709
  void swap(function& other) noexcept;
1710
  ```
1711
 
1712
+ *Effects:* Interchanges the targets of `*this` and `other`.
1713
 
1714
+ ##### Capacity <a id="func.wrap.func.cap">[[func.wrap.func.cap]]</a>
1715
 
1716
  ``` cpp
1717
  explicit operator bool() const noexcept;
1718
  ```
1719
 
1720
  *Returns:* `true` if `*this` has a target, otherwise `false`.
1721
 
1722
+ ##### Invocation <a id="func.wrap.func.inv">[[func.wrap.func.inv]]</a>
1723
 
1724
  ``` cpp
1725
  R operator()(ArgTypes... args) const;
1726
  ```
1727
 
1728
  *Returns:* *INVOKE*\<R\>(f,
1729
+ std::forward\<ArgTypes\>(args)...) [[func.require]], where `f` is the
1730
+ target object [[func.def]] of `*this`.
1731
 
1732
  *Throws:* `bad_function_call` if `!*this`; otherwise, any exception
1733
  thrown by the wrapped callable object.
1734
 
1735
+ ##### Target access <a id="func.wrap.func.targ">[[func.wrap.func.targ]]</a>
1736
 
1737
  ``` cpp
1738
  const type_info& target_type() const noexcept;
1739
  ```
1740
 
 
1747
  ```
1748
 
1749
  *Returns:* If `target_type() == typeid(T)` a pointer to the stored
1750
  function target; otherwise a null pointer.
1751
 
1752
+ ##### Null pointer comparison functions <a id="func.wrap.func.nullptr">[[func.wrap.func.nullptr]]</a>
1753
 
1754
  ``` cpp
1755
  template<class R, class... ArgTypes>
1756
  bool operator==(const function<R(ArgTypes...)>& f, nullptr_t) noexcept;
 
 
1757
  ```
1758
 
1759
  *Returns:* `!f`.
1760
 
1761
+ ##### Specialized algorithms <a id="func.wrap.func.alg">[[func.wrap.func.alg]]</a>
 
 
 
 
 
 
 
 
 
1762
 
1763
  ``` cpp
1764
  template<class R, class... ArgTypes>
1765
  void swap(function<R(ArgTypes...)>& f1, function<R(ArgTypes...)>& f2) noexcept;
1766
  ```
1767
 
1768
  *Effects:* As if by: `f1.swap(f2);`
1769
 
1770
  ### Searchers <a id="func.search">[[func.search]]</a>
1771
 
1772
+ This subclause provides function object types [[function.objects]] for
1773
+ operations that search for a sequence \[`pat``first`, `pat_last`) in
1774
  another sequence \[`first`, `last`) that is provided to the object’s
1775
  function call operator. The first sequence (the pattern to be searched
1776
  for) is provided to the object’s constructor, and the second (the
1777
  sequence to be searched) is provided to the function call operator.
1778
 
1779
  Each specialization of a class template specified in this subclause
1780
+ [[func.search]] shall meet the *Cpp17CopyConstructible* and
1781
+ *Cpp17CopyAssignable* requirements. Template parameters named
1782
 
1783
  - `ForwardIterator`,
1784
  - `ForwardIterator1`,
1785
  - `ForwardIterator2`,
1786
  - `RandomAccessIterator`,
 
1788
  - `RandomAccessIterator2`, and
1789
  - `BinaryPredicate`
1790
 
1791
  of templates specified in this subclause [[func.search]] shall meet the
1792
  same requirements and semantics as specified in [[algorithms.general]].
1793
+ Template parameters named `Hash` shall meet the *Cpp17Hash* requirements
1794
+ ([[cpp17.hash]]).
1795
 
1796
  The Boyer-Moore searcher implements the Boyer-Moore search algorithm.
1797
  The Boyer-Moore-Horspool searcher implements the Boyer-Moore-Horspool
1798
  search algorithm. In general, the Boyer-Moore searcher will use more
1799
  memory and give better runtime performance than Boyer-Moore-Horspool.
 
1802
 
1803
  ``` cpp
1804
  template<class ForwardIterator1, class BinaryPredicate = equal_to<>>
1805
  class default_searcher {
1806
  public:
1807
+ constexpr default_searcher(ForwardIterator1 pat_first, ForwardIterator1 pat_last,
1808
  BinaryPredicate pred = BinaryPredicate());
1809
 
1810
  template<class ForwardIterator2>
1811
+ constexpr pair<ForwardIterator2, ForwardIterator2>
1812
  operator()(ForwardIterator2 first, ForwardIterator2 last) const;
1813
 
1814
  private:
1815
  ForwardIterator1 pat_first_; // exposition only
1816
  ForwardIterator1 pat_last_; // exposition only
1817
  BinaryPredicate pred_; // exposition only
1818
  };
1819
  ```
1820
 
1821
  ``` cpp
1822
+ constexpr default_searcher(ForwardIterator pat_first, ForwardIterator pat_last,
1823
  BinaryPredicate pred = BinaryPredicate());
1824
  ```
1825
 
1826
  *Effects:* Constructs a `default_searcher` object, initializing
1827
  `pat_first_` with `pat_first`, \texttt{pat_last\_} with `pat_last`, and
 
1830
  *Throws:* Any exception thrown by the copy constructor of
1831
  `BinaryPredicate` or `ForwardIterator1`.
1832
 
1833
  ``` cpp
1834
  template<class ForwardIterator2>
1835
+ constexpr pair<ForwardIterator2, ForwardIterator2>
1836
  operator()(ForwardIterator2 first, ForwardIterator2 last) const;
1837
  ```
1838
 
1839
  *Effects:* Returns a pair of iterators `i` and `j` such that
1840
 
 
1872
  RandomAccessIterator1 pat_last,
1873
  Hash hf = Hash(),
1874
  BinaryPredicate pred = BinaryPredicate());
1875
  ```
1876
 
1877
+ *Preconditions:* The value type of `RandomAccessIterator1` meets the
1878
+ *Cpp17DefaultConstructible* requirements, the *Cpp17CopyConstructible*
1879
+ requirements, and the *Cpp17CopyAssignable* requirements.
1880
 
1881
+ *Preconditions:* Let `V` be
1882
+ `iterator_traits<RandomAccessIterator1>::value_type`. For any two values
1883
+ `A` and `B` of type `V`, if `pred(A, B) == true`, then `hf(A) == hf(B)`
1884
+ is `true`.
1885
 
1886
+ *Effects:* Initializes `pat_first_` with `pat_first`, `pat_last_` with
1887
+ `pat_last`, `hash_` with `hf`, and `pred_` with `pred`.
 
1888
 
1889
  *Throws:* Any exception thrown by the copy constructor of
1890
  `RandomAccessIterator1`, or by the default constructor, copy
1891
  constructor, or the copy assignment operator of the value type of
1892
  `RandomAccessIterator1`, or the copy constructor or `operator()` of
 
1897
  template<class RandomAccessIterator2>
1898
  pair<RandomAccessIterator2, RandomAccessIterator2>
1899
  operator()(RandomAccessIterator2 first, RandomAccessIterator2 last) const;
1900
  ```
1901
 
1902
+ *Mandates:* `RandomAccessIterator1` and `RandomAccessIterator2` have the
1903
+ same value type.
1904
 
1905
  *Effects:* Finds a subsequence of equal values in a sequence.
1906
 
1907
  *Returns:* A pair of iterators `i` and `j` such that
1908
 
 
1949
  RandomAccessIterator1 pat_last,
1950
  Hash hf = Hash(),
1951
  BinaryPredicate pred = BinaryPredicate());
1952
  ```
1953
 
1954
+ *Preconditions:* The value type of `RandomAccessIterator1` meets the
1955
+ *Cpp17DefaultConstructible*, *Cpp17CopyConstructible*, and
1956
+ *Cpp17CopyAssignable* requirements.
1957
 
1958
+ *Preconditions:* Let `V` be
1959
+ `iterator_traits<RandomAccessIterator1>::value_type`. For any two values
1960
+ `A` and `B` of type `V`, if `pred(A, B) == true`, then `hf(A) == hf(B)`
1961
+ is `true`.
1962
 
1963
+ *Effects:* Initializes `pat_first_` with `pat_first`, `pat_last_` with
1964
+ `pat_last`, `hash_` with `hf`, and `pred_` with `pred`.
 
1965
 
1966
  *Throws:* Any exception thrown by the copy constructor of
1967
  `RandomAccessIterator1`, or by the default constructor, copy
1968
  constructor, or the copy assignment operator of the value type of
1969
  `RandomAccessIterator1` or the copy constructor or `operator()` of
 
1974
  template<class RandomAccessIterator2>
1975
  pair<RandomAccessIterator2, RandomAccessIterator2>
1976
  operator()(RandomAccessIterator2 first, RandomAccessIterator2 last) const;
1977
  ```
1978
 
1979
+ *Mandates:* `RandomAccessIterator1` and `RandomAccessIterator2` have the
1980
+ same value type.
1981
 
1982
  *Effects:* Finds a subsequence of equal values in a sequence.
1983
 
1984
  *Returns:* A pair of iterators `i` and `j` such that
1985
 
 
1997
  applications of the predicate.
1998
 
1999
  ### Class template `hash` <a id="unord.hash">[[unord.hash]]</a>
2000
 
2001
  The unordered associative containers defined in [[unord]] use
2002
+ specializations of the class template `hash` [[functional.syn]] as the
2003
+ default hash function.
2004
 
2005
  Each specialization of `hash` is either enabled or disabled, as
2006
  described below.
2007
 
2008
+ [*Note 1*: Enabled specializations meet the *Cpp17Hash* requirements,
2009
+ and disabled specializations do not. — *end note*]
2010
 
2011
  Each header that declares the template `hash` provides enabled
2012
  specializations of `hash` for `nullptr_t` and all cv-unqualified
2013
  arithmetic, enumeration, and pointer types. For any type `Key` for which
2014
  neither the library nor the user provides an explicit or partial
 
2020
 
2021
  If `H` is a disabled specialization of `hash`, these values are `false`:
2022
  `is_default_constructible_v<H>`, `is_copy_constructible_v<H>`,
2023
  `is_move_constructible_v<H>`, `is_copy_assignable_v<H>`, and
2024
  `is_move_assignable_v<H>`. Disabled specializations of `hash` are not
2025
+ function object types [[function.objects]].
2026
 
2027
  [*Note 2*: This means that the specialization of `hash` exists, but any
2028
+ attempts to use it as a *Cpp17Hash* will be ill-formed. — *end note*]
2029
 
2030
  An enabled specialization `hash<Key>` will:
2031
 
2032
+ - meet the *Cpp17Hash* requirements ([[cpp17.hash]]), with `Key` as the
2033
+ function call argument type, the *Cpp17DefaultConstructible*
2034
+ requirements ([[cpp17.defaultconstructible]]), the
2035
+ *Cpp17CopyAssignable* requirements ([[cpp17.copyassignable]]),
2036
+ - be swappable [[swappable.requirements]] for lvalues,
2037
+ - meet the requirement that if `k1 == k2` is `true`, `h(k1) == h(k2)` is
2038
+ also `true`, where `h` is an object of type `hash<Key>` and `k1` and
2039
+ `k2` are objects of type `Key`;
2040
+ - meet the requirement that the expression `h(k)`, where `h` is an
2041
  object of type `hash<Key>` and `k` is an object of type `Key`, shall
2042
+ not throw an exception unless `hash<Key>` is a program-defined
2043
+ specialization that depends on at least one program-defined type.
2044