From Jason Turner

[function.objects]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmps52ajdpa/{from.md → to.md} +651 -232
tmp/tmps52ajdpa/{from.md → to.md} RENAMED
@@ -1,136 +1,167 @@
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;
36
- template<class T = void> struct divides;
37
- template<class T = void> struct modulus;
38
- template<class T = void> struct negate;
39
- template<> struct plus<void>;
40
- template<> struct minus<void>;
41
- template<> struct multiplies<void>;
42
- template<> struct divides<void>;
43
- template<> struct modulus<void>;
44
- template<> struct negate<void>;
45
 
46
  // [comparisons], comparisons
47
- template<class T = void> struct equal_to;
48
- template<class T = void> struct not_equal_to;
49
- template<class T = void> struct greater;
50
- template<class T = void> struct less;
51
- template<class T = void> struct greater_equal;
52
- template<class T = void> struct less_equal;
53
- template<> struct equal_to<void>;
54
- template<> struct not_equal_to<void>;
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>;
68
- template<> struct logical_or<void>;
69
- template<> struct logical_not<void>;
70
 
71
  // [bitwise.operations], bitwise operations
72
- template<class T = void> struct bit_and;
73
- template<class T = void> struct bit_or;
74
- template<class T = void> struct bit_xor;
75
- template<class T = void> struct bit_not;
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;
107
  .
108
  .
109
  .
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
121
  template<class R, class... ArgTypes> class function<R(ArgTypes...)>;
122
 
 
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
 
133
  template<class RandomAccessIterator,
134
  class Hash = hash<typename iterator_traits<RandomAccessIterator>::value_type>,
135
  class BinaryPredicate = equal_to<>>
136
  class boyer_moore_searcher;
@@ -140,20 +171,20 @@ namespace std {
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*:
@@ -206,35 +237,38 @@ collectively referred to as *state entities*.
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
@@ -255,11 +289,11 @@ 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
@@ -278,61 +312,79 @@ 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 {
298
  template<class T> class reference_wrapper {
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
  ```
@@ -349,11 +401,11 @@ void FUN(T&&) = delete;
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
  ```
@@ -386,11 +438,11 @@ constexpr T& get() const noexcept;
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(),
@@ -409,11 +461,11 @@ template<class T> constexpr reference_wrapper<T> ref(T& t) noexcept;
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
 
@@ -421,16 +473,50 @@ template<class T> constexpr reference_wrapper<const T> cref(const T& t) noexcept
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>
429
 
 
 
430
  The library provides basic function object classes for all of the
431
- arithmetic operators in the language ([[expr.mul]], [[expr.add]]).
432
 
433
  #### Class template `plus` <a id="arithmetic.operations.plus">[[arithmetic.operations.plus]]</a>
434
 
435
  ``` cpp
436
  template<class T = void> struct plus {
@@ -610,12 +696,14 @@ template<class T> constexpr auto operator()(T&& t) const
610
 
611
  *Returns:* `-std::forward<T>(t)`.
612
 
613
  ### Comparisons <a id="comparisons">[[comparisons]]</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]].
@@ -810,41 +898,34 @@ template<class T, class U> constexpr auto operator()(T&& t, U&& u) const
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`,
@@ -855,31 +936,32 @@ equality-preserving [[concepts.equality]].
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
@@ -890,56 +972,75 @@ equality-preserving [[concepts.equality]].
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
@@ -951,44 +1052,58 @@ exactly one of `ranges::less{}(ET, EU)`, `ranges::less{}(EU, ET)`, or
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]]).
990
 
991
  #### Class template `logical_and` <a id="logical.operations.and">[[logical.operations.and]]</a>
992
 
993
  ``` cpp
994
  template<class T = void> struct logical_and {
@@ -1078,13 +1193,15 @@ template<class T> constexpr auto operator()(T&& t) const
1078
 
1079
  *Returns:* `!std::forward<T>(t)`.
1080
 
1081
  ### Bitwise operations <a id="bitwise.operations">[[bitwise.operations]]</a>
1082
 
 
 
1083
  The library provides basic function object classes for all of the
1084
- bitwise operators in the language ([[expr.bit.and]], [[expr.or]],
1085
- [[expr.xor]], [[expr.unary.op]]).
1086
 
1087
  #### Class template `bit_and` <a id="bitwise.operations.and">[[bitwise.operations.and]]</a>
1088
 
1089
  ``` cpp
1090
  template<class T = void> struct bit_and {
@@ -1196,11 +1313,11 @@ template<> struct bit_not<void> {
1196
  using is_transparent = unspecified;
1197
  };
1198
  ```
1199
 
1200
  ``` cpp
1201
- template<class T> constexpr auto operator()(T&&) const
1202
  -> decltype(~std::forward<T>(t));
1203
  ```
1204
 
1205
  *Returns:* `~std::forward<T>(t)`.
1206
 
@@ -1238,25 +1355,29 @@ In the text that follows:
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]]
@@ -1278,20 +1399,27 @@ 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
 
1294
  #### Class template `is_bind_expression` <a id="func.bind.isbind">[[func.bind.isbind]]</a>
1295
 
1296
  ``` cpp
1297
  namespace std {
@@ -1319,12 +1447,12 @@ namespace std {
1319
  template<class T> struct is_placeholder; // see below
1320
  }
1321
  ```
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
@@ -1368,11 +1496,11 @@ $w_N$) [[func.require]] is a valid expression for some values `w₁`,
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
  ```
@@ -1417,20 +1545,22 @@ 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 {
1422
- // M is the implementation-defined number of placeholders
1423
  see below _1;
1424
  see below _2;
1425
  .
1426
  .
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
@@ -1447,26 +1577,30 @@ 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
@@ -1488,10 +1622,12 @@ const char* what() const noexcept override;
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 {
1495
  template<class> class function; // not defined
1496
 
1497
  template<class R, class... ArgTypes>
@@ -1502,11 +1638,11 @@ namespace std {
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;
1512
  template<class F> function& operator=(F&&);
@@ -1531,36 +1667,29 @@ namespace std {
1531
 
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;
@@ -1576,70 +1705,87 @@ function(nullptr_t) noexcept;
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
 
@@ -1707,11 +1853,11 @@ template<class F> function& operator=(reference_wrapper<F> f) noexcept;
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;
@@ -1728,11 +1874,11 @@ R operator()(ArgTypes... args) const;
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;
@@ -1747,11 +1893,11 @@ template<class T> const T* target() const noexcept;
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
  ```
@@ -1765,33 +1911,302 @@ 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`,
1787
  - `RandomAccessIterator1`,
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
@@ -1799,10 +2214,11 @@ search algorithm. In general, the Boyer-Moore searcher will use more
1799
  memory and give better runtime performance than Boyer-Moore-Horspool.
1800
 
1801
  #### Class template `default_searcher` <a id="func.search.default">[[func.search.default]]</a>
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());
@@ -1814,14 +2230,15 @@ template<class ForwardIterator1, class BinaryPredicate = equal_to<>>
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
@@ -1843,10 +2260,11 @@ template<class ForwardIterator2>
1843
  `j == next(i, distance(pat_first_, pat_last_))`.
1844
 
1845
  #### Class template `boyer_moore_searcher` <a id="func.search.bm">[[func.search.bm]]</a>
1846
 
1847
  ``` cpp
 
1848
  template<class RandomAccessIterator1,
1849
  class Hash = hash<typename iterator_traits<RandomAccessIterator1>::value_type>,
1850
  class BinaryPredicate = equal_to<>>
1851
  class boyer_moore_searcher {
1852
  public:
@@ -1863,30 +2281,30 @@ template<class RandomAccessIterator1,
1863
  RandomAccessIterator1 pat_first_; // exposition only
1864
  RandomAccessIterator1 pat_last_; // exposition only
1865
  Hash hash_; // exposition only
1866
  BinaryPredicate pred_; // exposition only
1867
  };
 
1868
  ```
1869
 
1870
  ``` cpp
1871
  boyer_moore_searcher(RandomAccessIterator1 pat_first,
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
@@ -1920,10 +2338,11 @@ found.
1920
  applications of the predicate.
1921
 
1922
  #### Class template `boyer_moore_horspool_searcher` <a id="func.search.bmh">[[func.search.bmh]]</a>
1923
 
1924
  ``` cpp
 
1925
  template<class RandomAccessIterator1,
1926
  class Hash = hash<typename iterator_traits<RandomAccessIterator1>::value_type>,
1927
  class BinaryPredicate = equal_to<>>
1928
  class boyer_moore_horspool_searcher {
1929
  public:
@@ -1940,10 +2359,11 @@ template<class RandomAccessIterator1,
1940
  RandomAccessIterator1 pat_first_; // exposition only
1941
  RandomAccessIterator1 pat_last_; // exposition only
1942
  Hash hash_; // exposition only
1943
  BinaryPredicate pred_; // exposition only
1944
  };
 
1945
  ```
1946
 
1947
  ``` cpp
1948
  boyer_moore_horspool_searcher(RandomAccessIterator1 pat_first,
1949
  RandomAccessIterator1 pat_last,
@@ -1953,22 +2373,21 @@ boyer_moore_horspool_searcher(RandomAccessIterator1 pat_first,
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
1970
  `BinaryPredicate` or `Hash`. May throw `bad_alloc` if additional memory
1971
  needed for internal data structures cannot be allocated.
1972
 
1973
  ``` cpp
1974
  template<class RandomAccessIterator2>
@@ -1981,11 +2400,11 @@ 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
 
1986
- - `i` is the first iterator `i` in the range \[`first`,
1987
  `last - (pat_last_ - pat_first_)`) such that for every non-negative
1988
  integer `n` less than `pat_last_ - pat_first_` the following condition
1989
  holds: `pred(*(i + n), *(pat_first_ + n)) != false`, and
1990
  - `j == next(i, distance(pat_first_, pat_last_))`.
1991
 
@@ -2030,15 +2449,15 @@ attempts to use it as a *Cpp17Hash* will be ill-formed. — *end note*]
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
 
 
1
  ## Function objects <a id="function.objects">[[function.objects]]</a>
2
 
3
+ ### General <a id="function.objects.general">[[function.objects.general]]</a>
4
+
5
+ A *function object type* is an object type [[term.object.type]] that can
6
+ be the type of the *postfix-expression* in a function call
7
+ [[expr.call]], [[over.match.call]].[^1]
8
+
9
+ A *function object* is an object of a function object type. In the
10
+ places where one would expect to pass a pointer to a function to an
11
+ algorithmic template [[algorithms]], the interface is specified to
12
+ accept a function object. This not only makes algorithmic templates work
13
+ with pointers to functions, but also enables them to work with arbitrary
14
+ function objects.
15
 
16
  ### Header `<functional>` synopsis <a id="functional.syn">[[functional.syn]]</a>
17
 
18
  ``` cpp
19
  namespace std {
20
  // [func.invoke], invoke
21
  template<class F, class... Args>
22
+ constexpr invoke_result_t<F, Args...> invoke(F&& f, Args&&... args) // freestanding
23
  noexcept(is_nothrow_invocable_v<F, Args...>);
24
 
25
+ template<class R, class F, class... Args>
26
+ constexpr R invoke_r(F&& f, Args&&... args) // freestanding
27
+ noexcept(is_nothrow_invocable_r_v<R, F, Args...>);
28
+
29
  // [refwrap], reference_wrapper
30
+ template<class T> class reference_wrapper; // freestanding
31
 
32
+ template<class T> constexpr reference_wrapper<T> ref(T&) noexcept; // freestanding
33
+ template<class T> constexpr reference_wrapper<const T> cref(const T&) noexcept; // freestanding
34
+ template<class T> void ref(const T&&) = delete; // freestanding
35
+ template<class T> void cref(const T&&) = delete; // freestanding
36
 
37
+ template<class T>
38
+ constexpr reference_wrapper<T> ref(reference_wrapper<T>) noexcept; // freestanding
39
+ template<class T>
40
+ constexpr reference_wrapper<const T> cref(reference_wrapper<T>) noexcept; // freestanding
41
+
42
+ // [refwrap.common.ref], common_reference related specializations
43
+ template<class R, class T, template<class> class RQual, template<class> class TQual>
44
+ requires see below
45
+ struct basic_common_reference<R, T, RQual, TQual>;
46
+
47
+ template<class T, class R, template<class> class TQual, template<class> class RQual>
48
+ requires see below
49
+ struct basic_common_reference<T, R, TQual, RQual>;
50
 
51
  // [arithmetic.operations], arithmetic operations
52
+ template<class T = void> struct plus; // freestanding
53
+ template<class T = void> struct minus; // freestanding
54
+ template<class T = void> struct multiplies; // freestanding
55
+ template<class T = void> struct divides; // freestanding
56
+ template<class T = void> struct modulus; // freestanding
57
+ template<class T = void> struct negate; // freestanding
58
+ template<> struct plus<void>; // freestanding
59
+ template<> struct minus<void>; // freestanding
60
+ template<> struct multiplies<void>; // freestanding
61
+ template<> struct divides<void>; // freestanding
62
+ template<> struct modulus<void>; // freestanding
63
+ template<> struct negate<void>; // freestanding
64
 
65
  // [comparisons], comparisons
66
+ template<class T = void> struct equal_to; // freestanding
67
+ template<class T = void> struct not_equal_to; // freestanding
68
+ template<class T = void> struct greater; // freestanding
69
+ template<class T = void> struct less; // freestanding
70
+ template<class T = void> struct greater_equal; // freestanding
71
+ template<class T = void> struct less_equal; // freestanding
72
+ template<> struct equal_to<void>; // freestanding
73
+ template<> struct not_equal_to<void>; // freestanding
74
+ template<> struct greater<void>; // freestanding
75
+ template<> struct less<void>; // freestanding
76
+ template<> struct greater_equal<void>; // freestanding
77
+ template<> struct less_equal<void>; // freestanding
78
 
79
  // [comparisons.three.way], class compare_three_way
80
+ struct compare_three_way; // freestanding
81
 
82
  // [logical.operations], logical operations
83
+ template<class T = void> struct logical_and; // freestanding
84
+ template<class T = void> struct logical_or; // freestanding
85
+ template<class T = void> struct logical_not; // freestanding
86
+ template<> struct logical_and<void>; // freestanding
87
+ template<> struct logical_or<void>; // freestanding
88
+ template<> struct logical_not<void>; // freestanding
89
 
90
  // [bitwise.operations], bitwise operations
91
+ template<class T = void> struct bit_and; // freestanding
92
+ template<class T = void> struct bit_or; // freestanding
93
+ template<class T = void> struct bit_xor; // freestanding
94
+ template<class T = void> struct bit_not; // freestanding
95
+ template<> struct bit_and<void>; // freestanding
96
+ template<> struct bit_or<void>; // freestanding
97
+ template<> struct bit_xor<void>; // freestanding
98
+ template<> struct bit_not<void>; // freestanding
99
 
100
  // [func.identity], identity
101
+ struct identity; // freestanding
102
 
103
  // [func.not.fn], function template not_fn
104
+ template<class F> constexpr unspecified not_fn(F&& f); // freestanding
105
 
106
+ // [func.bind.partial], function templates bind_front and bind_back
107
+ template<class F, class... Args>
108
+ constexpr unspecified bind_front(F&&, Args&&...); // freestanding
109
+ template<class F, class... Args>
110
+ constexpr unspecified bind_back(F&&, Args&&...); // freestanding
111
 
112
  // [func.bind], bind
113
+ template<class T> struct is_bind_expression; // freestanding
114
  template<class T>
115
+ constexpr bool is_bind_expression_v = // freestanding
116
+ is_bind_expression<T>::value;
117
+ template<class T> struct is_placeholder; // freestanding
118
  template<class T>
119
+ constexpr int is_placeholder_v = // freestanding
120
+ is_placeholder<T>::value;
121
 
122
  template<class F, class... BoundArgs>
123
+ constexpr unspecified bind(F&&, BoundArgs&&...); // freestanding
124
  template<class R, class F, class... BoundArgs>
125
+ constexpr unspecified bind(F&&, BoundArgs&&...); // freestanding
126
 
127
  namespace placeholders {
128
  // M is the implementation-defined number of placeholders
129
+ see belownc _1; // freestanding
130
+ see belownc _2; // freestanding
131
  .
132
  .
133
  .
134
+ see belownc _M; // freestanding
135
  }
136
 
137
  // [func.memfn], member function adaptors
138
  template<class R, class T>
139
+ constexpr unspecified mem_fn(R T::*) noexcept; // freestanding
140
 
141
  // [func.wrap], polymorphic function wrappers
142
  class bad_function_call;
143
 
144
  template<class> class function; // not defined
145
  template<class R, class... ArgTypes> class function<R(ArgTypes...)>;
146
 
147
+ // [func.wrap.func.alg], specialized algorithms
148
  template<class R, class... ArgTypes>
149
  void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&) noexcept;
150
 
151
+ // [func.wrap.func.nullptr], null pointer comparison operator functions
152
  template<class R, class... ArgTypes>
153
  bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
154
 
155
+ // [func.wrap.move], move only wrapper
156
+ template<class... S> class move_only_function; // not defined
157
+ template<class R, class... ArgTypes>
158
+ class move_only_function<R(ArgTypes...) cv ref noexcept(noex)>; // see below
159
+
160
  // [func.search], searchers
161
+ template<class ForwardIterator1, class BinaryPredicate = equal_to<>>
162
+ class default_searcher; // freestanding
163
 
164
  template<class RandomAccessIterator,
165
  class Hash = hash<typename iterator_traits<RandomAccessIterator>::value_type>,
166
  class BinaryPredicate = equal_to<>>
167
  class boyer_moore_searcher;
 
171
  class BinaryPredicate = equal_to<>>
172
  class boyer_moore_horspool_searcher;
173
 
174
  // [unord.hash], class template hash
175
  template<class T>
176
+ struct hash; // freestanding
177
 
178
  namespace ranges {
179
  // [range.cmp], concept-constrained comparisons
180
+ struct equal_to; // freestanding
181
+ struct not_equal_to; // freestanding
182
+ struct greater; // freestanding
183
+ struct less; // freestanding
184
+ struct greater_equal; // freestanding
185
+ struct less_equal; // freestanding
186
  }
187
  }
188
  ```
189
 
190
  [*Example 1*:
 
237
  ### Requirements <a id="func.require">[[func.require]]</a>
238
 
239
  Define `INVOKE(f, t₁, t₂, …, t_N)` as follows:
240
 
241
  - `(t₁.*f)(t₂, …, t_N)` when `f` is a pointer to a member function of a
242
+ class `T` and `is_same_v<T, remove_cvref_t<decltype(t1)>> ||`
243
+ `is_base_of_v<T, remove_cvref_t<decltype(t₁)>>` is `true`;
244
  - `(t₁.get().*f)(t₂, …, t_N)` when `f` is a pointer to a member function
245
  of a class `T` and `remove_cvref_t<decltype(t₁)>` is a specialization
246
  of `reference_wrapper`;
247
  - `((*t₁).*f)(t₂, …, t_N)` when `f` is a pointer to a member function of
248
  a class `T` and `t₁` does not satisfy the previous two items;
249
+ - `t₁.*f` when N = 1 and `f` is a pointer to data member of a class `T`
250
+ and `is_same_v<T, remove_cvref_t<decltype(t1)>> ||`
251
+ `is_base_of_v<T, remove_cvref_t<decltype(t₁)>>` is `true`;
252
+ - `t₁.get().*f` when N = 1 and `f` is a pointer to data member of a
253
  class `T` and `remove_cvref_t<decltype(t₁)>` is a specialization of
254
  `reference_wrapper`;
255
+ - `(*t₁).*f` when N = 1 and `f` is a pointer to data member of a class
256
+ `T` and `t₁` does not satisfy the previous two items;
257
  - `f(t₁, t₂, …, t_N)` in all other cases.
258
 
259
  Define `INVOKE<R>(f, t₁, t₂, …, t_N)` as
260
  `static_cast<void>(INVOKE(f, t₁, t₂, …, t_N))` if `R` is cv `void`,
261
+ otherwise `INVOKE(f, t₁, t₂, …, t_N)` implicitly converted to `R`. If
262
+ `reference_converts_from_temporary_v<R, decltype(INVOKE(f, t₁, t₂, …, t_N))>`
263
+ is `true`, `INVOKE<R>(f, t₁, t₂, …, t_N)` is ill-formed.
264
 
265
  Every call wrapper [[func.def]] meets the *Cpp17MoveConstructible* and
266
  *Cpp17Destructible* requirements. An *argument forwarding call wrapper*
267
  is a call wrapper that can be called with an arbitrary argument list and
268
+ delivers the arguments to the target object as references. This
269
+ forwarding step delivers rvalue arguments as rvalue references and
270
  lvalue arguments as lvalue references.
271
 
272
  [*Note 1*:
273
 
274
  In a typical implementation, argument forwarding call wrappers have an
 
289
  call wrapper and where cv shall be neither `volatile` nor
290
  `const volatile`.
291
 
292
  A *call pattern* defines the semantics of invoking a perfect forwarding
293
  call wrapper. A postfix call performed on a perfect forwarding call
294
+ wrapper is expression-equivalent [[defns.expression.equivalent]] to an
295
  expression `e` determined from its call pattern `cp` by replacing all
296
  occurrences of the arguments of the call wrapper and its state entities
297
  with references as described in the corresponding forwarding steps.
298
 
299
  A *simple call wrapper* is a perfect forwarding call wrapper that meets
 
312
 
313
  Argument forwarding call wrappers returned by a given standard library
314
  function template have the same type if the types of their corresponding
315
  state entities are the same.
316
 
317
+ ### `invoke` functions <a id="func.invoke">[[func.invoke]]</a>
318
 
319
  ``` cpp
320
  template<class F, class... Args>
321
  constexpr invoke_result_t<F, Args...> invoke(F&& f, Args&&... args)
322
  noexcept(is_nothrow_invocable_v<F, Args...>);
323
  ```
324
 
325
+ *Constraints:* `is_invocable_v<F, Args...>` is `true`.
326
+
327
  *Returns:* *INVOKE*(std::forward\<F\>(f),
328
  std::forward\<Args\>(args)...) [[func.require]].
329
 
330
+ ``` cpp
331
+ template<class R, class F, class... Args>
332
+ constexpr R invoke_r(F&& f, Args&&... args)
333
+ noexcept(is_nothrow_invocable_r_v<R, F, Args...>);
334
+ ```
335
+
336
+ *Constraints:* `is_invocable_r_v<R, F, Args...>` is `true`.
337
+
338
+ *Returns:* *INVOKE*\<R\>(std::forward\<F\>(f),
339
+ std::forward\<Args\>(args)...) [[func.require]].
340
+
341
  ### Class template `reference_wrapper` <a id="refwrap">[[refwrap]]</a>
342
 
343
+ #### General <a id="refwrap.general">[[refwrap.general]]</a>
344
+
345
  ``` cpp
346
  namespace std {
347
  template<class T> class reference_wrapper {
348
  public:
349
  // types
350
  using type = T;
351
 
352
+ // [refwrap.const], constructors
353
  template<class U>
354
  constexpr reference_wrapper(U&&) noexcept(see below);
355
  constexpr reference_wrapper(const reference_wrapper& x) noexcept;
356
 
357
+ // [refwrap.assign], assignment
358
  constexpr reference_wrapper& operator=(const reference_wrapper& x) noexcept;
359
 
360
+ // [refwrap.access], access
361
  constexpr operator T& () const noexcept;
362
  constexpr T& get() const noexcept;
363
 
364
+ // [refwrap.invoke], invocation
365
  template<class... ArgTypes>
366
+ constexpr invoke_result_t<T&, ArgTypes...> operator()(ArgTypes&&...) const
367
+ noexcept(is_nothrow_invocable_v<T&, ArgTypes...>);
368
  };
369
+
370
  template<class T>
371
  reference_wrapper(T&) -> reference_wrapper<T>;
372
  }
373
  ```
374
 
375
  `reference_wrapper<T>` is a *Cpp17CopyConstructible* and
376
  *Cpp17CopyAssignable* wrapper around a reference to an object or
377
  function of type `T`.
378
 
379
+ `reference_wrapper<T>` is a trivially copyable type
380
+ [[term.trivially.copyable.type]].
381
 
382
  The template parameter `T` of `reference_wrapper` may be an incomplete
383
  type.
384
 
385
+ #### Constructors <a id="refwrap.const">[[refwrap.const]]</a>
386
 
387
  ``` cpp
388
  template<class U>
389
  constexpr reference_wrapper(U&& u) noexcept(see below);
390
  ```
 
401
 
402
  *Effects:* Creates a variable `r` as if by `T& r = std::forward<U>(u)`,
403
  then constructs a `reference_wrapper` object that stores a reference to
404
  `r`.
405
 
406
+ *Remarks:* The exception specification is equivalent to
407
  `noexcept(`*`FUN`*`(declval<U>()))`.
408
 
409
  ``` cpp
410
  constexpr reference_wrapper(const reference_wrapper& x) noexcept;
411
  ```
 
438
  #### Invocation <a id="refwrap.invoke">[[refwrap.invoke]]</a>
439
 
440
  ``` cpp
441
  template<class... ArgTypes>
442
  constexpr invoke_result_t<T&, ArgTypes...>
443
+ operator()(ArgTypes&&... args) const noexcept(is_nothrow_invocable_v<T&, ArgTypes...>);
444
  ```
445
 
446
  *Mandates:* `T` is a complete type.
447
 
448
  *Returns:* *INVOKE*(get(),
 
461
 
462
  ``` cpp
463
  template<class T> constexpr reference_wrapper<T> ref(reference_wrapper<T> t) noexcept;
464
  ```
465
 
466
+ *Returns:* `t`.
467
 
468
  ``` cpp
469
  template<class T> constexpr reference_wrapper<const T> cref(const T& t) noexcept;
470
  ```
471
 
 
473
 
474
  ``` cpp
475
  template<class T> constexpr reference_wrapper<const T> cref(reference_wrapper<T> t) noexcept;
476
  ```
477
 
478
+ *Returns:* `t`.
479
+
480
+ #### `common_reference` related specializations <a id="refwrap.common.ref">[[refwrap.common.ref]]</a>
481
+
482
+ ``` cpp
483
+ namespace std {
484
+ template<class T>
485
+ constexpr bool is-ref-wrapper = false; // exposition only
486
+
487
+ template<class T>
488
+ constexpr bool is-ref-wrapper<reference_wrapper<T>> = true;
489
+
490
+ template<class R, class T, class RQ, class TQ>
491
+ concept ref-wrap-common-reference-exists-with = // exposition only
492
+ is-ref-wrapper<R> &&
493
+ requires { typename common_reference_t<typename R::type&, TQ>; } &&
494
+ convertible_to<RQ, common_reference_t<typename R::type&, TQ>>;
495
+
496
+ template<class R, class T, template<class> class RQual, template<class> class TQual>
497
+ requires (ref-wrap-common-reference-exists-with<R, T, RQual<R>, TQual<T>> &&
498
+ !ref-wrap-common-reference-exists-with<T, R, TQual<T>, RQual<R>>)
499
+ struct basic_common_reference<R, T, RQual, TQual> {
500
+ using type = common_reference_t<typename R::type&, TQual<T>>;
501
+ };
502
+
503
+ template<class T, class R, template<class> class TQual, template<class> class RQual>
504
+ requires (ref-wrap-common-reference-exists-with<R, T, RQual<R>, TQual<T>> &&
505
+ !ref-wrap-common-reference-exists-with<T, R, TQual<T>, RQual<R>>)
506
+ struct basic_common_reference<T, R, TQual, RQual> {
507
+ using type = common_reference_t<typename R::type&, TQual<T>>;
508
+ };
509
+ }
510
+ ```
511
 
512
  ### Arithmetic operations <a id="arithmetic.operations">[[arithmetic.operations]]</a>
513
 
514
+ #### General <a id="arithmetic.operations.general">[[arithmetic.operations.general]]</a>
515
+
516
  The library provides basic function object classes for all of the
517
+ arithmetic operators in the language [[expr.mul]], [[expr.add]].
518
 
519
  #### Class template `plus` <a id="arithmetic.operations.plus">[[arithmetic.operations.plus]]</a>
520
 
521
  ``` cpp
522
  template<class T = void> struct plus {
 
696
 
697
  *Returns:* `-std::forward<T>(t)`.
698
 
699
  ### Comparisons <a id="comparisons">[[comparisons]]</a>
700
 
701
+ #### General <a id="comparisons.general">[[comparisons.general]]</a>
702
+
703
  The library provides basic function object classes for all of the
704
+ comparison operators in the language [[expr.rel]], [[expr.eq]].
705
 
706
  For templates `less`, `greater`, `less_equal`, and `greater_equal`, the
707
  specializations for any pointer type yield a result consistent with the
708
  implementation-defined strict total order over pointers
709
  [[defns.order.ptr]].
 
898
 
899
  *Returns:* `std::forward<T>(t) <= std::forward<U>(u)`.
900
 
901
  #### Class `compare_three_way` <a id="comparisons.three.way">[[comparisons.three.way]]</a>
902
 
 
 
 
 
 
 
 
 
 
 
903
  ``` cpp
904
+ namespace std {
905
  struct compare_three_way {
906
  template<class T, class U>
 
907
  constexpr auto operator()(T&& t, U&& u) const;
908
 
909
  using is_transparent = unspecified;
910
  };
911
+ }
912
  ```
913
 
914
  ``` cpp
915
  template<class T, class U>
 
916
  constexpr auto operator()(T&& t, U&& u) const;
917
  ```
918
 
919
+ *Constraints:* `T` and `U` satisfy `three_way_comparable_with`.
920
+
921
  *Preconditions:* If the expression
922
  `std::forward<T>(t) <=> std::forward<U>(u)` results in a call to a
923
  built-in operator `<=>` comparing pointers of type `P`, the conversion
924
  sequences from both `T` and `U` to `P` are
925
+ equality-preserving [[concepts.equality]]; otherwise, `T` and `U` model
926
+ `three_way_comparable_with`.
927
 
928
  *Effects:*
929
 
930
  - If the expression `std::forward<T>(t) <=> std::forward<U>(u)` results
931
  in a call to a built-in operator `<=>` comparing pointers of type `P`,
 
936
  - Otherwise, equivalent to:
937
  `return std::forward<T>(t) <=> std::forward<U>(u);`
938
 
939
  ### Concept-constrained comparisons <a id="range.cmp">[[range.cmp]]</a>
940
 
 
 
 
 
 
 
941
  ``` cpp
942
  struct ranges::equal_to {
943
  template<class T, class U>
 
944
  constexpr bool operator()(T&& t, U&& u) const;
945
 
946
  using is_transparent = unspecified;
947
  };
948
  ```
949
 
950
+ ``` cpp
951
+ template<class T, class U>
952
+ constexpr bool operator()(T&& t, U&& u) const;
953
+ ```
954
+
955
+ *Constraints:* `T` and `U` satisfy `equality_comparable_with`.
956
+
957
  *Preconditions:* If the expression
958
  `std::forward<T>(t) == std::forward<U>(u)` results in a call to a
959
  built-in operator `==` comparing pointers of type `P`, the conversion
960
  sequences from both `T` and `U` to `P` are
961
+ equality-preserving [[concepts.equality]]; otherwise, `T` and `U` model
962
+ `equality_comparable_with`.
963
 
964
  *Effects:*
965
 
966
  - If the expression `std::forward<T>(t) == std::forward<U>(u)` results
967
  in a call to a built-in operator `==` comparing pointers: returns
 
972
  `return std::forward<T>(t) == std::forward<U>(u);`
973
 
974
  ``` cpp
975
  struct ranges::not_equal_to {
976
  template<class T, class U>
 
977
  constexpr bool operator()(T&& t, U&& u) const;
978
 
979
  using is_transparent = unspecified;
980
  };
981
  ```
982
 
983
+ ``` cpp
984
+ template<class T, class U>
985
+ constexpr bool operator()(T&& t, U&& u) const;
986
+ ```
987
+
988
+ *Constraints:* `T` and `U` satisfy `equality_comparable_with`.
989
+
990
+ *Effects:* Equivalent to:
991
 
992
  ``` cpp
993
  return !ranges::equal_to{}(std::forward<T>(t), std::forward<U>(u));
994
  ```
995
 
996
  ``` cpp
997
  struct ranges::greater {
998
  template<class T, class U>
 
999
  constexpr bool operator()(T&& t, U&& u) const;
1000
 
1001
  using is_transparent = unspecified;
1002
  };
1003
  ```
1004
 
1005
+ ``` cpp
1006
+ template<class T, class U>
1007
+ constexpr bool operator()(T&& t, U&& u) const;
1008
+ ```
1009
+
1010
+ *Constraints:* `T` and `U` satisfy `totally_ordered_with`.
1011
+
1012
+ *Effects:* Equivalent to:
1013
 
1014
  ``` cpp
1015
  return ranges::less{}(std::forward<U>(u), std::forward<T>(t));
1016
  ```
1017
 
1018
  ``` cpp
1019
  struct ranges::less {
1020
  template<class T, class U>
 
1021
  constexpr bool operator()(T&& t, U&& u) const;
1022
 
1023
  using is_transparent = unspecified;
1024
  };
1025
  ```
1026
 
1027
+ ``` cpp
1028
+ template<class T, class U>
1029
+ constexpr bool operator()(T&& t, U&& u) const;
1030
+ ```
1031
+
1032
+ *Constraints:* `T` and `U` satisfy `totally_ordered_with`.
1033
+
1034
  *Preconditions:* If the expression
1035
  `std::forward<T>(t) < std::forward<U>(u)` results in a call to a
1036
  built-in operator `<` comparing pointers of type `P`, the conversion
1037
  sequences from both `T` and `U` to `P` are
1038
+ equality-preserving [[concepts.equality]]; otherwise, `T` and `U` model
1039
+ `totally_ordered_with`. For any expressions `ET` and `EU` such that
1040
+ `decltype((ET))` is `T` and `decltype((EU))` is `U`, exactly one of
1041
+ `ranges::less{}(ET, EU)`, `ranges::less{}(EU, ET)`, or
1042
  `ranges::equal_to{}(ET, EU)` is `true`.
1043
 
1044
  *Effects:*
1045
 
1046
  - If the expression `std::forward<T>(t) < std::forward<U>(u)` results in
 
1052
  `return std::forward<T>(t) < std::forward<U>(u);`
1053
 
1054
  ``` cpp
1055
  struct ranges::greater_equal {
1056
  template<class T, class U>
 
1057
  constexpr bool operator()(T&& t, U&& u) const;
1058
 
1059
  using is_transparent = unspecified;
1060
  };
1061
  ```
1062
 
1063
+ ``` cpp
1064
+ template<class T, class U>
1065
+ constexpr bool operator()(T&& t, U&& u) const;
1066
+ ```
1067
+
1068
+ *Constraints:* `T` and `U` satisfy `totally_ordered_with`.
1069
+
1070
+ *Effects:* Equivalent to:
1071
 
1072
  ``` cpp
1073
  return !ranges::less{}(std::forward<T>(t), std::forward<U>(u));
1074
  ```
1075
 
1076
  ``` cpp
1077
  struct ranges::less_equal {
1078
  template<class T, class U>
 
1079
  constexpr bool operator()(T&& t, U&& u) const;
1080
 
1081
  using is_transparent = unspecified;
1082
  };
1083
  ```
1084
 
1085
+ ``` cpp
1086
+ template<class T, class U>
1087
+ constexpr bool operator()(T&& t, U&& u) const;
1088
+ ```
1089
+
1090
+ *Constraints:* `T` and `U` satisfy `totally_ordered_with`.
1091
+
1092
+ *Effects:* Equivalent to:
1093
 
1094
  ``` cpp
1095
  return !ranges::less{}(std::forward<U>(u), std::forward<T>(t));
1096
  ```
1097
 
1098
  ### Logical operations <a id="logical.operations">[[logical.operations]]</a>
1099
 
1100
+ #### General <a id="logical.operations.general">[[logical.operations.general]]</a>
1101
+
1102
  The library provides basic function object classes for all of the
1103
+ logical operators in the language
1104
+ [[expr.log.and]], [[expr.log.or]], [[expr.unary.op]].
1105
 
1106
  #### Class template `logical_and` <a id="logical.operations.and">[[logical.operations.and]]</a>
1107
 
1108
  ``` cpp
1109
  template<class T = void> struct logical_and {
 
1193
 
1194
  *Returns:* `!std::forward<T>(t)`.
1195
 
1196
  ### Bitwise operations <a id="bitwise.operations">[[bitwise.operations]]</a>
1197
 
1198
+ #### General <a id="bitwise.operations.general">[[bitwise.operations.general]]</a>
1199
+
1200
  The library provides basic function object classes for all of the
1201
+ bitwise operators in the language
1202
+ [[expr.bit.and]], [[expr.or]], [[expr.xor]], [[expr.unary.op]].
1203
 
1204
  #### Class template `bit_and` <a id="bitwise.operations.and">[[bitwise.operations.and]]</a>
1205
 
1206
  ``` cpp
1207
  template<class T = void> struct bit_and {
 
1313
  using is_transparent = unspecified;
1314
  };
1315
  ```
1316
 
1317
  ``` cpp
1318
+ template<class T> constexpr auto operator()(T&& t) const
1319
  -> decltype(~std::forward<T>(t));
1320
  ```
1321
 
1322
  *Returns:* `~std::forward<T>(t)`.
1323
 
 
1355
  *Mandates:* `is_constructible_v<FD, F> && is_move_constructible_v<FD>`
1356
  is `true`.
1357
 
1358
  *Preconditions:* `FD` meets the *Cpp17MoveConstructible* requirements.
1359
 
1360
+ *Returns:* A perfect forwarding call
1361
+ wrapper [[term.perfect.forwarding.call.wrapper]] `g` with call pattern
1362
  `!invoke(fd, call_args...)`.
1363
 
1364
  *Throws:* Any exception thrown by the initialization of `fd`.
1365
 
1366
+ ### Function templates `bind_front` and `bind_back` <a id="func.bind.partial">[[func.bind.partial]]</a>
1367
 
1368
  ``` cpp
1369
  template<class F, class... Args>
1370
  constexpr unspecified bind_front(F&& f, Args&&... args);
1371
+ template<class F, class... Args>
1372
+ constexpr unspecified bind_back(F&& f, Args&&... args);
1373
  ```
1374
 
1375
+ Within this subclause:
1376
 
1377
+ - `g` is a value of the result of a `bind_front` or `bind_back`
1378
+ invocation,
1379
  - `FD` is the type `decay_t<F>`,
1380
  - `fd` is the target object of `g` [[func.def]] of type `FD`,
1381
  direct-non-list-initialized with `std::forward<F>(f)`,
1382
  - `BoundArgs` is a pack that denotes `decay_t<Args>...`,
1383
  - `bound_args` is a pack of bound argument entities of `g` [[func.def]]
 
1399
 
1400
  *Preconditions:* `FD` meets the *Cpp17MoveConstructible* requirements.
1401
  For each `Tᵢ` in `BoundArgs`, if `Tᵢ` is an object type, `Tᵢ` meets the
1402
  *Cpp17MoveConstructible* requirements.
1403
 
1404
+ *Returns:* A perfect forwarding call
1405
+ wrapper [[term.perfect.forwarding.call.wrapper]] `g` with call pattern:
1406
+
1407
+ - `invoke(fd, bound_args..., call_args...)` for a `bind_front`
1408
+ invocation, or
1409
+ - `invoke(fd, call_args..., bound_args...)` for a `bind_back`
1410
+ invocation.
1411
 
1412
  *Throws:* Any exception thrown by the initialization of the state
1413
  entities of `g` [[func.def]].
1414
 
1415
  ### Function object binders <a id="func.bind">[[func.bind]]</a>
1416
 
1417
+ #### General <a id="func.bind.general">[[func.bind.general]]</a>
1418
+
1419
+ Subclause [[func.bind]] describes a uniform mechanism for binding
1420
+ arguments of callable objects.
1421
 
1422
  #### Class template `is_bind_expression` <a id="func.bind.isbind">[[func.bind.isbind]]</a>
1423
 
1424
  ``` cpp
1425
  namespace std {
 
1447
  template<class T> struct is_placeholder; // see below
1448
  }
1449
  ```
1450
 
1451
  The class template `is_placeholder` can be used to detect the standard
1452
+ placeholders `_1`, `_2`, and so on [[func.bind.place]]. The function
1453
+ template `bind` uses `is_placeholder` to detect placeholders.
1454
 
1455
  Specializations of the `is_placeholder` template shall meet the
1456
  *Cpp17UnaryTypeTrait* requirements [[meta.rqmts]]. The implementation
1457
  provides a definition that has the base characteristic of
1458
  `integral_constant<int, J>` if `T` is the type of
 
1496
 
1497
  *Returns:* An argument forwarding call wrapper `g` [[func.require]]. A
1498
  program that attempts to invoke a volatile-qualified `g` is ill-formed.
1499
  When `g` is not volatile-qualified, invocation of
1500
  `g(``u₁``, ``u₂``, `…`, ``u_M``)` is
1501
+ expression-equivalent [[defns.expression.equivalent]] to
1502
 
1503
  ``` cpp
1504
  INVOKE(static_cast<$V_fd$>($v_fd$),
1505
  static_cast<$V_1$>($v_1$), static_cast<$V_2$>($v_2$), …, static_cast<$V_N$>($v_N$))
1506
  ```
 
1545
 
1546
  #### Placeholders <a id="func.bind.place">[[func.bind.place]]</a>
1547
 
1548
  ``` cpp
1549
  namespace std::placeholders {
1550
+ // M is the number of placeholders
1551
  see below _1;
1552
  see below _2;
1553
  .
1554
  .
1555
  .
1556
  see below _M;
1557
  }
1558
  ```
1559
 
1560
+ The number `M` of placeholders is *implementation-defined*.
1561
+
1562
  All placeholder types meet the *Cpp17DefaultConstructible* and
1563
  *Cpp17CopyConstructible* requirements, and their default constructors
1564
  and copy/move constructors are constexpr functions that do not throw
1565
  exceptions. It is *implementation-defined* whether placeholder types
1566
  meet the *Cpp17CopyAssignable* requirements, but if so, their copy
 
1577
 
1578
  ``` cpp
1579
  extern unspecified _1;
1580
  ```
1581
 
1582
+ Placeholders are freestanding items [[freestanding.item]].
1583
+
1584
  ### Function template `mem_fn` <a id="func.memfn">[[func.memfn]]</a>
1585
 
1586
  ``` cpp
1587
  template<class R, class T> constexpr unspecified mem_fn(R T::* pm) noexcept;
1588
  ```
1589
 
1590
+ *Returns:* A simple call wrapper [[term.simple.call.wrapper]] `fn` with
1591
+ call pattern `invoke(pmd, call_args...)`, where `pmd` is the target
1592
+ object of `fn` of type `R T::*` direct-non-list-initialized with `pm`,
1593
+ and `call_args` is an argument pack used in a function call
1594
+ expression [[expr.call]] of `fn`.
1595
 
1596
  ### Polymorphic function wrappers <a id="func.wrap">[[func.wrap]]</a>
1597
 
1598
+ #### General <a id="func.wrap.general">[[func.wrap.general]]</a>
1599
+
1600
+ Subclause [[func.wrap]] describes polymorphic wrapper classes that
1601
+ encapsulate arbitrary callable objects.
1602
 
1603
  #### Class `bad_function_call` <a id="func.wrap.badcall">[[func.wrap.badcall]]</a>
1604
 
1605
  An exception of type `bad_function_call` is thrown by
1606
  `function::operator()` [[func.wrap.func.inv]] when the function wrapper
 
1622
 
1623
  *Returns:* An *implementation-defined* NTBS.
1624
 
1625
  #### Class template `function` <a id="func.wrap.func">[[func.wrap.func]]</a>
1626
 
1627
+ ##### General <a id="func.wrap.func.general">[[func.wrap.func.general]]</a>
1628
+
1629
  ``` cpp
1630
  namespace std {
1631
  template<class> class function; // not defined
1632
 
1633
  template<class R, class... ArgTypes>
 
1638
  // [func.wrap.func.con], construct/copy/destroy
1639
  function() noexcept;
1640
  function(nullptr_t) noexcept;
1641
  function(const function&);
1642
  function(function&&) noexcept;
1643
+ template<class F> function(F&&);
1644
 
1645
  function& operator=(const function&);
1646
  function& operator=(function&&);
1647
  function& operator=(nullptr_t) noexcept;
1648
  template<class F> function& operator=(F&&);
 
1667
 
1668
  template<class R, class... ArgTypes>
1669
  function(R(*)(ArgTypes...)) -> function<R(ArgTypes...)>;
1670
 
1671
  template<class F> function(F) -> function<see below>;
 
 
 
 
 
 
 
 
1672
  }
1673
  ```
1674
 
1675
  The `function` class template provides polymorphic wrappers that
1676
  generalize the notion of a function pointer. Wrappers can store, copy,
1677
  and call arbitrary callable objects [[func.def]], given a call signature
1678
+ [[func.def]].
1679
 
1680
  A callable type [[func.def]] `F` is *Lvalue-Callable* for argument types
1681
  `ArgTypes` and return type `R` if the expression
1682
  `INVOKE<R>(declval<F&>(), declval<ArgTypes>()...)`, considered as an
1683
+ unevaluated operand [[term.unevaluated.operand]], is well-formed
1684
+ [[func.require]].
1685
 
1686
  The `function` class template is a call wrapper [[func.def]] whose call
1687
  signature [[func.def]] is `R(ArgTypes...)`.
1688
 
1689
+ [*Note 1*: The types deduced by the deduction guides for `function`
1690
+ might change in future revisions of C++. — *end note*]
1691
 
1692
  ##### Constructors and destructor <a id="func.wrap.func.con">[[func.wrap.func.con]]</a>
1693
 
1694
  ``` cpp
1695
  function() noexcept;
 
1705
 
1706
  ``` cpp
1707
  function(const function& f);
1708
  ```
1709
 
1710
+ *Ensures:* `!*this` if `!f`; otherwise, the target object of `*this` is
1711
+ a copy of `f.target()`.
1712
 
1713
  *Throws:* Nothing if `f`’s target is a specialization of
1714
  `reference_wrapper` or a function pointer. Otherwise, may throw
1715
  `bad_alloc` or any exception thrown by the copy constructor of the
1716
  stored callable object.
1717
 
1718
+ *Recommended practice:* Implementations should avoid the use of
1719
+ dynamically allocated memory for small callable objects, for example,
1720
+ where `f`’s target is an object holding only a pointer or reference to
1721
+ an object and a member function pointer.
1722
 
1723
  ``` cpp
1724
  function(function&& f) noexcept;
1725
  ```
1726
 
1727
  *Ensures:* If `!f`, `*this` has no target; otherwise, the target of
1728
  `*this` is equivalent to the target of `f` before the construction, and
1729
  `f` is in a valid state with an unspecified value.
1730
 
1731
+ *Recommended practice:* Implementations should avoid the use of
1732
+ dynamically allocated memory for small callable objects, for example,
1733
+ where `f`’s target is an object holding only a pointer or reference to
1734
+ an object and a member function pointer.
1735
 
1736
  ``` cpp
1737
+ template<class F> function(F&& f);
1738
  ```
1739
 
1740
+ Let `FD` be `decay_t<F>`.
 
1741
 
1742
+ *Constraints:*
1743
 
1744
+ - `is_same_v<remove_cvref_t<F>, function>` is `false`, and
1745
+ - `FD` is Lvalue-Callable [[func.wrap.func]] for argument types
1746
+ `ArgTypes...` and return type `R`.
1747
+
1748
+ *Mandates:*
1749
+
1750
+ - `is_copy_constructible_v<FD>` is `true`, and
1751
+ - `is_constructible_v<FD, F>` is `true`.
1752
+
1753
+ *Preconditions:* `FD` meets the *Cpp17CopyConstructible* requirements.
1754
+
1755
+ *Ensures:* `!*this` is `true` if any of the following hold:
1756
 
1757
  - `f` is a null function pointer value.
1758
  - `f` is a null member pointer value.
1759
+ - `remove_cvref_t<F>` is a specialization of the `function` class
1760
+ template, and `!f` is `true`.
1761
 
1762
+ Otherwise, `*this` has a target object of type `FD`
1763
+ direct-non-list-initialized with `std::forward<F>(f)`.
1764
 
1765
+ *Throws:* Nothing if `FD` is a specialization of `reference_wrapper` or
1766
+ a function pointer type. Otherwise, may throw `bad_alloc` or any
1767
+ exception thrown by the initialization of the target object.
 
1768
 
1769
+ *Recommended practice:* Implementations should avoid the use of
1770
+ dynamically allocated memory for small callable objects, for example,
1771
+ where `f` refers to an object holding only a pointer or reference to an
1772
+ object and a member function pointer.
1773
 
1774
  ``` cpp
1775
  template<class F> function(F) -> function<see below>;
1776
  ```
1777
 
1778
  *Constraints:* `&F::operator()` is well-formed when treated as an
1779
+ unevaluated operand and either
1780
+
1781
+ - `F::operator()` is a non-static member function and
1782
+ `decltype(&F::operator())` is either of the form
1783
+ `R(G::*)(A...)` cv \\ₒₚₜ ` `noexceptₒₚₜ or of the form
1784
+ `R(*)(G, A...) `noexceptₒₚₜ for a type `G`, or
1785
+ - `F::operator()` is a static member function and
1786
+ `decltype(&F::operator())` is of the form `R(*)(A...) `noexceptₒₚₜ .
1787
 
1788
  *Remarks:* The deduced type is `function<R(A...)>`.
1789
 
1790
  [*Example 1*:
1791
 
 
1853
 
1854
  ``` cpp
1855
  void swap(function& other) noexcept;
1856
  ```
1857
 
1858
+ *Effects:* Interchanges the target objects of `*this` and `other`.
1859
 
1860
  ##### Capacity <a id="func.wrap.func.cap">[[func.wrap.func.cap]]</a>
1861
 
1862
  ``` cpp
1863
  explicit operator bool() const noexcept;
 
1874
  *Returns:* *INVOKE*\<R\>(f,
1875
  std::forward\<ArgTypes\>(args)...) [[func.require]], where `f` is the
1876
  target object [[func.def]] of `*this`.
1877
 
1878
  *Throws:* `bad_function_call` if `!*this`; otherwise, any exception
1879
+ thrown by the target object.
1880
 
1881
  ##### Target access <a id="func.wrap.func.targ">[[func.wrap.func.targ]]</a>
1882
 
1883
  ``` cpp
1884
  const type_info& target_type() const noexcept;
 
1893
  ```
1894
 
1895
  *Returns:* If `target_type() == typeid(T)` a pointer to the stored
1896
  function target; otherwise a null pointer.
1897
 
1898
+ ##### Null pointer comparison operator functions <a id="func.wrap.func.nullptr">[[func.wrap.func.nullptr]]</a>
1899
 
1900
  ``` cpp
1901
  template<class R, class... ArgTypes>
1902
  bool operator==(const function<R(ArgTypes...)>& f, nullptr_t) noexcept;
1903
  ```
 
1911
  void swap(function<R(ArgTypes...)>& f1, function<R(ArgTypes...)>& f2) noexcept;
1912
  ```
1913
 
1914
  *Effects:* As if by: `f1.swap(f2);`
1915
 
1916
+ #### Move only wrapper <a id="func.wrap.move">[[func.wrap.move]]</a>
1917
+
1918
+ ##### General <a id="func.wrap.move.general">[[func.wrap.move.general]]</a>
1919
+
1920
+ The header provides partial specializations of `move_only_function` for
1921
+ each combination of the possible replacements of the placeholders cv,
1922
+ *ref*, and *noex* where
1923
+
1924
+ - cv is either const or empty,
1925
+ - *ref* is either `&`, `&&`, or empty, and
1926
+ - *noex* is either `true` or `false`.
1927
+
1928
+ For each of the possible combinations of the placeholders mentioned
1929
+ above, there is a placeholder *inv-quals* defined as follows:
1930
+
1931
+ - If *ref* is empty, let *inv-quals* be cv`&`,
1932
+ - otherwise, let *inv-quals* be cv *ref*.
1933
+
1934
+ ##### Class template `move_only_function` <a id="func.wrap.move.class">[[func.wrap.move.class]]</a>
1935
+
1936
+ ``` cpp
1937
+ namespace std {
1938
+ template<class... S> class move_only_function; // not defined
1939
+
1940
+ template<class R, class... ArgTypes>
1941
+ class move_only_function<R(ArgTypes...) cv ref noexcept(noex)> {
1942
+ public:
1943
+ using result_type = R;
1944
+
1945
+ // [func.wrap.move.ctor], constructors, assignment, and destructor
1946
+ move_only_function() noexcept;
1947
+ move_only_function(nullptr_t) noexcept;
1948
+ move_only_function(move_only_function&&) noexcept;
1949
+ template<class F> move_only_function(F&&);
1950
+ template<class T, class... Args>
1951
+ explicit move_only_function(in_place_type_t<T>, Args&&...);
1952
+ template<class T, class U, class... Args>
1953
+ explicit move_only_function(in_place_type_t<T>, initializer_list<U>, Args&&...);
1954
+
1955
+ move_only_function& operator=(move_only_function&&);
1956
+ move_only_function& operator=(nullptr_t) noexcept;
1957
+ template<class F> move_only_function& operator=(F&&);
1958
+
1959
+ ~move_only_function();
1960
+
1961
+ // [func.wrap.move.inv], invocation
1962
+ explicit operator bool() const noexcept;
1963
+ R operator()(ArgTypes...) cv ref noexcept(noex);
1964
+
1965
+ // [func.wrap.move.util], utility
1966
+ void swap(move_only_function&) noexcept;
1967
+ friend void swap(move_only_function&, move_only_function&) noexcept;
1968
+ friend bool operator==(const move_only_function&, nullptr_t) noexcept;
1969
+
1970
+ private:
1971
+ template<class VT>
1972
+ static constexpr bool is-callable-from = see below; // exposition only
1973
+ };
1974
+ }
1975
+ ```
1976
+
1977
+ The `move_only_function` class template provides polymorphic wrappers
1978
+ that generalize the notion of a callable object [[func.def]]. These
1979
+ wrappers can store, move, and call arbitrary callable objects, given a
1980
+ call signature.
1981
+
1982
+ *Recommended practice:* Implementations should avoid the use of
1983
+ dynamically allocated memory for a small contained value.
1984
+
1985
+ [*Note 1*: Such small-object optimization can only be applied to a type
1986
+ `T` for which `is_nothrow_move_constructible_v<T>` is
1987
+ `true`. — *end note*]
1988
+
1989
+ ##### Constructors, assignment, and destructor <a id="func.wrap.move.ctor">[[func.wrap.move.ctor]]</a>
1990
+
1991
+ ``` cpp
1992
+ template<class VT>
1993
+ static constexpr bool is-callable-from = see below;
1994
+ ```
1995
+
1996
+ If *noex* is `true`, *`is-callable-from`*`<VT>` is equal to:
1997
+
1998
+ ``` cpp
1999
+ is_nothrow_invocable_r_v<R, VT cv ref, ArgTypes...> &&
2000
+ is_nothrow_invocable_r_v<R, VT inv-quals, ArgTypes...>
2001
+ ```
2002
+
2003
+ Otherwise, *`is-callable-from`*`<VT>` is equal to:
2004
+
2005
+ ``` cpp
2006
+ is_invocable_r_v<R, VT cv ref, ArgTypes...> &&
2007
+ is_invocable_r_v<R, VT inv-quals, ArgTypes...>
2008
+ ```
2009
+
2010
+ ``` cpp
2011
+ move_only_function() noexcept;
2012
+ move_only_function(nullptr_t) noexcept;
2013
+ ```
2014
+
2015
+ *Ensures:* `*this` has no target object.
2016
+
2017
+ ``` cpp
2018
+ move_only_function(move_only_function&& f) noexcept;
2019
+ ```
2020
+
2021
+ *Ensures:* The target object of `*this` is the target object `f` had
2022
+ before construction, and `f` is in a valid state with an unspecified
2023
+ value.
2024
+
2025
+ ``` cpp
2026
+ template<class F> move_only_function(F&& f);
2027
+ ```
2028
+
2029
+ Let `VT` be `decay_t<F>`.
2030
+
2031
+ *Constraints:*
2032
+
2033
+ - `remove_cvref_t<F>` is not the same type as `move_only_function`, and
2034
+ - `remove_cvref_t<F>` is not a specialization of `in_place_type_t`, and
2035
+ - *`is-callable-from`*`<VT>` is `true`.
2036
+
2037
+ *Mandates:* `is_constructible_v<VT, F>` is `true`.
2038
+
2039
+ *Preconditions:* `VT` meets the *Cpp17Destructible* requirements, and if
2040
+ `is_move_constructible_v<VT>` is `true`, `VT` meets the
2041
+ *Cpp17MoveConstructible* requirements.
2042
+
2043
+ *Ensures:* `*this` has no target object if any of the following hold:
2044
+
2045
+ - `f` is a null function pointer value, or
2046
+ - `f` is a null member pointer value, or
2047
+ - `remove_cvref_t<F>` is a specialization of the `move_only_function`
2048
+ class template, and `f` has no target object.
2049
+
2050
+ Otherwise, `*this` has a target object of type `VT`
2051
+ direct-non-list-initialized with `std::forward<F>(f)`.
2052
+
2053
+ *Throws:* Any exception thrown by the initialization of the target
2054
+ object. May throw `bad_alloc` unless `VT` is a function pointer or a
2055
+ specialization of `reference_wrapper`.
2056
+
2057
+ ``` cpp
2058
+ template<class T, class... Args>
2059
+ explicit move_only_function(in_place_type_t<T>, Args&&... args);
2060
+ ```
2061
+
2062
+ Let `VT` be `decay_t<T>`.
2063
+
2064
+ *Constraints:*
2065
+
2066
+ - `is_constructible_v<VT, Args...>` is `true`, and
2067
+ - *`is-callable-from`*`<VT>` is `true`.
2068
+
2069
+ *Mandates:* `VT` is the same type as `T`.
2070
+
2071
+ *Preconditions:* `VT` meets the *Cpp17Destructible* requirements, and if
2072
+ `is_move_constructible_v<VT>` is `true`, `VT` meets the
2073
+ *Cpp17MoveConstructible* requirements.
2074
+
2075
+ *Ensures:* `*this` has a target object of type `VT`
2076
+ direct-non-list-initialized with `std::forward<Args>(args)...`.
2077
+
2078
+ *Throws:* Any exception thrown by the initialization of the target
2079
+ object. May throw `bad_alloc` unless `VT` is a function pointer or a
2080
+ specialization of `reference_wrapper`.
2081
+
2082
+ ``` cpp
2083
+ template<class T, class U, class... Args>
2084
+ explicit move_only_function(in_place_type_t<T>, initializer_list<U> ilist, Args&&... args);
2085
+ ```
2086
+
2087
+ Let `VT` be `decay_t<T>`.
2088
+
2089
+ *Constraints:*
2090
+
2091
+ - `is_constructible_v<VT, initializer_list<U>&, Args...>` is `true`, and
2092
+ - *`is-callable-from`*`<VT>` is `true`.
2093
+
2094
+ *Mandates:* `VT` is the same type as `T`.
2095
+
2096
+ *Preconditions:* `VT` meets the *Cpp17Destructible* requirements, and if
2097
+ `is_move_constructible_v<VT>` is `true`, `VT` meets the
2098
+ *Cpp17MoveConstructible* requirements.
2099
+
2100
+ *Ensures:* `*this` has a target object of type `VT`
2101
+ direct-non-list-initialized with `ilist, std::forward<Args>(args)...`.
2102
+
2103
+ *Throws:* Any exception thrown by the initialization of the target
2104
+ object. May throw `bad_alloc` unless `VT` is a function pointer or a
2105
+ specialization of `reference_wrapper`.
2106
+
2107
+ ``` cpp
2108
+ move_only_function& operator=(move_only_function&& f);
2109
+ ```
2110
+
2111
+ *Effects:* Equivalent to:
2112
+ `move_only_function(std::move(f)).swap(*this);`
2113
+
2114
+ *Returns:* `*this`.
2115
+
2116
+ ``` cpp
2117
+ move_only_function& operator=(nullptr_t) noexcept;
2118
+ ```
2119
+
2120
+ *Effects:* Destroys the target object of `*this`, if any.
2121
+
2122
+ *Returns:* `*this`.
2123
+
2124
+ ``` cpp
2125
+ template<class F> move_only_function& operator=(F&& f);
2126
+ ```
2127
+
2128
+ *Effects:* Equivalent to:
2129
+ `move_only_function(std::forward<F>(f)).swap(*this);`
2130
+
2131
+ *Returns:* `*this`.
2132
+
2133
+ ``` cpp
2134
+ ~move_only_function();
2135
+ ```
2136
+
2137
+ *Effects:* Destroys the target object of `*this`, if any.
2138
+
2139
+ ##### Invocation <a id="func.wrap.move.inv">[[func.wrap.move.inv]]</a>
2140
+
2141
+ ``` cpp
2142
+ explicit operator bool() const noexcept;
2143
+ ```
2144
+
2145
+ *Returns:* `true` if `*this` has a target object, otherwise `false`.
2146
+
2147
+ ``` cpp
2148
+ R operator()(ArgTypes... args) cv ref noexcept(noex);
2149
+ ```
2150
+
2151
+ *Preconditions:* `*this` has a target object.
2152
+
2153
+ *Effects:* Equivalent to:
2154
+
2155
+ ``` cpp
2156
+ return INVOKE<R>(static_cast<F inv-quals>(f), std::forward<ArgTypes>(args)...);
2157
+ ```
2158
+
2159
+ where `f` is an lvalue designating the target object of `*this` and `F`
2160
+ is the type of `f`.
2161
+
2162
+ ##### Utility <a id="func.wrap.move.util">[[func.wrap.move.util]]</a>
2163
+
2164
+ ``` cpp
2165
+ void swap(move_only_function& other) noexcept;
2166
+ ```
2167
+
2168
+ *Effects:* Exchanges the target objects of `*this` and `other`.
2169
+
2170
+ ``` cpp
2171
+ friend void swap(move_only_function& f1, move_only_function& f2) noexcept;
2172
+ ```
2173
+
2174
+ *Effects:* Equivalent to `f1.swap(f2)`.
2175
+
2176
+ ``` cpp
2177
+ friend bool operator==(const move_only_function& f, nullptr_t) noexcept;
2178
+ ```
2179
+
2180
+ *Returns:* `true` if `f` has no target object, otherwise `false`.
2181
+
2182
  ### Searchers <a id="func.search">[[func.search]]</a>
2183
 
2184
+ #### General <a id="func.search.general">[[func.search.general]]</a>
 
 
 
 
 
2185
 
2186
+ Subclause [[func.search]] provides function object types
2187
+ [[function.objects]] for operations that search for a sequence
2188
+ \[`pat``first`, `pat_last`) in another sequence \[`first`, `last`) that
2189
+ is provided to the object’s function call operator. The first sequence
2190
+ (the pattern to be searched for) is provided to the object’s
2191
+ constructor, and the second (the sequence to be searched) is provided to
2192
+ the function call operator.
2193
+
2194
+ Each specialization of a class template specified in [[func.search]]
2195
+ shall meet the *Cpp17CopyConstructible* and *Cpp17CopyAssignable*
2196
+ requirements. Template parameters named
2197
 
2198
  - `ForwardIterator`,
2199
  - `ForwardIterator1`,
2200
  - `ForwardIterator2`,
2201
  - `RandomAccessIterator`,
2202
  - `RandomAccessIterator1`,
2203
  - `RandomAccessIterator2`, and
2204
  - `BinaryPredicate`
2205
 
2206
+ of templates specified in [[func.search]] shall meet the same
2207
+ requirements and semantics as specified in [[algorithms.general]].
2208
  Template parameters named `Hash` shall meet the *Cpp17Hash* requirements
2209
  ([[cpp17.hash]]).
2210
 
2211
  The Boyer-Moore searcher implements the Boyer-Moore search algorithm.
2212
  The Boyer-Moore-Horspool searcher implements the Boyer-Moore-Horspool
 
2214
  memory and give better runtime performance than Boyer-Moore-Horspool.
2215
 
2216
  #### Class template `default_searcher` <a id="func.search.default">[[func.search.default]]</a>
2217
 
2218
  ``` cpp
2219
+ namespace std {
2220
  template<class ForwardIterator1, class BinaryPredicate = equal_to<>>
2221
  class default_searcher {
2222
  public:
2223
  constexpr default_searcher(ForwardIterator1 pat_first, ForwardIterator1 pat_last,
2224
  BinaryPredicate pred = BinaryPredicate());
 
2230
  private:
2231
  ForwardIterator1 pat_first_; // exposition only
2232
  ForwardIterator1 pat_last_; // exposition only
2233
  BinaryPredicate pred_; // exposition only
2234
  };
2235
+ }
2236
  ```
2237
 
2238
  ``` cpp
2239
+ constexpr default_searcher(ForwardIterator1 pat_first, ForwardIterator1 pat_last,
2240
  BinaryPredicate pred = BinaryPredicate());
2241
  ```
2242
 
2243
  *Effects:* Constructs a `default_searcher` object, initializing
2244
  `pat_first_` with `pat_first`, \texttt{pat_last\_} with `pat_last`, and
 
2260
  `j == next(i, distance(pat_first_, pat_last_))`.
2261
 
2262
  #### Class template `boyer_moore_searcher` <a id="func.search.bm">[[func.search.bm]]</a>
2263
 
2264
  ``` cpp
2265
+ namespace std {
2266
  template<class RandomAccessIterator1,
2267
  class Hash = hash<typename iterator_traits<RandomAccessIterator1>::value_type>,
2268
  class BinaryPredicate = equal_to<>>
2269
  class boyer_moore_searcher {
2270
  public:
 
2281
  RandomAccessIterator1 pat_first_; // exposition only
2282
  RandomAccessIterator1 pat_last_; // exposition only
2283
  Hash hash_; // exposition only
2284
  BinaryPredicate pred_; // exposition only
2285
  };
2286
+ }
2287
  ```
2288
 
2289
  ``` cpp
2290
  boyer_moore_searcher(RandomAccessIterator1 pat_first,
2291
  RandomAccessIterator1 pat_last,
2292
  Hash hf = Hash(),
2293
  BinaryPredicate pred = BinaryPredicate());
2294
  ```
2295
 
2296
  *Preconditions:* The value type of `RandomAccessIterator1` meets the
2297
+ *Cpp17DefaultConstructible*, the *Cpp17CopyConstructible*, and the
2298
+ *Cpp17CopyAssignable* requirements.
2299
 
2300
+ Let `V` be `iterator_traits<RandomAccessIterator1>::value_type`. For any
2301
+ two values `A` and `B` of type `V`, if `pred(A, B) == true`, then
2302
+ `hf(A) == hf(B)` is `true`.
 
2303
 
2304
  *Effects:* Initializes `pat_first_` with `pat_first`, `pat_last_` with
2305
+ `pat_last`, `hash_` with `hf`, and \texttt{pred\_} with `pred`.
2306
 
2307
  *Throws:* Any exception thrown by the copy constructor of
2308
  `RandomAccessIterator1`, or by the default constructor, copy
2309
  constructor, or the copy assignment operator of the value type of
2310
  `RandomAccessIterator1`, or the copy constructor or `operator()` of
 
2338
  applications of the predicate.
2339
 
2340
  #### Class template `boyer_moore_horspool_searcher` <a id="func.search.bmh">[[func.search.bmh]]</a>
2341
 
2342
  ``` cpp
2343
+ namespace std {
2344
  template<class RandomAccessIterator1,
2345
  class Hash = hash<typename iterator_traits<RandomAccessIterator1>::value_type>,
2346
  class BinaryPredicate = equal_to<>>
2347
  class boyer_moore_horspool_searcher {
2348
  public:
 
2359
  RandomAccessIterator1 pat_first_; // exposition only
2360
  RandomAccessIterator1 pat_last_; // exposition only
2361
  Hash hash_; // exposition only
2362
  BinaryPredicate pred_; // exposition only
2363
  };
2364
+ }
2365
  ```
2366
 
2367
  ``` cpp
2368
  boyer_moore_horspool_searcher(RandomAccessIterator1 pat_first,
2369
  RandomAccessIterator1 pat_last,
 
2373
 
2374
  *Preconditions:* The value type of `RandomAccessIterator1` meets the
2375
  *Cpp17DefaultConstructible*, *Cpp17CopyConstructible*, and
2376
  *Cpp17CopyAssignable* requirements.
2377
 
2378
+ Let `V` be `iterator_traits<RandomAccessIterator1>::value_type`. For any
2379
+ two values `A` and `B` of type `V`, if `pred(A, B) == true`, then
2380
+ `hf(A) == hf(B)` is `true`.
 
2381
 
2382
  *Effects:* Initializes `pat_first_` with `pat_first`, `pat_last_` with
2383
+ `pat_last`, `hash_` with `hf`, and \texttt{pred\_} with `pred`.
2384
 
2385
  *Throws:* Any exception thrown by the copy constructor of
2386
  `RandomAccessIterator1`, or by the default constructor, copy
2387
  constructor, or the copy assignment operator of the value type of
2388
+ `RandomAccessIterator1`, or the copy constructor or `operator()` of
2389
  `BinaryPredicate` or `Hash`. May throw `bad_alloc` if additional memory
2390
  needed for internal data structures cannot be allocated.
2391
 
2392
  ``` cpp
2393
  template<class RandomAccessIterator2>
 
2400
 
2401
  *Effects:* Finds a subsequence of equal values in a sequence.
2402
 
2403
  *Returns:* A pair of iterators `i` and `j` such that
2404
 
2405
+ - `i` is the first iterator in the range \[`first`,
2406
  `last - (pat_last_ - pat_first_)`) such that for every non-negative
2407
  integer `n` less than `pat_last_ - pat_first_` the following condition
2408
  holds: `pred(*(i + n), *(pat_first_ + n)) != false`, and
2409
  - `j == next(i, distance(pat_first_, pat_last_))`.
2410
 
 
2449
  An enabled specialization `hash<Key>` will:
2450
 
2451
  - meet the *Cpp17Hash* requirements ([[cpp17.hash]]), with `Key` as the
2452
  function call argument type, the *Cpp17DefaultConstructible*
2453
  requirements ([[cpp17.defaultconstructible]]), the
2454
+ *Cpp17CopyAssignable* requirements ([[cpp17.copyassignable]]), the
2455
+ *Cpp17Swappable* requirements [[swappable.requirements]],
2456
  - meet the requirement that if `k1 == k2` is `true`, `h(k1) == h(k2)` is
2457
  also `true`, where `h` is an object of type `hash<Key>` and `k1` and
2458
  `k2` are objects of type `Key`;
2459
  - meet the requirement that the expression `h(k)`, where `h` is an
2460
  object of type `hash<Key>` and `k` is an object of type `Key`, shall
2461
  not throw an exception unless `hash<Key>` is a program-defined
2462
+ specialization.
2463