From Jason Turner

[function.objects]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp0oxzndr8/{from.md → to.md} +1014 -648
tmp/tmp0oxzndr8/{from.md → to.md} RENAMED
@@ -8,28 +8,31 @@ to pass a pointer to a function to an algorithmic template (Clause 
8
  [[algorithms]]), the interface is specified to accept a function object.
9
  This not only makes algorithmic templates work with pointers to
10
  functions, but also enables them to work with arbitrary function
11
  objects.
12
 
 
 
13
  ``` cpp
14
  namespace std {
15
- // [depr.base], base (deprecated):
16
- template <class Arg, class Result> struct unary_function;
17
- template <class Arg1, class Arg2, class Result> struct binary_function;
 
18
 
19
- // [refwrap], reference_wrapper:
20
  template <class T> class reference_wrapper;
21
 
22
  template <class T> reference_wrapper<T> ref(T&) noexcept;
23
  template <class T> reference_wrapper<const T> cref(const T&) noexcept;
24
  template <class T> void ref(const T&&) = delete;
25
  template <class T> void cref(const T&&) = delete;
26
 
27
  template <class T> reference_wrapper<T> ref(reference_wrapper<T>) noexcept;
28
  template <class T> reference_wrapper<const T> cref(reference_wrapper<T>) noexcept;
29
 
30
- // [arithmetic.operations], arithmetic operations:
31
  template <class T = void> struct plus;
32
  template <class T = void> struct minus;
33
  template <class T = void> struct multiplies;
34
  template <class T = void> struct divides;
35
  template <class T = void> struct modulus;
@@ -39,11 +42,11 @@ namespace std {
39
  template <> struct multiplies<void>;
40
  template <> struct divides<void>;
41
  template <> struct modulus<void>;
42
  template <> struct negate<void>;
43
 
44
- // [comparisons], comparisons:
45
  template <class T = void> struct equal_to;
46
  template <class T = void> struct not_equal_to;
47
  template <class T = void> struct greater;
48
  template <class T = void> struct less;
49
  template <class T = void> struct greater_equal;
@@ -53,168 +56,119 @@ namespace std {
53
  template <> struct greater<void>;
54
  template <> struct less<void>;
55
  template <> struct greater_equal<void>;
56
  template <> struct less_equal<void>;
57
 
58
- // [logical.operations], logical operations:
59
  template <class T = void> struct logical_and;
60
  template <class T = void> struct logical_or;
61
  template <class T = void> struct logical_not;
62
  template <> struct logical_and<void>;
63
  template <> struct logical_or<void>;
64
  template <> struct logical_not<void>;
65
 
66
- // [bitwise.operations], bitwise operations:
67
  template <class T = void> struct bit_and;
68
  template <class T = void> struct bit_or;
69
  template <class T = void> struct bit_xor;
70
  template <class T = void> struct bit_not;
71
  template <> struct bit_and<void>;
72
  template <> struct bit_or<void>;
73
  template <> struct bit_xor<void>;
74
  template <> struct bit_not<void>;
75
 
76
- // [negators], negators:
77
- template <class Predicate> class unary_negate;
78
- template <class Predicate>
79
- constexpr unary_negate<Predicate> not1(const Predicate&);
80
- template <class Predicate> class binary_negate;
81
- template <class Predicate>
82
- constexpr binary_negate<Predicate> not2(const Predicate&);
83
 
84
- // [func.bind], bind:
85
  template<class T> struct is_bind_expression;
86
  template<class T> struct is_placeholder;
87
 
88
  template<class F, class... BoundArgs>
89
  unspecified bind(F&&, BoundArgs&&...);
90
  template<class R, class F, class... BoundArgs>
91
  unspecified bind(F&&, BoundArgs&&...);
92
 
93
  namespace placeholders {
94
  // M is the implementation-defined number of placeholders
95
- extern unspecified _1;
96
- extern unspecified _2;
97
  .
98
  .
99
  .
100
- extern unspecified _M;
101
  }
102
 
103
- // [depr.lib.binders], binders (deprecated):
104
- template <class Fn> class binder1st;
105
- template <class Fn, class T>
106
- binder1st<Fn> bind1st(const Fn&, const T&);
107
- template <class Fn> class binder2nd;
108
- template <class Fn, class T>
109
- binder2nd<Fn> bind2nd(const Fn&, const T&);
110
 
111
- // [depr.function.pointer.adaptors], adaptors (deprecated):
112
- template <class Arg, class Result> class pointer_to_unary_function;
113
- template <class Arg, class Result>
114
- pointer_to_unary_function<Arg,Result> ptr_fun(Result (*)(Arg));
115
- template <class Arg1, class Arg2, class Result>
116
- class pointer_to_binary_function;
117
- template <class Arg1, class Arg2, class Result>
118
- pointer_to_binary_function<Arg1,Arg2,Result>
119
- ptr_fun(Result (*)(Arg1,Arg2));
120
-
121
- // [depr.member.pointer.adaptors], adaptors (deprecated):
122
- template<class S, class T> class mem_fun_t;
123
- template<class S, class T, class A> class mem_fun1_t;
124
- template<class S, class T>
125
- mem_fun_t<S,T> mem_fun(S (T::*f)());
126
- template<class S, class T, class A>
127
- mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A));
128
- template<class S, class T> class mem_fun_ref_t;
129
- template<class S, class T, class A> class mem_fun1_ref_t;
130
- template<class S, class T>
131
- mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)());
132
- template<class S, class T, class A>
133
- mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A));
134
-
135
- template <class S, class T> class const_mem_fun_t;
136
- template <class S, class T, class A> class const_mem_fun1_t;
137
- template <class S, class T>
138
- const_mem_fun_t<S,T> mem_fun(S (T::*f)() const);
139
- template <class S, class T, class A>
140
- const_mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A) const);
141
- template <class S, class T> class const_mem_fun_ref_t;
142
- template <class S, class T, class A> class const_mem_fun1_ref_t;
143
- template <class S, class T>
144
- const_mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)() const);
145
- template <class S, class T, class A>
146
- const_mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A) const);
147
-
148
- // [func.memfn], member function adaptors:
149
- template<class R, class T> unspecified mem_fn(R T::*);
150
-
151
- // [func.wrap] polymorphic function wrappers:
152
  class bad_function_call;
153
 
154
- template<class> class function; // undefined
155
  template<class R, class... ArgTypes> class function<R(ArgTypes...)>;
156
 
157
  template<class R, class... ArgTypes>
158
- void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&);
159
 
160
  template<class R, class... ArgTypes>
161
- bool operator==(const function<R(ArgTypes...)>&, nullptr_t);
162
  template<class R, class... ArgTypes>
163
- bool operator==(nullptr_t, const function<R(ArgTypes...)>&);
164
  template<class R, class... ArgTypes>
165
- bool operator!=(const function<R(ArgTypes...)>&, nullptr_t);
166
  template<class R, class... ArgTypes>
167
- bool operator!=(nullptr_t, const function<R(ArgTypes...)>&);
168
 
169
- // [unord.hash], hash function primary template:
170
- template <class T> struct hash;
 
171
 
172
- // Hash function specializations
173
- template <> struct hash<bool>;
174
- template <> struct hash<char>;
175
- template <> struct hash<signed char>;
176
- template <> struct hash<unsigned char>;
177
- template <> struct hash<char16_t>;
178
- template <> struct hash<char32_t>;
179
- template <> struct hash<wchar_t>;
180
- template <> struct hash<short>;
181
- template <> struct hash<unsigned short>;
182
- template <> struct hash<int>;
183
- template <> struct hash<unsigned int>;
184
- template <> struct hash<long>;
185
- template <> struct hash<long long>;
186
- template <> struct hash<unsigned long>;
187
- template <> struct hash<unsigned long long>;
188
 
189
- template <> struct hash<float>;
190
- template <> struct hash<double>;
191
- template <> struct hash<long double>;
 
192
 
193
- template<class T> struct hash<T*>;
 
 
 
 
 
 
 
 
194
  }
195
  ```
196
 
 
 
197
  If a C++program wants to have a by-element addition of two vectors `a`
198
  and `b` containing `double` and put the result into `a`, it can do:
199
 
200
  ``` cpp
201
  transform(a.begin(), a.end(), b.begin(), a.begin(), plus<double>());
202
  ```
203
 
 
 
 
 
204
  To negate every element of `a`:
205
 
206
  ``` cpp
207
  transform(a.begin(), a.end(), a.begin(), negate<double>());
208
  ```
209
 
210
- To enable adaptors and other components to manipulate function objects
211
- that take one or two arguments many of the function objects in this
212
- clause correspondingly provide typedefs `argument_type` and
213
- `result_type` for function objects that take one argument and
214
- `first_argument_type`, `second_argument_type`, and `result_type` for
215
- function objects that take two arguments.
216
 
217
  ### Definitions <a id="func.def">[[func.def]]</a>
218
 
219
  The following definitions apply to this Clause:
220
 
@@ -236,67 +190,70 @@ A *target object* is the callable object held by a call wrapper.
236
  ### Requirements <a id="func.require">[[func.require]]</a>
237
 
238
  Define `INVOKE(f, t1, t2, ..., tN)` as follows:
239
 
240
  - `(t1.*f)(t2, ..., tN)` when `f` is a pointer to a member function of a
241
- class `T` and `t1` is an object of type `T` or a reference to an
242
- object of type `T` or a reference to an object of a type derived from
243
- `T`;
 
244
  - `((*t1).*f)(t2, ..., tN)` when `f` is a pointer to a member function
245
- of a class `T` and `t1` is not one of the types described in the
246
- previous item;
247
- - `t1.*f` when `N == 1` and `f` is a pointer to member data of a class
248
- `T` and `t1` is an object of type `T` or a reference to an object of
249
- type `T` or a reference to an object of a type derived from `T`;
250
- - `(*t1).*f` when `N == 1` and `f` is a pointer to member data of a
251
- class `T` and `t1` is not one of the types described in the previous
252
- item;
253
  - `f(t1, t2, ..., tN)` in all other cases.
254
 
255
- Define `INVOKE(f, t1, t2, ..., tN, R)` as `INVOKE(f, t1, t2, ..., tN)`
256
- implicitly converted to `R`.
257
-
258
- If a call wrapper ([[func.def]]) has a *weak result type* the type of
259
- its member type `result_type` is based on the type `T` of the wrapper’s
260
- target object ([[func.def]]):
261
-
262
- - if `T` is a pointer to function type, `result_type` shall be a synonym
263
- for the return type of `T`;
264
- - if `T` is a pointer to member function, `result_type` shall be a
265
- synonym for the return type of `T`;
266
- - if `T` is a class type with a member type `result_type`, then
267
- `result_type` shall be a synonym for `T::result_type`;
268
- - otherwise `result_type` shall not be defined.
269
 
270
  Every call wrapper ([[func.def]]) shall be `MoveConstructible`. A
271
- *simple call wrapper* is a call wrapper that is `CopyConstructible` and
272
- `CopyAssignable` and whose copy constructor, move constructor, and
273
- assignment operator do not throw exceptions. A *forwarding call wrapper*
274
- is a call wrapper that can be called with an arbitrary argument list and
275
- delivers the arguments to the wrapped callable object as references.
276
- This forwarding step shall ensure that rvalue arguments are delivered as
277
- rvalue-references and lvalue arguments are delivered as
278
- lvalue-references. In a typical implementation forwarding call wrappers
279
- have an overloaded function call operator of the form
 
 
 
 
280
 
281
  ``` cpp
282
  template<class... UnBoundArgs>
283
  R operator()(UnBoundArgs&&... unbound_args) cv-qual;
284
  ```
285
 
 
 
 
 
 
 
 
 
 
 
 
 
 
286
  ### Class template `reference_wrapper` <a id="refwrap">[[refwrap]]</a>
287
 
288
  ``` cpp
289
  namespace std {
290
  template <class T> class reference_wrapper {
291
  public :
292
  // types
293
- typedef T type;
294
- typedef see below result_type; // not always defined
295
- typedef see below argument_type; // not always defined
296
- typedef see below first_argument_type; // not always defined
297
- typedef see below second_argument_type; // not always defined
298
 
299
  // construct/copy/destroy
300
  reference_wrapper(T&) noexcept;
301
  reference_wrapper(T&&) = delete; // do not bind to temporary objects
302
  reference_wrapper(const reference_wrapper& x) noexcept;
@@ -308,46 +265,24 @@ namespace std {
308
  operator T& () const noexcept;
309
  T& get() const noexcept;
310
 
311
  // invocation
312
  template <class... ArgTypes>
313
- result_of_t<T&(ArgTypes&&...)>
314
  operator() (ArgTypes&&...) const;
315
  };
 
 
 
316
  }
317
  ```
318
 
319
  `reference_wrapper<T>` is a `CopyConstructible` and `CopyAssignable`
320
  wrapper around a reference to an object or function of type `T`.
321
 
322
- `reference_wrapper<T>` has a weak result type ([[func.require]]). If
323
- `T` is a function type, `result_type` shall be a synonym for the return
324
- type of `T`.
325
-
326
- The template specialization `reference_wrapper<T>` shall define a nested
327
- type named `argument_type` as a synonym for `T1` only if the type `T` is
328
- any of the following:
329
-
330
- - a function type or a pointer to function type taking one argument of
331
- type `T1`
332
- - a pointer to member function `R T0::f` *cv* (where *cv* represents the
333
- member function’s cv-qualifiers); the type `T1` is *cv* `T0*`
334
- - a class type with a member type `argument_type`; the type `T1` is
335
- `T::argument_type`.
336
-
337
- The template instantiation `reference_wrapper<T>` shall define two
338
- nested types named `first_argument_type` and `second_argument_type` as
339
- synonyms for `T1` and `T2`, respectively, only if the type `T` is any of
340
- the following:
341
-
342
- - a function type or a pointer to function type taking two arguments of
343
- types `T1` and `T2`
344
- - a pointer to member function `R T0::f(T2)` *cv* (where *cv* represents
345
- the member function’s cv-qualifiers); the type `T1` is *cv* `T0*`
346
- - a class type with member types `first_argument_type` and
347
- `second_argument_type`; the type `T1` is `T::first_argument_type` and
348
- the type `T2` is `T::second_argument_type`.
349
 
350
  #### `reference_wrapper` construct/copy/destroy <a id="refwrap.const">[[refwrap.const]]</a>
351
 
352
  ``` cpp
353
  reference_wrapper(T& t) noexcept;
@@ -383,539 +318,735 @@ operator T& () const noexcept;
383
  T& get() const noexcept;
384
  ```
385
 
386
  *Returns:* The stored reference.
387
 
388
- #### reference_wrapper invocation <a id="refwrap.invoke">[[refwrap.invoke]]</a>
389
 
390
  ``` cpp
391
  template <class... ArgTypes>
392
- result_of_t<T&(ArgTypes&&... )>
393
  operator()(ArgTypes&&... args) const;
394
  ```
395
 
396
- *Returns:*
397
- *`INVOKE`*`(get(), std::forward<ArgTypes>(args)...)`. ([[func.require]])
398
 
399
- `operator()` is described for exposition only. Implementations are not
400
- required to provide an actual `reference_wrapper::operator()`.
401
- Implementations are permitted to support `reference_wrapper` function
402
- invocation through multiple overloaded operators or through other means.
403
-
404
- #### reference_wrapper helper functions <a id="refwrap.helpers">[[refwrap.helpers]]</a>
405
 
406
  ``` cpp
407
  template <class T> reference_wrapper<T> ref(T& t) noexcept;
408
  ```
409
 
410
- *Returns:* `reference_wrapper<T>(t)`
411
 
412
  ``` cpp
413
  template <class T> reference_wrapper<T> ref(reference_wrapper<T> t) noexcept;
414
  ```
415
 
416
- *Returns:* `ref(t.get())`
417
 
418
  ``` cpp
419
  template <class T> reference_wrapper<const T> cref(const T& t) noexcept;
420
  ```
421
 
422
- *Returns:* `reference_wrapper <const T>(t)`
423
 
424
  ``` cpp
425
  template <class T> reference_wrapper<const T> cref(reference_wrapper<T> t) noexcept;
426
  ```
427
 
428
- *Returns:* `cref(t.get());`
429
 
430
  ### Arithmetic operations <a id="arithmetic.operations">[[arithmetic.operations]]</a>
431
 
432
  The library provides basic function object classes for all of the
433
  arithmetic operators in the language ([[expr.mul]], [[expr.add]]).
434
 
 
 
435
  ``` cpp
436
  template <class T = void> struct plus {
437
  constexpr T operator()(const T& x, const T& y) const;
438
- typedef T first_argument_type;
439
- typedef T second_argument_type;
440
- typedef T result_type;
441
  };
442
  ```
443
 
444
- `operator()` returns `x + y`.
445
-
446
- ``` cpp
447
- template <class T = void> struct minus {
448
- constexpr T operator()(const T& x, const T& y) const;
449
- typedef T first_argument_type;
450
- typedef T second_argument_type;
451
- typedef T result_type;
452
- };
453
- ```
454
-
455
- `operator()` returns `x - y`.
456
-
457
- ``` cpp
458
- template <class T = void> struct multiplies {
459
- constexpr T operator()(const T& x, const T& y) const;
460
- typedef T first_argument_type;
461
- typedef T second_argument_type;
462
- typedef T result_type;
463
- };
464
- ```
465
-
466
- `operator()` returns `x * y`.
467
-
468
  ``` cpp
469
- template <class T = void> struct divides {
470
  constexpr T operator()(const T& x, const T& y) const;
471
- typedef T first_argument_type;
472
- typedef T second_argument_type;
473
- typedef T result_type;
474
- };
475
- ```
476
-
477
- `operator()` returns `x / y`.
478
-
479
- ``` cpp
480
- template <class T = void> struct modulus {
481
- constexpr T operator()(const T& x, const T& y) const;
482
- typedef T first_argument_type;
483
- typedef T second_argument_type;
484
- typedef T result_type;
485
- };
486
- ```
487
-
488
- `operator()` returns `x % y`.
489
-
490
- ``` cpp
491
- template <class T = void> struct negate {
492
- constexpr T operator()(const T& x) const;
493
- typedef T argument_type;
494
- typedef T result_type;
495
- };
496
  ```
497
 
498
- `operator()` returns `-x`.
499
 
500
  ``` cpp
501
  template <> struct plus<void> {
502
  template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
503
  -> decltype(std::forward<T>(t) + std::forward<U>(u));
504
 
505
- typedef unspecified is_transparent;
506
  };
507
  ```
508
 
509
- `operator()` returns `std::forward<T>(t) + std::forward<U>(u)`.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
510
 
511
  ``` cpp
512
  template <> struct minus<void> {
513
  template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
514
  -> decltype(std::forward<T>(t) - std::forward<U>(u));
515
 
516
- typedef unspecified is_transparent;
517
  };
518
  ```
519
 
520
- `operator()` returns `std::forward<T>(t) - std::forward<U>(u)`.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
521
 
522
  ``` cpp
523
  template <> struct multiplies<void> {
524
  template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
525
  -> decltype(std::forward<T>(t) * std::forward<U>(u));
526
 
527
- typedef unspecified is_transparent;
528
  };
529
  ```
530
 
531
- `operator()` returns `std::forward<T>(t) * std::forward<U>(u)`.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
532
 
533
  ``` cpp
534
  template <> struct divides<void> {
535
  template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
536
  -> decltype(std::forward<T>(t) / std::forward<U>(u));
537
 
538
- typedef unspecified is_transparent;
539
  };
540
  ```
541
 
542
- `operator()` returns `std::forward<T>(t) / std::forward<U>(u)`.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
543
 
544
  ``` cpp
545
  template <> struct modulus<void> {
546
  template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
547
  -> decltype(std::forward<T>(t) % std::forward<U>(u));
548
 
549
- typedef unspecified is_transparent;
550
  };
551
  ```
552
 
553
- `operator()` returns `std::forward<T>(t) % std::forward<U>(u)`.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
554
 
555
  ``` cpp
556
  template <> struct negate<void> {
557
  template <class T> constexpr auto operator()(T&& t) const
558
  -> decltype(-std::forward<T>(t));
559
 
560
- typedef unspecified is_transparent;
561
  };
562
  ```
563
 
564
- `operator()` returns `-std::forward<T>(t)`.
 
 
 
 
 
565
 
566
  ### Comparisons <a id="comparisons">[[comparisons]]</a>
567
 
568
  The library provides basic function object classes for all of the
569
  comparison operators in the language ([[expr.rel]], [[expr.eq]]).
570
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
571
  ``` cpp
572
  template <class T = void> struct equal_to {
573
  constexpr bool operator()(const T& x, const T& y) const;
574
- typedef T first_argument_type;
575
- typedef T second_argument_type;
576
- typedef bool result_type;
577
  };
578
  ```
579
 
580
- `operator()` returns `x == y`.
581
-
582
- ``` cpp
583
- template <class T = void> struct not_equal_to {
584
- constexpr bool operator()(const T& x, const T& y) const;
585
- typedef T first_argument_type;
586
- typedef T second_argument_type;
587
- typedef bool result_type;
588
- };
589
- ```
590
-
591
- `operator()` returns `x != y`.
592
-
593
- ``` cpp
594
- template <class T = void> struct greater {
595
- constexpr bool operator()(const T& x, const T& y) const;
596
- typedef T first_argument_type;
597
- typedef T second_argument_type;
598
- typedef bool result_type;
599
- };
600
- ```
601
-
602
- `operator()` returns `x > y`.
603
-
604
  ``` cpp
605
- template <class T = void> struct less {
606
  constexpr bool operator()(const T& x, const T& y) const;
607
- typedef T first_argument_type;
608
- typedef T second_argument_type;
609
- typedef bool result_type;
610
- };
611
- ```
612
-
613
- `operator()` returns `x < y`.
614
-
615
- ``` cpp
616
- template <class T = void> struct greater_equal {
617
- constexpr bool operator()(const T& x, const T& y) const;
618
- typedef T first_argument_type;
619
- typedef T second_argument_type;
620
- typedef bool result_type;
621
- };
622
- ```
623
-
624
- `operator()` returns `x >= y`.
625
-
626
- ``` cpp
627
- template <class T = void> struct less_equal {
628
- constexpr bool operator()(const T& x, const T& y) const;
629
- typedef T first_argument_type;
630
- typedef T second_argument_type;
631
- typedef bool result_type;
632
- };
633
  ```
634
 
635
- `operator()` returns `x <= y`.
636
 
637
  ``` cpp
638
  template <> struct equal_to<void> {
639
  template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
640
  -> decltype(std::forward<T>(t) == std::forward<U>(u));
641
 
642
- typedef unspecified is_transparent;
643
  };
644
  ```
645
 
646
- `operator()` returns `std::forward<T>(t) == std::forward<U>(u)`.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
647
 
648
  ``` cpp
649
  template <> struct not_equal_to<void> {
650
  template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
651
  -> decltype(std::forward<T>(t) != std::forward<U>(u));
652
 
653
- typedef unspecified is_transparent;
654
  };
655
  ```
656
 
657
- `operator()` returns `std::forward<T>(t) != std::forward<U>(u)`.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
658
 
659
  ``` cpp
660
  template <> struct greater<void> {
661
  template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
662
  -> decltype(std::forward<T>(t) > std::forward<U>(u));
663
 
664
- typedef unspecified is_transparent;
665
  };
666
  ```
667
 
668
- `operator()` returns `std::forward<T>(t) > std::forward<U>(u)`.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
669
 
670
  ``` cpp
671
  template <> struct less<void> {
672
  template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
673
  -> decltype(std::forward<T>(t) < std::forward<U>(u));
674
 
675
- typedef unspecified is_transparent;
676
  };
677
  ```
678
 
679
- `operator()` returns `std::forward<T>(t) < std::forward<U>(u)`.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
680
 
681
  ``` cpp
682
  template <> struct greater_equal<void> {
683
  template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
684
  -> decltype(std::forward<T>(t) >= std::forward<U>(u));
685
 
686
- typedef unspecified is_transparent;
687
  };
688
  ```
689
 
690
- `operator()` returns `std::forward<T>(t) >= std::forward<U>(u)`.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
691
 
692
  ``` cpp
693
  template <> struct less_equal<void> {
694
  template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
695
  -> decltype(std::forward<T>(t) <= std::forward<U>(u));
696
 
697
- typedef unspecified is_transparent;
698
  };
699
  ```
700
 
701
- `operator()` returns `std::forward<T>(t) <= std::forward<U>(u)`.
 
 
 
702
 
703
- For templates `greater`, `less`, `greater_equal`, and `less_equal`, the
704
- specializations for any pointer type yield a total order, even if the
705
- built-in operators `<`, `>`, `<=`, `>=` do not.
706
 
707
  ### Logical operations <a id="logical.operations">[[logical.operations]]</a>
708
 
709
  The library provides basic function object classes for all of the
710
  logical operators in the language ([[expr.log.and]], [[expr.log.or]],
711
  [[expr.unary.op]]).
712
 
 
 
713
  ``` cpp
714
  template <class T = void> struct logical_and {
715
  constexpr bool operator()(const T& x, const T& y) const;
716
- typedef T first_argument_type;
717
- typedef T second_argument_type;
718
- typedef bool result_type;
719
  };
720
  ```
721
 
722
- `operator()` returns `x && y`.
723
-
724
  ``` cpp
725
- template <class T = void> struct logical_or {
726
  constexpr bool operator()(const T& x, const T& y) const;
727
- typedef T first_argument_type;
728
- typedef T second_argument_type;
729
- typedef bool result_type;
730
- };
731
  ```
732
 
733
- `operator()` returns `x || y`.
734
-
735
- ``` cpp
736
- template <class T = void> struct logical_not {
737
- constexpr bool operator()(const T& x) const;
738
- typedef T argument_type;
739
- typedef bool result_type;
740
- };
741
- ```
742
-
743
- `operator()` returns `!x`.
744
 
745
  ``` cpp
746
  template <> struct logical_and<void> {
747
  template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
748
  -> decltype(std::forward<T>(t) && std::forward<U>(u));
749
 
750
- typedef unspecified is_transparent;
751
  };
752
  ```
753
 
754
- `operator()` returns `std::forward<T>(t) && std::forward<U>(u)`.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
755
 
756
  ``` cpp
757
  template <> struct logical_or<void> {
758
  template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
759
  -> decltype(std::forward<T>(t) || std::forward<U>(u));
760
 
761
- typedef unspecified is_transparent;
762
  };
763
  ```
764
 
765
- `operator()` returns `std::forward<T>(t) || std::forward<U>(u)`.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
766
 
767
  ``` cpp
768
  template <> struct logical_not<void> {
769
  template <class T> constexpr auto operator()(T&& t) const
770
  -> decltype(!std::forward<T>(t));
771
 
772
- typedef unspecified is_transparent;
773
  };
774
  ```
775
 
776
- `operator()` returns `!std::forward<T>(t)`.
 
 
 
 
 
777
 
778
  ### Bitwise operations <a id="bitwise.operations">[[bitwise.operations]]</a>
779
 
780
  The library provides basic function object classes for all of the
781
  bitwise operators in the language ([[expr.bit.and]], [[expr.or]],
782
  [[expr.xor]], [[expr.unary.op]]).
783
 
 
 
784
  ``` cpp
785
  template <class T = void> struct bit_and {
786
  constexpr T operator()(const T& x, const T& y) const;
787
- typedef T first_argument_type;
788
- typedef T second_argument_type;
789
- typedef T result_type;
790
  };
791
  ```
792
 
793
- `operator()` returns `x & y`.
794
-
795
- ``` cpp
796
- template <class T = void> struct bit_or {
797
- constexpr T operator()(const T& x, const T& y) const;
798
- typedef T first_argument_type;
799
- typedef T second_argument_type;
800
- typedef T result_type;
801
- };
802
- ```
803
-
804
- `operator()` returns `x | y`.
805
-
806
  ``` cpp
807
- template <class T = void> struct bit_xor {
808
  constexpr T operator()(const T& x, const T& y) const;
809
- typedef T first_argument_type;
810
- typedef T second_argument_type;
811
- typedef T result_type;
812
- };
813
- ```
814
-
815
- `operator()` returns `x ^ y`.
816
-
817
- ``` cpp
818
- template <class T = void> struct bit_not {
819
- constexpr T operator()(const T& x) const;
820
- typedef T argument_type;
821
- typedef T result_type;
822
- };
823
  ```
824
 
825
- `operator()` returns `~x`.
826
 
827
  ``` cpp
828
  template <> struct bit_and<void> {
829
  template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
830
  -> decltype(std::forward<T>(t) & std::forward<U>(u));
831
 
832
- typedef unspecified is_transparent;
833
  };
834
  ```
835
 
836
- `operator()` returns `std::forward<T>(t) & std::forward<U>(u)`.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
837
 
838
  ``` cpp
839
  template <> struct bit_or<void> {
840
  template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
841
  -> decltype(std::forward<T>(t) | std::forward<U>(u));
842
 
843
- typedef unspecified is_transparent;
844
  };
845
  ```
846
 
847
- `operator()` returns `std::forward<T>(t) | std::forward<U>(u)`.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
848
 
849
  ``` cpp
850
  template <> struct bit_xor<void> {
851
  template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
852
  -> decltype(std::forward<T>(t) ^ std::forward<U>(u));
853
 
854
- typedef unspecified is_transparent;
855
  };
856
  ```
857
 
858
- `operator()` returns `std::forward<T>(t) ^ std::forward<U>(u)`.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
859
 
860
  ``` cpp
861
  template <> struct bit_not<void> {
862
  template <class T> constexpr auto operator()(T&& t) const
863
  -> decltype(~std::forward<T>(t));
864
 
865
- typedef unspecified is_transparent;
866
  };
867
  ```
868
 
869
- `operator()` returns `~std::forward<T>(t)`.
 
 
 
 
 
870
 
871
- ### Negators <a id="negators">[[negators]]</a>
 
 
 
 
872
 
873
- Negators `not1` and `not2` take a unary and a binary predicate,
874
- respectively, and return their complements ([[expr.unary.op]]).
 
875
 
876
  ``` cpp
877
- template <class Predicate>
878
- class unary_negate {
 
 
 
 
879
  public:
880
- constexpr explicit unary_negate(const Predicate& pred);
881
- constexpr bool operator()(const typename Predicate::argument_type& x) const;
882
- typedef typename Predicate::argument_type argument_type;
883
- typedef bool result_type;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
884
  };
885
  ```
886
 
887
- `operator()` returns `!pred(x)`.
888
-
889
  ``` cpp
890
- template <class Predicate>
891
- constexpr unary_negate<Predicate> not1(const Predicate& pred);
892
  ```
893
 
894
- *Returns:* `unary_negate<Predicate>(pred)`.
 
 
 
 
 
 
895
 
896
  ``` cpp
897
- template <class Predicate>
898
- class binary_negate {
899
- public:
900
- constexpr explicit binary_negate(const Predicate& pred);
901
- constexpr bool operator()(const typename Predicate::first_argument_type& x,
902
- const typename Predicate::second_argument_type& y) const;
903
- typedef typename Predicate::first_argument_type first_argument_type;
904
- typedef typename Predicate::second_argument_type second_argument_type;
905
- typedef bool result_type;
906
- };
907
  ```
908
 
909
- `operator()` returns `!pred(x,y)`.
910
 
911
  ``` cpp
912
- template <class Predicate>
913
- constexpr binary_negate<Predicate> not2(const Predicate& pred);
914
  ```
915
 
916
- *Returns:* `binary_negate<Predicate>(pred)`.
 
 
 
 
 
 
 
 
 
 
 
 
 
917
 
918
  ### Function object binders <a id="func.bind">[[func.bind]]</a>
919
 
920
  This subclause describes a uniform mechanism for binding arguments of
921
  callable objects.
@@ -926,179 +1057,187 @@ callable objects.
926
  namespace std {
927
  template<class T> struct is_bind_expression; // see below
928
  }
929
  ```
930
 
931
- `is_bind_expression` can be used to detect function objects generated by
932
- `bind`. `bind` uses `is_bind_expression` to detect subexpressions.
 
933
 
934
  Instantiations of the `is_bind_expression` template shall meet the
935
- UnaryTypeTrait requirements ([[meta.rqmts]]). The implementation shall
936
- provide a definition that has a BaseCharacteristic of `true_type` if `T`
937
- is a type returned from `bind`, otherwise it shall have a
938
- BaseCharacteristic of `false_type`. A program may specialize this
939
- template for a user-defined type `T` to have a BaseCharacteristic of
940
- `true_type` to indicate that `T` should be treated as a subexpression in
941
- a `bind` call.
942
 
943
  #### Class template `is_placeholder` <a id="func.bind.isplace">[[func.bind.isplace]]</a>
944
 
945
  ``` cpp
946
  namespace std {
947
  template<class T> struct is_placeholder; // see below
948
  }
949
  ```
950
 
951
- `is_placeholder` can be used to detect the standard placeholders `_1`,
952
- `_2`, and so on. `bind` uses `is_placeholder` to detect placeholders.
 
953
 
954
  Instantiations of the `is_placeholder` template shall meet the
955
- UnaryTypeTrait requirements ([[meta.rqmts]]). The implementation shall
956
- provide a definition that has the BaseCharacteristic of
957
  `integral_constant<int, J>` if `T` is the type of
958
- `std::placeholders::_J`, otherwise it shall have a BaseCharacteristic of
959
- `integral_constant<int, 0>`. A program may specialize this template for
960
- a user-defined type `T` to have a BaseCharacteristic of
961
  `integral_constant<int, N>` with `N > 0` to indicate that `T` should be
962
  treated as a placeholder type.
963
 
964
  #### Function template `bind` <a id="func.bind.bind">[[func.bind.bind]]</a>
965
 
966
- In the text that follows, the following names have the following
967
- meanings:
968
 
969
  - `FD` is the type `decay_t<F>`,
970
  - `fd` is an lvalue of type `FD` constructed from `std::forward<F>(f)`,
971
- - `Ti` is the iᵗʰ type in the template parameter pack `BoundArgs`,
972
- - `TiD` is the type `decay_t<Ti>`,
973
- - `ti` is the iᵗʰ argument in the function parameter pack `bound_args`,
974
- - `tid` is an lvalue of type `TiD` constructed from
975
- `std::forward<Ti>(ti)`,
976
- - `Uj` is the jᵗʰ deduced type of the `UnBoundArgs&&...` parameter of
977
  the forwarding call wrapper, and
978
- - `uj` is the jᵗʰ argument associated with `Uj`.
979
 
980
  ``` cpp
981
  template<class F, class... BoundArgs>
982
  unspecified bind(F&& f, BoundArgs&&... bound_args);
983
  ```
984
 
985
- *Requires:* `is_constructible<FD, F>::value` shall be `true`. For each
986
- `Ti` in `BoundArgs`, `is_constructible<TiD, Ti>::value` shall be `true`.
987
- *`INVOKE`*` (fd, w1, w2, ..., wN)` ([[func.require]]) shall be a valid
988
- expression for some values *w1, w2, ..., wN*, where
989
- `N == sizeof...(bound_args)`.
 
990
 
991
- *Returns:* A forwarding call wrapper `g` with a weak result
992
- type ([[func.require]]). The effect of `g(u1, u2, ..., uM)` shall be
993
- *`INVOKE`*`(fd, std::forward<V1>(v1), std::forward<V2>(v2), ..., std::forward<VN>(vN), result_of_t<FD `*`cv`*` & (V1, V2, ..., VN)>)`,
994
- where *`cv`* represents the *cv*-qualifiers of `g` and the values and
995
- types of the bound arguments `v1, v2, ..., vN` are determined as
996
- specified below. The copy constructor and move constructor of the
997
- forwarding call wrapper shall throw an exception if and only if the
998
- corresponding constructor of `FD` or of any of the types `TiD` throws an
999
- exception.
 
 
 
1000
 
1001
  *Throws:* Nothing unless the construction of `fd` or of one of the
1002
- values `tid` throws an exception.
1003
 
1004
  *Remarks:* The return type shall satisfy the requirements of
1005
- `MoveConstructible`. If all of `FD` and `TiD` satisfy the requirements
1006
  of `CopyConstructible`, then the return type shall satisfy the
1007
- requirements of `CopyConstructible`. This implies that all of `FD` and
1008
- `TiD` are `MoveConstructible`.
 
 
1009
 
1010
  ``` cpp
1011
  template<class R, class F, class... BoundArgs>
1012
  unspecified bind(F&& f, BoundArgs&&... bound_args);
1013
  ```
1014
 
1015
- *Requires:* `is_constructible<FD, F>::value` shall be `true`. For each
1016
- `Ti` in `BoundArgs`, `is_constructible<TiD, Ti>::value` shall be `true`.
1017
- *`INVOKE`*`(fd, w1, w2, ..., wN)` shall be a valid expression for some
1018
- values *w1, w2, ..., wN*, where `N == sizeof...(bound_args)`.
 
 
1019
 
1020
- *Returns:* A forwarding call wrapper `g` with a nested type
1021
- `result_type` defined as a synonym for `R`. The effect of
1022
- `g(u1, u2, ..., uM)` shall be
1023
- *`INVOKE`*`(fd, std::forward<V1>(v1), std::forward<V2>(v2), ..., std::forward<VN>(vN), R)`,
1024
- where the values and types of the bound arguments `v1, v2, ..., vN` are
1025
- determined as specified below. The copy constructor and move constructor
1026
- of the forwarding call wrapper shall throw an exception if and only if
1027
- the corresponding constructor of `FD` or of any of the types `TiD`
1028
- throws an exception.
 
 
 
1029
 
1030
  *Throws:* Nothing unless the construction of `fd` or of one of the
1031
- values `tid` throws an exception.
1032
 
1033
  *Remarks:* The return type shall satisfy the requirements of
1034
- `MoveConstructible`. If all of `FD` and `TiD` satisfy the requirements
1035
  of `CopyConstructible`, then the return type shall satisfy the
1036
- requirements of `CopyConstructible`. This implies that all of `FD` and
1037
- `TiD` are `MoveConstructible`.
1038
 
1039
- The values of the *bound arguments* `v1, v2, ..., vN` and their
1040
- corresponding types `V1, V2, ..., VN` depend on the types `TiD` derived
1041
- from the call to `bind` and the *cv*-qualifiers *cv* of the call wrapper
1042
- `g` as follows:
1043
 
1044
- - if `TiD` is `reference_wrapper<T>`, the argument is `tid.get()` and
1045
- its type `Vi` is `T&`;
1046
- - if the value of `is_bind_expression<TiD>::value` is `true`, the
1047
- argument is `tid(std::forward<Uj>({}uj)...)` and its type `Vi` is
1048
- `result_of_t<TiD cv & (Uj&&...)>&&`;
1049
- - if the value `j` of `is_placeholder<TiD>::value` is not zero, the
1050
- argument is `std::forward<Uj>(uj)` and its type `Vi` is `Uj&&`;
1051
- - otherwise, the value is `tid` and its type `Vi` is `TiD cv &`.
 
 
 
 
 
1052
 
1053
  #### Placeholders <a id="func.bind.place">[[func.bind.place]]</a>
1054
 
1055
  ``` cpp
1056
- namespace std {
1057
- namespace placeholders {
1058
  // M is the implementation-defined number of placeholders
1059
- extern unspecified _1;
1060
- extern unspecified _2;
1061
  .
1062
  .
1063
  .
1064
- extern unspecified _M;
1065
- }
1066
  }
1067
  ```
1068
 
1069
  All placeholder types shall be `DefaultConstructible` and
1070
  `CopyConstructible`, and their default constructors and copy/move
1071
  constructors shall not throw exceptions. It is *implementation-defined*
1072
  whether placeholder types are `CopyAssignable`. `CopyAssignable`
1073
  placeholders’ copy assignment operators shall not throw exceptions.
1074
 
 
 
 
 
 
 
 
 
 
 
 
 
1075
  ### Function template `mem_fn` <a id="func.memfn">[[func.memfn]]</a>
1076
 
1077
  ``` cpp
1078
- template<class R, class T> unspecified mem_fn(R T::* pm);
1079
  ```
1080
 
1081
  *Returns:* A simple call wrapper ([[func.def]]) `fn` such that the
1082
- expression `fn(t, a2, ..., aN)` is equivalent to
1083
- *`INVOKE`*`(pm, t, a2, ..., aN)` ([[func.require]]). `fn` shall have a
1084
- nested type `result_type` that is a synonym for the return type of `pm`
1085
- when `pm` is a pointer to member function.
1086
-
1087
- The simple call wrapper shall define two nested types named
1088
- `argument_type` and `result_type` as synonyms for `cv T*` and `Ret`,
1089
- respectively, when `pm` is a pointer to member function with
1090
- cv-qualifier *cv* and taking no arguments, where *Ret* is `pm`’s return
1091
- type.
1092
-
1093
- The simple call wrapper shall define three nested types named
1094
- `first_argument_type`, `second_argument_type`, and `result_type` as
1095
- synonyms for `cv T*`, `T1`, and `Ret`, respectively, when `pm` is a
1096
- pointer to member function with cv-qualifier *cv* and taking one
1097
- argument of type `T1`, where *Ret* is `pm`’s return type.
1098
-
1099
- *Throws:* Nothing.
1100
 
1101
  ### Polymorphic function wrappers <a id="func.wrap">[[func.wrap]]</a>
1102
 
1103
  This subclause describes a polymorphic wrapper class that encapsulates
1104
  arbitrary callable objects.
@@ -1109,84 +1248,75 @@ An exception of type `bad_function_call` is thrown by
1109
  `function::operator()` ([[func.wrap.func.inv]]) when the function
1110
  wrapper object has no target.
1111
 
1112
  ``` cpp
1113
  namespace std {
1114
- class bad_function_call : public std::exception {
1115
  public:
1116
- // [func.wrap.badcall.const], constructor:
1117
  bad_function_call() noexcept;
1118
  };
1119
- } // namespace std
1120
  ```
1121
 
1122
  ##### `bad_function_call` constructor <a id="func.wrap.badcall.const">[[func.wrap.badcall.const]]</a>
1123
 
1124
  ``` cpp
1125
  bad_function_call() noexcept;
1126
  ```
1127
 
1128
- *Effects:* constructs a `bad_function_call` object.
 
 
1129
 
1130
  #### Class template `function` <a id="func.wrap.func">[[func.wrap.func]]</a>
1131
 
1132
  ``` cpp
1133
  namespace std {
1134
- template<class> class function; // undefined
1135
 
1136
  template<class R, class... ArgTypes>
1137
  class function<R(ArgTypes...)> {
1138
  public:
1139
- typedef R result_type;
1140
- typedef T1 argument_type; // only if sizeof...(ArgTypes) == 1 and
1141
- // the type in ArgTypes is T1
1142
- typedef T1 first_argument_type; // only if sizeof...(ArgTypes) == 2 and
1143
- // ArgTypes contains T1 and T2
1144
- typedef T2 second_argument_type; // only if sizeof...(ArgTypes) == 2 and
1145
- // ArgTypes contains T1 and T2
1146
 
1147
- // [func.wrap.func.con], construct/copy/destroy:
1148
  function() noexcept;
1149
  function(nullptr_t) noexcept;
1150
  function(const function&);
1151
  function(function&&);
1152
  template<class F> function(F);
1153
- template<class A> function(allocator_arg_t, const A&) noexcept;
1154
- template<class A> function(allocator_arg_t, const A&,
1155
- nullptr_t) noexcept;
1156
- template<class A> function(allocator_arg_t, const A&,
1157
- const function&);
1158
- template<class A> function(allocator_arg_t, const A&,
1159
- function&&);
1160
- template<class F, class A> function(allocator_arg_t, const A&, F);
1161
 
1162
  function& operator=(const function&);
1163
  function& operator=(function&&);
1164
- function& operator=(nullptr_t);
1165
  template<class F> function& operator=(F&&);
1166
  template<class F> function& operator=(reference_wrapper<F>) noexcept;
1167
 
1168
  ~function();
1169
 
1170
- // [func.wrap.func.mod], function modifiers:
1171
  void swap(function&) noexcept;
1172
- template<class F, class A> void assign(F&&, const A&);
1173
 
1174
- // [func.wrap.func.cap], function capacity:
1175
  explicit operator bool() const noexcept;
1176
 
1177
- // [func.wrap.func.inv], function invocation:
1178
  R operator()(ArgTypes...) const;
1179
 
1180
- // [func.wrap.func.targ], function target access:
1181
- const std::type_info& target_type() const noexcept;
1182
  template<class T> T* target() noexcept;
1183
  template<class T> const T* target() const noexcept;
1184
-
1185
  };
1186
 
1187
- // [func.wrap.func.nullptr], Null pointer comparisons:
 
 
 
 
 
1188
  template <class R, class... ArgTypes>
1189
  bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
1190
 
1191
  template <class R, class... ArgTypes>
1192
  bool operator==(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
@@ -1195,154 +1325,176 @@ namespace std {
1195
  bool operator!=(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
1196
 
1197
  template <class R, class... ArgTypes>
1198
  bool operator!=(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
1199
 
1200
- // [func.wrap.func.alg], specialized algorithms:
1201
  template <class R, class... ArgTypes>
1202
- void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&);
1203
-
1204
- template<class R, class... ArgTypes, class Alloc>
1205
- struct uses_allocator<function<R(ArgTypes...)>, Alloc>
1206
- : true_type { };
1207
  }
1208
  ```
1209
 
1210
  The `function` class template provides polymorphic wrappers that
1211
  generalize the notion of a function pointer. Wrappers can store, copy,
1212
  and call arbitrary callable objects ([[func.def]]), given a call
1213
  signature ([[func.def]]), allowing functions to be first-class objects.
1214
 
1215
- A callable object `f` of type `F` is *Callable* for argument types
1216
- `ArgTypes` and return type `R` if the expression
1217
- `INVOKE(f, declval<ArgTypes>()..., R)`, considered as an unevaluated
1218
- operand (Clause  [[expr]]), is well formed ([[func.require]]).
 
1219
 
1220
  The `function` class template is a call wrapper ([[func.def]]) whose
1221
  call signature ([[func.def]]) is `R(ArgTypes...)`.
1222
 
 
 
 
1223
  ##### `function` construct/copy/destroy <a id="func.wrap.func.con">[[func.wrap.func.con]]</a>
1224
 
1225
- When any `function` constructor that takes a first argument of type
1226
- `allocator_arg_t` is invoked, the second argument shall have a type that
1227
- conforms to the requirements for Allocator (Table 
1228
- [[allocator.requirements]]). A copy of the allocator argument is used to
1229
- allocate memory, if necessary, for the internal data structures of the
1230
- constructed `function` object.
1231
-
1232
  ``` cpp
1233
  function() noexcept;
1234
- template <class A> function(allocator_arg_t, const A& a) noexcept;
1235
  ```
1236
 
1237
  *Postconditions:* `!*this`.
1238
 
1239
  ``` cpp
1240
  function(nullptr_t) noexcept;
1241
- template <class A> function(allocator_arg_t, const A& a, nullptr_t) noexcept;
1242
  ```
1243
 
1244
  *Postconditions:* `!*this`.
1245
 
1246
  ``` cpp
1247
  function(const function& f);
1248
- template <class A> function(allocator_arg_t, const A& a, const function& f);
1249
  ```
1250
 
1251
  *Postconditions:* `!*this` if `!f`; otherwise, `*this` targets a copy of
1252
  `f.target()`.
1253
 
1254
- *Throws:* shall not throw exceptions if `f`’s target is a callable
1255
- object passed via `reference_wrapper` or a function pointer. Otherwise,
1256
- may throw `bad_alloc` or any exception thrown by the copy constructor of
1257
- the stored callable object. Implementations are encouraged to avoid the
1258
- use of dynamically allocated memory for small callable objects, for
1259
- example, where `f`’s target is an object holding only a pointer or
1260
- reference to an object and a member function pointer.
 
 
1261
 
1262
  ``` cpp
1263
  function(function&& f);
1264
- template <class A> function(allocator_arg_t, const A& a, function&& f);
1265
  ```
1266
 
1267
- *Effects:* If `!f`, `*this` has no target; otherwise, move-constructs
1268
- the target of `f` into the target of `*this`, leaving `f` in a valid
1269
- state with an unspecified value.
 
 
 
 
 
 
 
 
 
 
1270
 
1271
  ``` cpp
1272
  template<class F> function(F f);
1273
- template <class F, class A> function(allocator_arg_t, const A& a, F f);
1274
  ```
1275
 
1276
  *Requires:* `F` shall be `CopyConstructible`.
1277
 
1278
- *Remarks:* These constructors shall not participate in overload
1279
- resolution unless `f` is Callable ([[func.wrap.func]]) for argument
1280
- types `ArgTypes...` and return type `R`.
1281
 
1282
  *Postconditions:* `!*this` if any of the following hold:
1283
 
1284
  - `f` is a null function pointer value.
1285
  - `f` is a null member pointer value.
1286
  - `F` is an instance of the `function` class template, and `!f`.
1287
 
1288
  Otherwise, `*this` targets a copy of `f` initialized with
1289
- `std::move(f)`. Implementations are encouraged to avoid the use of
 
 
1290
  dynamically allocated memory for small callable objects, for example,
1291
- where `f`’s target is an object holding only a pointer or reference to
1292
- an object and a member function pointer.
1293
 
1294
  *Throws:* shall not throw exceptions when `f` is a function pointer or a
1295
  `reference_wrapper<T>` for some `T`. Otherwise, may throw `bad_alloc` or
1296
  any exception thrown by `F`’s copy or move constructor.
1297
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1298
  ``` cpp
1299
  function& operator=(const function& f);
1300
  ```
1301
 
1302
- *Effects:* `function(f).swap(*this);`
1303
 
1304
- *Returns:* `*this`
1305
 
1306
  ``` cpp
1307
  function& operator=(function&& f);
1308
  ```
1309
 
1310
  *Effects:* Replaces the target of `*this` with the target of `f`.
1311
 
1312
- *Returns:* `*this`
1313
 
1314
  ``` cpp
1315
- function& operator=(nullptr_t);
1316
  ```
1317
 
1318
  *Effects:* If `*this != nullptr`, destroys the target of `this`.
1319
 
1320
  *Postconditions:* `!(*this)`.
1321
 
1322
- *Returns:* `*this`
1323
 
1324
  ``` cpp
1325
  template<class F> function& operator=(F&& f);
1326
  ```
1327
 
1328
- *Effects:* `function(std::forward<F>(f)).swap(*this);`
1329
 
1330
- *Returns:* `*this`
1331
 
1332
  *Remarks:* This assignment operator shall not participate in overload
1333
- resolution unless `declval<typename decay<F>::type&>()` is
1334
- Callable ([[func.wrap.func]]) for argument types `ArgTypes...` and
1335
- return type `R`.
1336
 
1337
  ``` cpp
1338
  template<class F> function& operator=(reference_wrapper<F> f) noexcept;
1339
  ```
1340
 
1341
- *Effects:* `function(f).swap(*this);`
1342
 
1343
- *Returns:* `*this`
1344
 
1345
  ``` cpp
1346
  ~function();
1347
  ```
1348
 
@@ -1354,17 +1506,10 @@ template<class F> function& operator=(reference_wrapper<F> f) noexcept;
1354
  void swap(function& other) noexcept;
1355
  ```
1356
 
1357
  *Effects:* interchanges the targets of `*this` and `other`.
1358
 
1359
- ``` cpp
1360
- template<class F, class A>
1361
- void assign(F&& f, const A& a);
1362
- ```
1363
-
1364
- *Effects:* `function(allocator_arg, a, std::forward<F>(f)).swap(*this)`
1365
-
1366
  ##### `function` capacity <a id="func.wrap.func.cap">[[func.wrap.func.cap]]</a>
1367
 
1368
  ``` cpp
1369
  explicit operator bool() const noexcept;
1370
  ```
@@ -1372,44 +1517,38 @@ explicit operator bool() const noexcept;
1372
  *Returns:* `true` if `*this` has a target, otherwise `false`.
1373
 
1374
  ##### `function` invocation <a id="func.wrap.func.inv">[[func.wrap.func.inv]]</a>
1375
 
1376
  ``` cpp
1377
- R operator()(ArgTypes... args) const
1378
  ```
1379
 
1380
- *Effects:*
1381
- *`INVOKE`*`(f, std::forward<ArgTypes>(args)..., R)` ([[func.require]]),
1382
- where `f` is the target object ([[func.def]]) of `*this`.
1383
-
1384
- *Returns:* Nothing if `R` is `void`, otherwise the return value of
1385
- *`INVOKE`*`(f, std::forward<ArgTypes>(args)..., R)`.
1386
 
1387
  *Throws:* `bad_function_call` if `!*this`; otherwise, any exception
1388
  thrown by the wrapped callable object.
1389
 
1390
- ##### function target access <a id="func.wrap.func.targ">[[func.wrap.func.targ]]</a>
1391
 
1392
  ``` cpp
1393
- const std::type_info& target_type() const noexcept;
1394
  ```
1395
 
1396
  *Returns:* If `*this` has a target of type `T`, `typeid(T)`; otherwise,
1397
  `typeid(void)`.
1398
 
1399
  ``` cpp
1400
  template<class T> T* target() noexcept;
1401
  template<class T> const T* target() const noexcept;
1402
  ```
1403
 
1404
- *Requires:* `T` shall be a type that is Callable ([[func.wrap.func]])
1405
- for parameter types `ArgTypes` and return type `R`.
1406
-
1407
  *Returns:* If `target_type() == typeid(T)` a pointer to the stored
1408
  function target; otherwise a null pointer.
1409
 
1410
- ##### null pointer comparison operators <a id="func.wrap.func.nullptr">[[func.wrap.func.nullptr]]</a>
1411
 
1412
  ``` cpp
1413
  template <class R, class... ArgTypes>
1414
  bool operator==(const function<R(ArgTypes...)>& f, nullptr_t) noexcept;
1415
  template <class R, class... ArgTypes>
@@ -1429,58 +1568,285 @@ template <class R, class... ArgTypes>
1429
 
1430
  ##### specialized algorithms <a id="func.wrap.func.alg">[[func.wrap.func.alg]]</a>
1431
 
1432
  ``` cpp
1433
  template<class R, class... ArgTypes>
1434
- void swap(function<R(ArgTypes...)>& f1, function<R(ArgTypes...)>& f2);
1435
  ```
1436
 
1437
- *Effects:* `f1.swap(f2);`
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1438
 
1439
  ### Class template `hash` <a id="unord.hash">[[unord.hash]]</a>
1440
 
1441
  The unordered associative containers defined in [[unord]] use
1442
- specializations of the class template `hash` as the default hash
1443
- function. For all object types `Key` for which there exists a
1444
- specialization `hash<Key>`, and for all enumeration types (
1445
- [[dcl.enum]]) `Key`, the instantiation `hash<Key>` shall:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1446
 
1447
  - satisfy the `Hash` requirements ([[hash.requirements]]), with `Key`
1448
  as the function call argument type, the `DefaultConstructible`
1449
- requirements (Table  [[defaultconstructible]]), the `CopyAssignable`
1450
- requirements (Table  [[copyassignable]]),
1451
  - be swappable ([[swappable.requirements]]) for lvalues,
1452
- - provide two nested types `result_type` and `argument_type` which shall
1453
- be synonyms for `size_t` and `Key`, respectively,
1454
- - satisfy the requirement that if `k1 == k2` is true, `h(k1) == h(k2)`
1455
- is also true, where `h` is an object of type `hash<Key>` and `k1` and
1456
- `k2` are objects of type `Key`;
1457
  - satisfy the requirement that the expression `h(k)`, where `h` is an
1458
  object of type `hash<Key>` and `k` is an object of type `Key`, shall
1459
  not throw an exception unless `hash<Key>` is a user-defined
1460
  specialization that depends on at least one user-defined type.
1461
 
1462
- ``` cpp
1463
- template <> struct hash<bool>;
1464
- template <> struct hash<char>;
1465
- template <> struct hash<signed char>;
1466
- template <> struct hash<unsigned char>;
1467
- template <> struct hash<char16_t>;
1468
- template <> struct hash<char32_t>;
1469
- template <> struct hash<wchar_t>;
1470
- template <> struct hash<short>;
1471
- template <> struct hash<unsigned short>;
1472
- template <> struct hash<int>;
1473
- template <> struct hash<unsigned int>;
1474
- template <> struct hash<long>;
1475
- template <> struct hash<unsigned long>;
1476
- template <> struct hash<long long>;
1477
- template <> struct hash<unsigned long long>;
1478
- template <> struct hash<float>;
1479
- template <> struct hash<double>;
1480
- template <> struct hash<long double>;
1481
- template <class T> struct hash<T*>;
1482
- ```
1483
-
1484
- The template specializations shall meet the requirements of class
1485
- template `hash` ([[unord.hash]]).
1486
-
 
8
  [[algorithms]]), the interface is specified to accept a function object.
9
  This not only makes algorithmic templates work with pointers to
10
  functions, but also enables them to work with arbitrary function
11
  objects.
12
 
13
+ ### Header `<functional>` synopsis <a id="functional.syn">[[functional.syn]]</a>
14
+
15
  ``` cpp
16
  namespace std {
17
+ // [func.invoke], invoke
18
+ template <class F, class... Args>
19
+ invoke_result_t<F, Args...> invoke(F&& f, Args&&... args)
20
+ noexcept(is_nothrow_invocable_v<F, Args...>);
21
 
22
+ // [refwrap], reference_wrapper
23
  template <class T> class reference_wrapper;
24
 
25
  template <class T> reference_wrapper<T> ref(T&) noexcept;
26
  template <class T> reference_wrapper<const T> cref(const T&) noexcept;
27
  template <class T> void ref(const T&&) = delete;
28
  template <class T> void cref(const T&&) = delete;
29
 
30
  template <class T> reference_wrapper<T> ref(reference_wrapper<T>) noexcept;
31
  template <class T> reference_wrapper<const T> cref(reference_wrapper<T>) noexcept;
32
 
33
+ // [arithmetic.operations], arithmetic operations
34
  template <class T = void> struct plus;
35
  template <class T = void> struct minus;
36
  template <class T = void> struct multiplies;
37
  template <class T = void> struct divides;
38
  template <class T = void> struct modulus;
 
42
  template <> struct multiplies<void>;
43
  template <> struct divides<void>;
44
  template <> struct modulus<void>;
45
  template <> struct negate<void>;
46
 
47
+ // [comparisons], comparisons
48
  template <class T = void> struct equal_to;
49
  template <class T = void> struct not_equal_to;
50
  template <class T = void> struct greater;
51
  template <class T = void> struct less;
52
  template <class T = void> struct greater_equal;
 
56
  template <> struct greater<void>;
57
  template <> struct less<void>;
58
  template <> struct greater_equal<void>;
59
  template <> struct less_equal<void>;
60
 
61
+ // [logical.operations], logical operations
62
  template <class T = void> struct logical_and;
63
  template <class T = void> struct logical_or;
64
  template <class T = void> struct logical_not;
65
  template <> struct logical_and<void>;
66
  template <> struct logical_or<void>;
67
  template <> struct logical_not<void>;
68
 
69
+ // [bitwise.operations], bitwise operations
70
  template <class T = void> struct bit_and;
71
  template <class T = void> struct bit_or;
72
  template <class T = void> struct bit_xor;
73
  template <class T = void> struct bit_not;
74
  template <> struct bit_and<void>;
75
  template <> struct bit_or<void>;
76
  template <> struct bit_xor<void>;
77
  template <> struct bit_not<void>;
78
 
79
+ // [func.not_fn], function template not_fn
80
+ template <class F>
81
+ unspecified not_fn(F&& f);
 
 
 
 
82
 
83
+ // [func.bind], bind
84
  template<class T> struct is_bind_expression;
85
  template<class T> struct is_placeholder;
86
 
87
  template<class F, class... BoundArgs>
88
  unspecified bind(F&&, BoundArgs&&...);
89
  template<class R, class F, class... BoundArgs>
90
  unspecified bind(F&&, BoundArgs&&...);
91
 
92
  namespace placeholders {
93
  // M is the implementation-defined number of placeholders
94
+ see belownc _1;
95
+ see belownc _2;
96
  .
97
  .
98
  .
99
+ see belownc _M;
100
  }
101
 
102
+ // [func.memfn], member function adaptors
103
+ template<class R, class T>
104
+ unspecified mem_fn(R T::*) noexcept;
 
 
 
 
105
 
106
+ // [func.wrap], polymorphic function wrappers
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
107
  class bad_function_call;
108
 
109
+ template<class> class function; // not defined
110
  template<class R, class... ArgTypes> class function<R(ArgTypes...)>;
111
 
112
  template<class R, class... ArgTypes>
113
+ void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&) noexcept;
114
 
115
  template<class R, class... ArgTypes>
116
+ bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
117
  template<class R, class... ArgTypes>
118
+ bool operator==(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
119
  template<class R, class... ArgTypes>
120
+ bool operator!=(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
121
  template<class R, class... ArgTypes>
122
+ bool operator!=(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
123
 
124
+ // [func.search], searchers
125
+ template<class ForwardIterator, class BinaryPredicate = equal_to<>>
126
+ class default_searcher;
127
 
128
+ template<class RandomAccessIterator,
129
+ class Hash = hash<typename iterator_traits<RandomAccessIterator>::value_type>,
130
+ class BinaryPredicate = equal_to<>>
131
+ class boyer_moore_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_horspool_searcher;
137
 
138
+ // [unord.hash], hash function primary template
139
+ template <class T>
140
+ struct hash;
141
+
142
+ // [func.bind], function object binders
143
+ template <class T>
144
+ inline constexpr bool is_bind_expression_v = is_bind_expression<T>::value;
145
+ template <class T>
146
+ inline constexpr int is_placeholder_v = is_placeholder<T>::value;
147
  }
148
  ```
149
 
150
+ [*Example 1*:
151
+
152
  If a C++program wants to have a by-element addition of two vectors `a`
153
  and `b` containing `double` and put the result into `a`, it can do:
154
 
155
  ``` cpp
156
  transform(a.begin(), a.end(), b.begin(), a.begin(), plus<double>());
157
  ```
158
 
159
+ — *end example*]
160
+
161
+ [*Example 2*:
162
+
163
  To negate every element of `a`:
164
 
165
  ``` cpp
166
  transform(a.begin(), a.end(), a.begin(), negate<double>());
167
  ```
168
 
169
+ *end example*]
 
 
 
 
 
170
 
171
  ### Definitions <a id="func.def">[[func.def]]</a>
172
 
173
  The following definitions apply to this Clause:
174
 
 
190
  ### Requirements <a id="func.require">[[func.require]]</a>
191
 
192
  Define `INVOKE(f, t1, t2, ..., tN)` as follows:
193
 
194
  - `(t1.*f)(t2, ..., tN)` when `f` is a pointer to a member function of a
195
+ class `T` and `is_base_of_v<T, decay_t<decltype(t1)>>` is `true`;
196
+ - `(t1.get().*f)(t2, ..., tN)` when `f` is a pointer to a member
197
+ function of a class `T` and `decay_t<decltype(t1)>` is a
198
+ specialization of `reference_wrapper`;
199
  - `((*t1).*f)(t2, ..., tN)` when `f` is a pointer to a member function
200
+ of a class `T` and `t1` does not satisfy the previous two items;
201
+ - `t1.*f` when `N == 1` and `f` is a pointer to data member of a class
202
+ `T` and `is_base_of_v<T, decay_t<decltype(t1)>>` is `true`;
203
+ - `t1.get().*f` when `N == 1` and `f` is a pointer to data member of a
204
+ class `T` and `decay_t<decltype(t1)>` is a specialization of
205
+ `reference_wrapper`;
206
+ - `(*t1).*f` when `N == 1` and `f` is a pointer to data member of a
207
+ class `T` and `t1` does not satisfy the previous two items;
208
  - `f(t1, t2, ..., tN)` in all other cases.
209
 
210
+ Define `INVOKE<R>(f, t1, t2, ..., tN)` as
211
+ `static_cast<void>(INVOKE(f, t1, t2, ..., tN))` if `R` is cv `void`,
212
+ otherwise `INVOKE(f, t1, t2, ..., tN)` implicitly converted to `R`.
 
 
 
 
 
 
 
 
 
 
 
213
 
214
  Every call wrapper ([[func.def]]) shall be `MoveConstructible`. A
215
+ *forwarding call wrapper* is a call wrapper that can be called with an
216
+ arbitrary argument list and delivers the arguments to the wrapped
217
+ callable object as references. This forwarding step shall ensure that
218
+ rvalue arguments are delivered as rvalue references and lvalue arguments
219
+ are delivered as lvalue references. A *simple call wrapper* is a
220
+ forwarding call wrapper that is `CopyConstructible` and `CopyAssignable`
221
+ and whose copy constructor, move constructor, and assignment operator do
222
+ not throw exceptions.
223
+
224
+ [*Note 1*:
225
+
226
+ In a typical implementation forwarding call wrappers have an overloaded
227
+ function call operator of the form
228
 
229
  ``` cpp
230
  template<class... UnBoundArgs>
231
  R operator()(UnBoundArgs&&... unbound_args) cv-qual;
232
  ```
233
 
234
+ — *end note*]
235
+
236
+ ### Function template `invoke` <a id="func.invoke">[[func.invoke]]</a>
237
+
238
+ ``` cpp
239
+ template <class F, class... Args>
240
+ invoke_result_t<F, Args...> invoke(F&& f, Args&&... args)
241
+ noexcept(is_nothrow_invocable_v<F, Args...>);
242
+ ```
243
+
244
+ *Returns:* *INVOKE*(std::forward\<F\>(f),
245
+ std::forward\<Args\>(args)...) ([[func.require]]).
246
+
247
  ### Class template `reference_wrapper` <a id="refwrap">[[refwrap]]</a>
248
 
249
  ``` cpp
250
  namespace std {
251
  template <class T> class reference_wrapper {
252
  public :
253
  // types
254
+ using type = T;
 
 
 
 
255
 
256
  // construct/copy/destroy
257
  reference_wrapper(T&) noexcept;
258
  reference_wrapper(T&&) = delete; // do not bind to temporary objects
259
  reference_wrapper(const reference_wrapper& x) noexcept;
 
265
  operator T& () const noexcept;
266
  T& get() const noexcept;
267
 
268
  // invocation
269
  template <class... ArgTypes>
270
+ invoke_result_t<T&, ArgTypes...>
271
  operator() (ArgTypes&&...) const;
272
  };
273
+
274
+ template<class T>
275
+ reference_wrapper(reference_wrapper<T>) -> reference_wrapper<T>;
276
  }
277
  ```
278
 
279
  `reference_wrapper<T>` is a `CopyConstructible` and `CopyAssignable`
280
  wrapper around a reference to an object or function of type `T`.
281
 
282
+ `reference_wrapper<T>` shall be a trivially copyable type (
283
+ [[basic.types]]).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
284
 
285
  #### `reference_wrapper` construct/copy/destroy <a id="refwrap.const">[[refwrap.const]]</a>
286
 
287
  ``` cpp
288
  reference_wrapper(T& t) noexcept;
 
318
  T& get() const noexcept;
319
  ```
320
 
321
  *Returns:* The stored reference.
322
 
323
+ #### `reference_wrapper` invocation <a id="refwrap.invoke">[[refwrap.invoke]]</a>
324
 
325
  ``` cpp
326
  template <class... ArgTypes>
327
+ invoke_result_t<T&, ArgTypes...>
328
  operator()(ArgTypes&&... args) const;
329
  ```
330
 
331
+ *Returns:* *INVOKE*(get(),
332
+ std::forward\<ArgTypes\>(args)...). ([[func.require]])
333
 
334
+ #### `reference_wrapper` helper functions <a id="refwrap.helpers">[[refwrap.helpers]]</a>
 
 
 
 
 
335
 
336
  ``` cpp
337
  template <class T> reference_wrapper<T> ref(T& t) noexcept;
338
  ```
339
 
340
+ *Returns:* `reference_wrapper<T>(t)`.
341
 
342
  ``` cpp
343
  template <class T> reference_wrapper<T> ref(reference_wrapper<T> t) noexcept;
344
  ```
345
 
346
+ *Returns:* `ref(t.get())`.
347
 
348
  ``` cpp
349
  template <class T> reference_wrapper<const T> cref(const T& t) noexcept;
350
  ```
351
 
352
+ *Returns:* `reference_wrapper <const T>(t)`.
353
 
354
  ``` cpp
355
  template <class T> reference_wrapper<const T> cref(reference_wrapper<T> t) noexcept;
356
  ```
357
 
358
+ *Returns:* `cref(t.get())`.
359
 
360
  ### Arithmetic operations <a id="arithmetic.operations">[[arithmetic.operations]]</a>
361
 
362
  The library provides basic function object classes for all of the
363
  arithmetic operators in the language ([[expr.mul]], [[expr.add]]).
364
 
365
+ #### Class template `plus` <a id="arithmetic.operations.plus">[[arithmetic.operations.plus]]</a>
366
+
367
  ``` cpp
368
  template <class T = void> struct plus {
369
  constexpr T operator()(const T& x, const T& y) const;
 
 
 
370
  };
371
  ```
372
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
373
  ``` cpp
 
374
  constexpr T operator()(const T& x, const T& y) const;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
375
  ```
376
 
377
+ *Returns:* `x + y`.
378
 
379
  ``` cpp
380
  template <> struct plus<void> {
381
  template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
382
  -> decltype(std::forward<T>(t) + std::forward<U>(u));
383
 
384
+ using is_transparent = unspecified;
385
  };
386
  ```
387
 
388
+ ``` cpp
389
+ template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
390
+ -> decltype(std::forward<T>(t) + std::forward<U>(u));
391
+ ```
392
+
393
+ *Returns:* `std::forward<T>(t) + std::forward<U>(u)`.
394
+
395
+ #### Class template `minus` <a id="arithmetic.operations.minus">[[arithmetic.operations.minus]]</a>
396
+
397
+ ``` cpp
398
+ template <class T = void> struct minus {
399
+ constexpr T operator()(const T& x, const T& y) const;
400
+ };
401
+ ```
402
+
403
+ ``` cpp
404
+ constexpr T operator()(const T& x, const T& y) const;
405
+ ```
406
+
407
+ *Returns:* `x - y`.
408
 
409
  ``` cpp
410
  template <> struct minus<void> {
411
  template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
412
  -> decltype(std::forward<T>(t) - std::forward<U>(u));
413
 
414
+ using is_transparent = unspecified;
415
  };
416
  ```
417
 
418
+ ``` cpp
419
+ template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
420
+ -> decltype(std::forward<T>(t) - std::forward<U>(u));
421
+ ```
422
+
423
+ *Returns:* `std::forward<T>(t) - std::forward<U>(u)`.
424
+
425
+ #### Class template `multiplies` <a id="arithmetic.operations.multiplies">[[arithmetic.operations.multiplies]]</a>
426
+
427
+ ``` cpp
428
+ template <class T = void> struct multiplies {
429
+ constexpr T operator()(const T& x, const T& y) const;
430
+ };
431
+ ```
432
+
433
+ ``` cpp
434
+ constexpr T operator()(const T& x, const T& y) const;
435
+ ```
436
+
437
+ *Returns:* `x * y`.
438
 
439
  ``` cpp
440
  template <> struct multiplies<void> {
441
  template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
442
  -> decltype(std::forward<T>(t) * std::forward<U>(u));
443
 
444
+ using is_transparent = unspecified;
445
  };
446
  ```
447
 
448
+ ``` cpp
449
+ template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
450
+ -> decltype(std::forward<T>(t) * std::forward<U>(u));
451
+ ```
452
+
453
+ *Returns:* `std::forward<T>(t) * std::forward<U>(u)`.
454
+
455
+ #### Class template `divides` <a id="arithmetic.operations.divides">[[arithmetic.operations.divides]]</a>
456
+
457
+ ``` cpp
458
+ template <class T = void> struct divides {
459
+ constexpr T operator()(const T& x, const T& y) const;
460
+ };
461
+ ```
462
+
463
+ ``` cpp
464
+ constexpr T operator()(const T& x, const T& y) const;
465
+ ```
466
+
467
+ *Returns:* `x / y`.
468
 
469
  ``` cpp
470
  template <> struct divides<void> {
471
  template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
472
  -> decltype(std::forward<T>(t) / std::forward<U>(u));
473
 
474
+ using is_transparent = unspecified;
475
  };
476
  ```
477
 
478
+ ``` cpp
479
+ template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
480
+ -> decltype(std::forward<T>(t) / std::forward<U>(u));
481
+ ```
482
+
483
+ *Returns:* `std::forward<T>(t) / std::forward<U>(u)`.
484
+
485
+ #### Class template `modulus` <a id="arithmetic.operations.modulus">[[arithmetic.operations.modulus]]</a>
486
+
487
+ ``` cpp
488
+ template <class T = void> struct modulus {
489
+ constexpr T operator()(const T& x, const T& y) const;
490
+ };
491
+ ```
492
+
493
+ ``` cpp
494
+ constexpr T operator()(const T& x, const T& y) const;
495
+ ```
496
+
497
+ *Returns:* `x % y`.
498
 
499
  ``` cpp
500
  template <> struct modulus<void> {
501
  template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
502
  -> decltype(std::forward<T>(t) % std::forward<U>(u));
503
 
504
+ using is_transparent = unspecified;
505
  };
506
  ```
507
 
508
+ ``` cpp
509
+ template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
510
+ -> decltype(std::forward<T>(t) % std::forward<U>(u));
511
+ ```
512
+
513
+ *Returns:* `std::forward<T>(t) % std::forward<U>(u)`.
514
+
515
+ #### Class template `negate` <a id="arithmetic.operations.negate">[[arithmetic.operations.negate]]</a>
516
+
517
+ ``` cpp
518
+ template <class T = void> struct negate {
519
+ constexpr T operator()(const T& x) const;
520
+ };
521
+ ```
522
+
523
+ ``` cpp
524
+ constexpr T operator()(const T& x) const;
525
+ ```
526
+
527
+ *Returns:* `-x`.
528
 
529
  ``` cpp
530
  template <> struct negate<void> {
531
  template <class T> constexpr auto operator()(T&& t) const
532
  -> decltype(-std::forward<T>(t));
533
 
534
+ using is_transparent = unspecified;
535
  };
536
  ```
537
 
538
+ ``` cpp
539
+ template <class T> constexpr auto operator()(T&& t) const
540
+ -> decltype(-std::forward<T>(t));
541
+ ```
542
+
543
+ *Returns:* `-std::forward<T>(t)`.
544
 
545
  ### Comparisons <a id="comparisons">[[comparisons]]</a>
546
 
547
  The library provides basic function object classes for all of the
548
  comparison operators in the language ([[expr.rel]], [[expr.eq]]).
549
 
550
+ For templates `less`, `greater`, `less_equal`, and `greater_equal`, the
551
+ specializations for any pointer type yield a strict total order that is
552
+ consistent among those specializations and is also consistent with the
553
+ partial order imposed by the built-in operators `<`, `>`, `<=`, `>=`.
554
+
555
+ [*Note 1*: When `a < b` is well-defined for pointers `a` and `b` of
556
+ type `P`, this implies `(a < b) == less<P>(a, b)`,
557
+ `(a > b) == greater<P>(a, b)`, and so forth. — *end note*]
558
+
559
+ For template specializations `less<void>`, `greater<void>`,
560
+ `less_equal<void>`, and `greater_equal<void>`, if the call operator
561
+ calls a built-in operator comparing pointers, the call operator yields a
562
+ strict total order that is consistent among those specializations and is
563
+ also consistent with the partial order imposed by those built-in
564
+ operators.
565
+
566
+ #### Class template `equal_to` <a id="comparisons.equal_to">[[comparisons.equal_to]]</a>
567
+
568
  ``` cpp
569
  template <class T = void> struct equal_to {
570
  constexpr bool operator()(const T& x, const T& y) const;
 
 
 
571
  };
572
  ```
573
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
574
  ``` cpp
 
575
  constexpr bool operator()(const T& x, const T& y) const;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
576
  ```
577
 
578
+ *Returns:* `x == y`.
579
 
580
  ``` cpp
581
  template <> struct equal_to<void> {
582
  template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
583
  -> decltype(std::forward<T>(t) == std::forward<U>(u));
584
 
585
+ using is_transparent = unspecified;
586
  };
587
  ```
588
 
589
+ ``` cpp
590
+ template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
591
+ -> decltype(std::forward<T>(t) == std::forward<U>(u));
592
+ ```
593
+
594
+ *Returns:* `std::forward<T>(t) == std::forward<U>(u)`.
595
+
596
+ #### Class template `not_equal_to` <a id="comparisons.not_equal_to">[[comparisons.not_equal_to]]</a>
597
+
598
+ ``` cpp
599
+ template <class T = void> struct not_equal_to {
600
+ constexpr bool operator()(const T& x, const T& y) const;
601
+ };
602
+ ```
603
+
604
+ ``` cpp
605
+ constexpr bool operator()(const T& x, const T& y) const;
606
+ ```
607
+
608
+ *Returns:* `x != y`.
609
 
610
  ``` cpp
611
  template <> struct not_equal_to<void> {
612
  template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
613
  -> decltype(std::forward<T>(t) != std::forward<U>(u));
614
 
615
+ using is_transparent = unspecified;
616
  };
617
  ```
618
 
619
+ ``` cpp
620
+ template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
621
+ -> decltype(std::forward<T>(t) != std::forward<U>(u));
622
+ ```
623
+
624
+ *Returns:* `std::forward<T>(t) != std::forward<U>(u)`.
625
+
626
+ #### Class template `greater` <a id="comparisons.greater">[[comparisons.greater]]</a>
627
+
628
+ ``` cpp
629
+ template <class T = void> struct greater {
630
+ constexpr bool operator()(const T& x, const T& y) const;
631
+ };
632
+ ```
633
+
634
+ ``` cpp
635
+ constexpr bool operator()(const T& x, const T& y) const;
636
+ ```
637
+
638
+ *Returns:* `x > y`.
639
 
640
  ``` cpp
641
  template <> struct greater<void> {
642
  template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
643
  -> decltype(std::forward<T>(t) > std::forward<U>(u));
644
 
645
+ using is_transparent = unspecified;
646
  };
647
  ```
648
 
649
+ ``` cpp
650
+ template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
651
+ -> decltype(std::forward<T>(t) > std::forward<U>(u));
652
+ ```
653
+
654
+ *Returns:* `std::forward<T>(t) > std::forward<U>(u)`.
655
+
656
+ #### Class template `less` <a id="comparisons.less">[[comparisons.less]]</a>
657
+
658
+ ``` cpp
659
+ template <class T = void> struct less {
660
+ constexpr bool operator()(const T& x, const T& y) const;
661
+ };
662
+ ```
663
+
664
+ ``` cpp
665
+ constexpr bool operator()(const T& x, const T& y) const;
666
+ ```
667
+
668
+ *Returns:* `x < y`.
669
 
670
  ``` cpp
671
  template <> struct less<void> {
672
  template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
673
  -> decltype(std::forward<T>(t) < std::forward<U>(u));
674
 
675
+ using is_transparent = unspecified;
676
  };
677
  ```
678
 
679
+ ``` cpp
680
+ template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
681
+ -> decltype(std::forward<T>(t) < std::forward<U>(u));
682
+ ```
683
+
684
+ *Returns:* `std::forward<T>(t) < std::forward<U>(u)`.
685
+
686
+ #### Class template `greater_equal` <a id="comparisons.greater_equal">[[comparisons.greater_equal]]</a>
687
+
688
+ ``` cpp
689
+ template <class T = void> struct greater_equal {
690
+ constexpr bool operator()(const T& x, const T& y) const;
691
+ };
692
+ ```
693
+
694
+ ``` cpp
695
+ constexpr bool operator()(const T& x, const T& y) const;
696
+ ```
697
+
698
+ *Returns:* `x >= y`.
699
 
700
  ``` cpp
701
  template <> struct greater_equal<void> {
702
  template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
703
  -> decltype(std::forward<T>(t) >= std::forward<U>(u));
704
 
705
+ using is_transparent = unspecified;
706
  };
707
  ```
708
 
709
+ ``` cpp
710
+ template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
711
+ -> decltype(std::forward<T>(t) >= std::forward<U>(u));
712
+ ```
713
+
714
+ *Returns:* `std::forward<T>(t) >= std::forward<U>(u)`.
715
+
716
+ #### Class template `less_equal` <a id="comparisons.less_equal">[[comparisons.less_equal]]</a>
717
+
718
+ ``` cpp
719
+ template <class T = void> struct less_equal {
720
+ constexpr bool operator()(const T& x, const T& y) const;
721
+ };
722
+ ```
723
+
724
+ ``` cpp
725
+ constexpr bool operator()(const T& x, const T& y) const;
726
+ ```
727
+
728
+ *Returns:* `x <= y`.
729
 
730
  ``` cpp
731
  template <> struct less_equal<void> {
732
  template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
733
  -> decltype(std::forward<T>(t) <= std::forward<U>(u));
734
 
735
+ using is_transparent = unspecified;
736
  };
737
  ```
738
 
739
+ ``` cpp
740
+ template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
741
+ -> decltype(std::forward<T>(t) <= std::forward<U>(u));
742
+ ```
743
 
744
+ *Returns:* `std::forward<T>(t) <= std::forward<U>(u)`.
 
 
745
 
746
  ### Logical operations <a id="logical.operations">[[logical.operations]]</a>
747
 
748
  The library provides basic function object classes for all of the
749
  logical operators in the language ([[expr.log.and]], [[expr.log.or]],
750
  [[expr.unary.op]]).
751
 
752
+ #### Class template `logical_and` <a id="logical.operations.and">[[logical.operations.and]]</a>
753
+
754
  ``` cpp
755
  template <class T = void> struct logical_and {
756
  constexpr bool operator()(const T& x, const T& y) const;
 
 
 
757
  };
758
  ```
759
 
 
 
760
  ``` cpp
 
761
  constexpr bool operator()(const T& x, const T& y) const;
 
 
 
 
762
  ```
763
 
764
+ *Returns:* `x && y`.
 
 
 
 
 
 
 
 
 
 
765
 
766
  ``` cpp
767
  template <> struct logical_and<void> {
768
  template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
769
  -> decltype(std::forward<T>(t) && std::forward<U>(u));
770
 
771
+ using is_transparent = unspecified;
772
  };
773
  ```
774
 
775
+ ``` cpp
776
+ template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
777
+ -> decltype(std::forward<T>(t) && std::forward<U>(u));
778
+ ```
779
+
780
+ *Returns:* `std::forward<T>(t) && std::forward<U>(u)`.
781
+
782
+ #### Class template `logical_or` <a id="logical.operations.or">[[logical.operations.or]]</a>
783
+
784
+ ``` cpp
785
+ template <class T = void> struct logical_or {
786
+ constexpr bool operator()(const T& x, const T& y) const;
787
+ };
788
+ ```
789
+
790
+ ``` cpp
791
+ constexpr bool operator()(const T& x, const T& y) const;
792
+ ```
793
+
794
+ *Returns:* `x || y`.
795
 
796
  ``` cpp
797
  template <> struct logical_or<void> {
798
  template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
799
  -> decltype(std::forward<T>(t) || std::forward<U>(u));
800
 
801
+ using is_transparent = unspecified;
802
  };
803
  ```
804
 
805
+ ``` cpp
806
+ template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
807
+ -> decltype(std::forward<T>(t) || std::forward<U>(u));
808
+ ```
809
+
810
+ *Returns:* `std::forward<T>(t) || std::forward<U>(u)`.
811
+
812
+ #### Class template `logical_not` <a id="logical.operations.not">[[logical.operations.not]]</a>
813
+
814
+ ``` cpp
815
+ template <class T = void> struct logical_not {
816
+ constexpr bool operator()(const T& x) const;
817
+ };
818
+ ```
819
+
820
+ ``` cpp
821
+ constexpr bool operator()(const T& x) const;
822
+ ```
823
+
824
+ *Returns:* `!x`.
825
 
826
  ``` cpp
827
  template <> struct logical_not<void> {
828
  template <class T> constexpr auto operator()(T&& t) const
829
  -> decltype(!std::forward<T>(t));
830
 
831
+ using is_transparent = unspecified;
832
  };
833
  ```
834
 
835
+ ``` cpp
836
+ template <class T> constexpr auto operator()(T&& t) const
837
+ -> decltype(!std::forward<T>(t));
838
+ ```
839
+
840
+ *Returns:* `!std::forward<T>(t)`.
841
 
842
  ### Bitwise operations <a id="bitwise.operations">[[bitwise.operations]]</a>
843
 
844
  The library provides basic function object classes for all of the
845
  bitwise operators in the language ([[expr.bit.and]], [[expr.or]],
846
  [[expr.xor]], [[expr.unary.op]]).
847
 
848
+ #### Class template `bit_and` <a id="bitwise.operations.and">[[bitwise.operations.and]]</a>
849
+
850
  ``` cpp
851
  template <class T = void> struct bit_and {
852
  constexpr T operator()(const T& x, const T& y) const;
 
 
 
853
  };
854
  ```
855
 
 
 
 
 
 
 
 
 
 
 
 
 
 
856
  ``` cpp
 
857
  constexpr T operator()(const T& x, const T& y) const;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
858
  ```
859
 
860
+ *Returns:* `x & y`.
861
 
862
  ``` cpp
863
  template <> struct bit_and<void> {
864
  template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
865
  -> decltype(std::forward<T>(t) & std::forward<U>(u));
866
 
867
+ using is_transparent = unspecified;
868
  };
869
  ```
870
 
871
+ ``` cpp
872
+ template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
873
+ -> decltype(std::forward<T>(t) & std::forward<U>(u));
874
+ ```
875
+
876
+ *Returns:* `std::forward<T>(t) & std::forward<U>(u)`.
877
+
878
+ #### Class template `bit_or` <a id="bitwise.operations.or">[[bitwise.operations.or]]</a>
879
+
880
+ ``` cpp
881
+ template <class T = void> struct bit_or {
882
+ constexpr T operator()(const T& x, const T& y) const;
883
+ };
884
+ ```
885
+
886
+ ``` cpp
887
+ constexpr T operator()(const T& x, const T& y) const;
888
+ ```
889
+
890
+ *Returns:* `x | y`.
891
 
892
  ``` cpp
893
  template <> struct bit_or<void> {
894
  template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
895
  -> decltype(std::forward<T>(t) | std::forward<U>(u));
896
 
897
+ using is_transparent = unspecified;
898
  };
899
  ```
900
 
901
+ ``` cpp
902
+ template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
903
+ -> decltype(std::forward<T>(t) | std::forward<U>(u));
904
+ ```
905
+
906
+ *Returns:* `std::forward<T>(t) | std::forward<U>(u)`.
907
+
908
+ #### Class template `bit_xor` <a id="bitwise.operations.xor">[[bitwise.operations.xor]]</a>
909
+
910
+ ``` cpp
911
+ template <class T = void> struct bit_xor {
912
+ constexpr T operator()(const T& x, const T& y) const;
913
+ };
914
+ ```
915
+
916
+ ``` cpp
917
+ constexpr T operator()(const T& x, const T& y) const;
918
+ ```
919
+
920
+ *Returns:* `x ^ y`.
921
 
922
  ``` cpp
923
  template <> struct bit_xor<void> {
924
  template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
925
  -> decltype(std::forward<T>(t) ^ std::forward<U>(u));
926
 
927
+ using is_transparent = unspecified;
928
  };
929
  ```
930
 
931
+ ``` cpp
932
+ template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
933
+ -> decltype(std::forward<T>(t) ^ std::forward<U>(u));
934
+ ```
935
+
936
+ *Returns:* `std::forward<T>(t) ^ std::forward<U>(u)`.
937
+
938
+ #### Class template `bit_not` <a id="bitwise.operations.not">[[bitwise.operations.not]]</a>
939
+
940
+ ``` cpp
941
+ template <class T = void> struct bit_not {
942
+ constexpr T operator()(const T& x) const;
943
+ };
944
+ ```
945
+
946
+ ``` cpp
947
+ constexpr T operator()(const T& x) const;
948
+ ```
949
+
950
+ *Returns:* `~x`.
951
 
952
  ``` cpp
953
  template <> struct bit_not<void> {
954
  template <class T> constexpr auto operator()(T&& t) const
955
  -> decltype(~std::forward<T>(t));
956
 
957
+ using is_transparent = unspecified;
958
  };
959
  ```
960
 
961
+ ``` cpp
962
+ template <class T> constexpr auto operator()(T&&) const
963
+ -> decltype(~std::forward<T>(t));
964
+ ```
965
+
966
+ *Returns:* `~std::forward<T>(t)`.
967
 
968
+ ### Function template `not_fn` <a id="func.not_fn">[[func.not_fn]]</a>
969
+
970
+ ``` cpp
971
+ template <class F> unspecified not_fn(F&& f);
972
+ ```
973
 
974
+ *Effects:* Equivalent to
975
+ `return `*`call_wrapper`*`(std::forward<F>(f));` where *`call_wrapper`*
976
+ is an exposition only class defined as follows:
977
 
978
  ``` cpp
979
+ class call_wrapper {
980
+ using FD = decay_t<F>;
981
+ FD fd;
982
+
983
+ explicit call_wrapper(F&& f);
984
+
985
  public:
986
+ call_wrapper(call_wrapper&&) = default;
987
+ call_wrapper(const call_wrapper&) = default;
988
+
989
+ template<class... Args>
990
+ auto operator()(Args&&...) &
991
+ -> decltype(!declval<invoke_result_t<FD&, Args...>>());
992
+
993
+ template<class... Args>
994
+ auto operator()(Args&&...) const&
995
+ -> decltype(!declval<invoke_result_t<const FD&, Args...>>());
996
+
997
+ template<class... Args>
998
+ auto operator()(Args&&...) &&
999
+ -> decltype(!declval<invoke_result_t<FD, Args...>>());
1000
+
1001
+ template<class... Args>
1002
+ auto operator()(Args&&...) const&&
1003
+ -> decltype(!declval<invoke_result_t<const FD, Args...>>());
1004
  };
1005
  ```
1006
 
 
 
1007
  ``` cpp
1008
+ explicit call_wrapper(F&& f);
 
1009
  ```
1010
 
1011
+ *Requires:* `FD` shall satisfy the requirements of `MoveConstructible`.
1012
+ `is_constructible_v<FD, F>` shall be `true`. `fd` shall be a callable
1013
+ object ([[func.def]]).
1014
+
1015
+ *Effects:* Initializes `fd` from `std::forward<F>(f)`.
1016
+
1017
+ *Throws:* Any exception thrown by construction of `fd`.
1018
 
1019
  ``` cpp
1020
+ template<class... Args>
1021
+ auto operator()(Args&&... args) &
1022
+ -> decltype(!declval<invoke_result_t<FD&, Args...>>());
1023
+ template<class... Args>
1024
+ auto operator()(Args&&... args) const&
1025
+ -> decltype(!declval<invoke_result_t<const FD&, Args...>>());
 
 
 
 
1026
  ```
1027
 
1028
+ *Effects:* Equivalent to:
1029
 
1030
  ``` cpp
1031
+ return !INVOKE(fd, std::forward<Args>(args)...); // see [func.require]
 
1032
  ```
1033
 
1034
+ ``` cpp
1035
+ template<class... Args>
1036
+ auto operator()(Args&&... args) &&
1037
+ -> decltype(!declval<invoke_result_t<FD, Args...>>());
1038
+ template<class... Args>
1039
+ auto operator()(Args&&... args) const&&
1040
+ -> decltype(!declval<invoke_result_t<const FD, Args...>>());
1041
+ ```
1042
+
1043
+ *Effects:* Equivalent to:
1044
+
1045
+ ``` cpp
1046
+ return !INVOKE(std::move(fd), std::forward<Args>(args)...); // see [func.require]
1047
+ ```
1048
 
1049
  ### Function object binders <a id="func.bind">[[func.bind]]</a>
1050
 
1051
  This subclause describes a uniform mechanism for binding arguments of
1052
  callable objects.
 
1057
  namespace std {
1058
  template<class T> struct is_bind_expression; // see below
1059
  }
1060
  ```
1061
 
1062
+ The class template `is_bind_expression` can be used to detect function
1063
+ objects generated by `bind`. The function template `bind` uses
1064
+ `is_bind_expression` to detect subexpressions.
1065
 
1066
  Instantiations of the `is_bind_expression` template shall meet the
1067
+ `UnaryTypeTrait` requirements ([[meta.rqmts]]). The implementation
1068
+ shall provide a definition that has a base characteristic of `true_type`
1069
+ if `T` is a type returned from `bind`, otherwise it shall have a base
1070
+ characteristic of `false_type`. A program may specialize this template
1071
+ for a user-defined type `T` to have a base characteristic of `true_type`
1072
+ to indicate that `T` should be treated as a subexpression in a `bind`
1073
+ call.
1074
 
1075
  #### Class template `is_placeholder` <a id="func.bind.isplace">[[func.bind.isplace]]</a>
1076
 
1077
  ``` cpp
1078
  namespace std {
1079
  template<class T> struct is_placeholder; // see below
1080
  }
1081
  ```
1082
 
1083
+ The class template `is_placeholder` can be used to detect the standard
1084
+ placeholders `_1`, `_2`, and so on. The function template `bind` uses
1085
+ `is_placeholder` to detect placeholders.
1086
 
1087
  Instantiations of the `is_placeholder` template shall meet the
1088
+ `UnaryTypeTrait` requirements ([[meta.rqmts]]). The implementation
1089
+ shall provide a definition that has the base characteristic of
1090
  `integral_constant<int, J>` if `T` is the type of
1091
+ `std::placeholders::_J`, otherwise it shall have a base characteristic
1092
+ of `integral_constant<int, 0>`. A program may specialize this template
1093
+ for a user-defined type `T` to have a base characteristic of
1094
  `integral_constant<int, N>` with `N > 0` to indicate that `T` should be
1095
  treated as a placeholder type.
1096
 
1097
  #### Function template `bind` <a id="func.bind.bind">[[func.bind.bind]]</a>
1098
 
1099
+ In the text that follows:
 
1100
 
1101
  - `FD` is the type `decay_t<F>`,
1102
  - `fd` is an lvalue of type `FD` constructed from `std::forward<F>(f)`,
1103
+ - `Tᵢ` is the iᵗʰ type in the template parameter pack `BoundArgs`,
1104
+ - `TDᵢ` is the type `decay_t<Tᵢ>`,
1105
+ - `tᵢ` is the iᵗʰ argument in the function parameter pack `bound_args`,
1106
+ - `tdᵢ` is an lvalue of type `TDᵢ` constructed from
1107
+ `std::forward<Tᵢ>(tᵢ)`,
1108
+ - `Uⱼ` is the jᵗʰ deduced type of the `UnBoundArgs&&...` parameter of
1109
  the forwarding call wrapper, and
1110
+ - `uⱼ` is the jᵗʰ argument associated with `Uⱼ`.
1111
 
1112
  ``` cpp
1113
  template<class F, class... BoundArgs>
1114
  unspecified bind(F&& f, BoundArgs&&... bound_args);
1115
  ```
1116
 
1117
+ *Requires:* `is_constructible_v<FD, F>` shall be `true`. For each `Tᵢ`
1118
+ in `BoundArgs`, `is_constructible_v<``TDᵢ``, ``Tᵢ``>` shall be `true`.
1119
+ *INVOKE*(fd, w₁, w₂, , $w_N$) ([[func.require]]) shall be a valid
1120
+ expression for some values `w₁`, `w₂`, , `w_N`, where N has the value
1121
+ `sizeof...(bound_args)`. The cv-qualifiers cv of the call wrapper `g`,
1122
+ as specified below, shall be neither `volatile` nor `const volatile`.
1123
 
1124
+ *Returns:* A forwarding call wrapper `g` ([[func.require]]). The effect
1125
+ of `g(``u₁``, ``u₂``, , ``u_M``)` shall be
1126
+
1127
+ ``` cpp
1128
+ INVOKE(fd, std::forward<$V_1$>($v_1$), std::forward<$V_2$>($v_2$), , std::forward<$V_N$>($v_N$))
1129
+ ```
1130
+
1131
+ where the values and types of the bound arguments `v₁`, `v₂`, …, `v_N`
1132
+ are determined as specified below. The copy constructor and move
1133
+ constructor of the forwarding call wrapper shall throw an exception if
1134
+ and only if the corresponding constructor of `FD` or of any of the types
1135
+ `TDᵢ` throws an exception.
1136
 
1137
  *Throws:* Nothing unless the construction of `fd` or of one of the
1138
+ values `tdᵢ` throws an exception.
1139
 
1140
  *Remarks:* The return type shall satisfy the requirements of
1141
+ `MoveConstructible`. If all of `FD` and `TDᵢ` satisfy the requirements
1142
  of `CopyConstructible`, then the return type shall satisfy the
1143
+ requirements of `CopyConstructible`.
1144
+
1145
+ [*Note 1*: This implies that all of `FD` and `TDᵢ` are
1146
+ `MoveConstructible`. — *end note*]
1147
 
1148
  ``` cpp
1149
  template<class R, class F, class... BoundArgs>
1150
  unspecified bind(F&& f, BoundArgs&&... bound_args);
1151
  ```
1152
 
1153
+ *Requires:* `is_constructible_v<FD, F>` shall be `true`. For each `Tᵢ`
1154
+ in `BoundArgs`, `is_constructible_v<``TDᵢ``, ``Tᵢ``>` shall be `true`.
1155
+ *INVOKE*(fd, w₁, w₂, , $w_N$) shall be a valid expression for some
1156
+ values `w₁`, `w₂`, , `w_N`, where N has the value
1157
+ `sizeof...(bound_args)`. The cv-qualifiers cv of the call wrapper `g`,
1158
+ as specified below, shall be neither `volatile` nor `const volatile`.
1159
 
1160
+ *Returns:* A forwarding call wrapper `g` ([[func.require]]). The effect
1161
+ of `g(``u₁``, ``u₂``, …, ``u_M``)` shall be
1162
+
1163
+ ``` cpp
1164
+ INVOKE<R>(fd, std::forward<$V_1$>($v_1$), std::forward<$V_2$>($v_2$), , std::forward<$V_N$>($v_N$))
1165
+ ```
1166
+
1167
+ where the values and types of the bound arguments `v₁`, `v₂`, …, `v_N`
1168
+ are determined as specified below. The copy constructor and move
1169
+ constructor of the forwarding call wrapper shall throw an exception if
1170
+ and only if the corresponding constructor of `FD` or of any of the types
1171
+ `TDᵢ` throws an exception.
1172
 
1173
  *Throws:* Nothing unless the construction of `fd` or of one of the
1174
+ values `tdᵢ` throws an exception.
1175
 
1176
  *Remarks:* The return type shall satisfy the requirements of
1177
+ `MoveConstructible`. If all of `FD` and `TDᵢ` satisfy the requirements
1178
  of `CopyConstructible`, then the return type shall satisfy the
1179
+ requirements of `CopyConstructible`.
 
1180
 
1181
+ [*Note 2*: This implies that all of `FD` and `TDᵢ` are
1182
+ `MoveConstructible`. *end note*]
 
 
1183
 
1184
+ The values of the *bound arguments* `v₁`, `v₂`, …, `v_N` and their
1185
+ corresponding types `V₁`, `V₂`, …, `V_N` depend on the types `TDᵢ`
1186
+ derived from the call to `bind` and the cv-qualifiers cv of the call
1187
+ wrapper `g` as follows:
1188
+
1189
+ - if `TDᵢ` is `reference_wrapper<T>`, the argument is `tdᵢ.get()` and
1190
+ its type `Vᵢ` is `T&`;
1191
+ - if the value of `is_bind_expression_v<TDᵢ>` is `true`, the argument is
1192
+ `tdᵢ(std::forward<Uⱼ>(uⱼ)...)` and its type `Vᵢ` is
1193
+ `invoke_result_t<TDᵢ cv &, Uⱼ...>&&`;
1194
+ - if the value `j` of `is_placeholder_v<TDᵢ>` is not zero, the argument
1195
+ is `std::forward<Uⱼ>(uⱼ)` and its type `Vᵢ` is `Uⱼ&&`;
1196
+ - otherwise, the value is `tdᵢ` and its type `Vᵢ` is `TDᵢ cv &`.
1197
 
1198
  #### Placeholders <a id="func.bind.place">[[func.bind.place]]</a>
1199
 
1200
  ``` cpp
1201
+ namespace std::placeholders {
 
1202
  // M is the implementation-defined number of placeholders
1203
+ see below _1;
1204
+ see below _2;
1205
  .
1206
  .
1207
  .
1208
+ see below _M;
 
1209
  }
1210
  ```
1211
 
1212
  All placeholder types shall be `DefaultConstructible` and
1213
  `CopyConstructible`, and their default constructors and copy/move
1214
  constructors shall not throw exceptions. It is *implementation-defined*
1215
  whether placeholder types are `CopyAssignable`. `CopyAssignable`
1216
  placeholders’ copy assignment operators shall not throw exceptions.
1217
 
1218
+ Placeholders should be defined as:
1219
+
1220
+ ``` cpp
1221
+ inline constexpr unspecified _1{};
1222
+ ```
1223
+
1224
+ If they are not, they shall be declared as:
1225
+
1226
+ ``` cpp
1227
+ extern unspecified _1;
1228
+ ```
1229
+
1230
  ### Function template `mem_fn` <a id="func.memfn">[[func.memfn]]</a>
1231
 
1232
  ``` cpp
1233
+ template<class R, class T> unspecified mem_fn(R T::* pm) noexcept;
1234
  ```
1235
 
1236
  *Returns:* A simple call wrapper ([[func.def]]) `fn` such that the
1237
+ expression `fn(t, a2, ..., aN)` is equivalent to *INVOKE*(pm, t, a2,
1238
+ ..., aN) ([[func.require]]).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1239
 
1240
  ### Polymorphic function wrappers <a id="func.wrap">[[func.wrap]]</a>
1241
 
1242
  This subclause describes a polymorphic wrapper class that encapsulates
1243
  arbitrary callable objects.
 
1248
  `function::operator()` ([[func.wrap.func.inv]]) when the function
1249
  wrapper object has no target.
1250
 
1251
  ``` cpp
1252
  namespace std {
1253
+ class bad_function_call : public exception {
1254
  public:
1255
+ // [func.wrap.badcall.const], constructor
1256
  bad_function_call() noexcept;
1257
  };
1258
+ }
1259
  ```
1260
 
1261
  ##### `bad_function_call` constructor <a id="func.wrap.badcall.const">[[func.wrap.badcall.const]]</a>
1262
 
1263
  ``` cpp
1264
  bad_function_call() noexcept;
1265
  ```
1266
 
1267
+ *Effects:* Constructs a `bad_function_call` object.
1268
+
1269
+ *Postconditions:* `what()` returns an *implementation-defined* NTBS.
1270
 
1271
  #### Class template `function` <a id="func.wrap.func">[[func.wrap.func]]</a>
1272
 
1273
  ``` cpp
1274
  namespace std {
1275
+ template<class> class function; // not defined
1276
 
1277
  template<class R, class... ArgTypes>
1278
  class function<R(ArgTypes...)> {
1279
  public:
1280
+ using result_type = R;
 
 
 
 
 
 
1281
 
1282
+ // [func.wrap.func.con], construct/copy/destroy
1283
  function() noexcept;
1284
  function(nullptr_t) noexcept;
1285
  function(const function&);
1286
  function(function&&);
1287
  template<class F> function(F);
 
 
 
 
 
 
 
 
1288
 
1289
  function& operator=(const function&);
1290
  function& operator=(function&&);
1291
+ function& operator=(nullptr_t) noexcept;
1292
  template<class F> function& operator=(F&&);
1293
  template<class F> function& operator=(reference_wrapper<F>) noexcept;
1294
 
1295
  ~function();
1296
 
1297
+ // [func.wrap.func.mod], function modifiers
1298
  void swap(function&) noexcept;
 
1299
 
1300
+ // [func.wrap.func.cap], function capacity
1301
  explicit operator bool() const noexcept;
1302
 
1303
+ // [func.wrap.func.inv], function invocation
1304
  R operator()(ArgTypes...) const;
1305
 
1306
+ // [func.wrap.func.targ], function target access
1307
+ const type_info& target_type() const noexcept;
1308
  template<class T> T* target() noexcept;
1309
  template<class T> const T* target() const noexcept;
 
1310
  };
1311
 
1312
+ template<class R, class... ArgTypes>
1313
+ function(R(*)(ArgTypes...)) -> function<R(ArgTypes...)>;
1314
+
1315
+ template<class F> function(F) -> function<see below>;
1316
+
1317
+ // [func.wrap.func.nullptr], Null pointer comparisons
1318
  template <class R, class... ArgTypes>
1319
  bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
1320
 
1321
  template <class R, class... ArgTypes>
1322
  bool operator==(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
 
1325
  bool operator!=(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
1326
 
1327
  template <class R, class... ArgTypes>
1328
  bool operator!=(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
1329
 
1330
+ // [func.wrap.func.alg], specialized algorithms
1331
  template <class R, class... ArgTypes>
1332
+ void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&) noexcept;
 
 
 
 
1333
  }
1334
  ```
1335
 
1336
  The `function` class template provides polymorphic wrappers that
1337
  generalize the notion of a function pointer. Wrappers can store, copy,
1338
  and call arbitrary callable objects ([[func.def]]), given a call
1339
  signature ([[func.def]]), allowing functions to be first-class objects.
1340
 
1341
+ A callable type ([[func.def]]) `F` is *Lvalue-Callable* for argument
1342
+ types `ArgTypes` and return type `R` if the expression
1343
+ `INVOKE<R>(declval<F&>(), declval<ArgTypes>()...)`, considered as an
1344
+ unevaluated operand (Clause  [[expr]]), is well formed (
1345
+ [[func.require]]).
1346
 
1347
  The `function` class template is a call wrapper ([[func.def]]) whose
1348
  call signature ([[func.def]]) is `R(ArgTypes...)`.
1349
 
1350
+ [*Note 1*: The types deduced by the deduction guides for `function` may
1351
+ change in future versions of this International Standard. — *end note*]
1352
+
1353
  ##### `function` construct/copy/destroy <a id="func.wrap.func.con">[[func.wrap.func.con]]</a>
1354
 
 
 
 
 
 
 
 
1355
  ``` cpp
1356
  function() noexcept;
 
1357
  ```
1358
 
1359
  *Postconditions:* `!*this`.
1360
 
1361
  ``` cpp
1362
  function(nullptr_t) noexcept;
 
1363
  ```
1364
 
1365
  *Postconditions:* `!*this`.
1366
 
1367
  ``` cpp
1368
  function(const function& f);
 
1369
  ```
1370
 
1371
  *Postconditions:* `!*this` if `!f`; otherwise, `*this` targets a copy of
1372
  `f.target()`.
1373
 
1374
+ *Throws:* shall not throw exceptions if `f`’s target is a specialization
1375
+ of `reference_wrapper` or a function pointer. Otherwise, may throw
1376
+ `bad_alloc` or any exception thrown by the copy constructor of the
1377
+ stored callable object.
1378
+
1379
+ [*Note 1*: Implementations are encouraged to avoid the use of
1380
+ dynamically allocated memory for small callable objects, for example,
1381
+ where `f`’s target is an object holding only a pointer or reference to
1382
+ an object and a member function pointer. — *end note*]
1383
 
1384
  ``` cpp
1385
  function(function&& f);
 
1386
  ```
1387
 
1388
+ *Postconditions:* If `!f`, `*this` has no target; otherwise, the target
1389
+ of `*this` is equivalent to the target of `f` before the construction,
1390
+ and `f` is in a valid state with an unspecified value.
1391
+
1392
+ *Throws:* shall not throw exceptions if `f`’s target is a specialization
1393
+ of `reference_wrapper` or a function pointer. Otherwise, may throw
1394
+ `bad_alloc` or any exception thrown by the copy or move constructor of
1395
+ the stored callable object.
1396
+
1397
+ [*Note 2*: Implementations are encouraged to avoid the use of
1398
+ dynamically allocated memory for small callable objects, for example,
1399
+ where `f`’s target is an object holding only a pointer or reference to
1400
+ an object and a member function pointer. — *end note*]
1401
 
1402
  ``` cpp
1403
  template<class F> function(F f);
 
1404
  ```
1405
 
1406
  *Requires:* `F` shall be `CopyConstructible`.
1407
 
1408
+ *Remarks:* This constructor template shall not participate in overload
1409
+ resolution unless `F` is Lvalue-Callable ([[func.wrap.func]]) for
1410
+ argument types `ArgTypes...` and return type `R`.
1411
 
1412
  *Postconditions:* `!*this` if any of the following hold:
1413
 
1414
  - `f` is a null function pointer value.
1415
  - `f` is a null member pointer value.
1416
  - `F` is an instance of the `function` class template, and `!f`.
1417
 
1418
  Otherwise, `*this` targets a copy of `f` initialized with
1419
+ `std::move(f)`.
1420
+
1421
+ [*Note 3*: Implementations are encouraged to avoid the use of
1422
  dynamically allocated memory for small callable objects, for example,
1423
+ where `f` is an object holding only a pointer or reference to an object
1424
+ and a member function pointer. — *end note*]
1425
 
1426
  *Throws:* shall not throw exceptions when `f` is a function pointer or a
1427
  `reference_wrapper<T>` for some `T`. Otherwise, may throw `bad_alloc` or
1428
  any exception thrown by `F`’s copy or move constructor.
1429
 
1430
+ ``` cpp
1431
+ template<class F> function(F) -> function<see below>;
1432
+ ```
1433
+
1434
+ *Remarks:* This deduction guide participates in overload resolution only
1435
+ if `&F::operator()` is well-formed when treated as an unevaluated
1436
+ operand. In that case, if `decltype(&F::operator())` is of the form
1437
+ `R(G::*)(A...)` cv `&`ₒₚₜ ` noexcept` for a class type `G`, then the
1438
+ deduced type is `function<R(A...)>`.
1439
+
1440
+ [*Example 1*:
1441
+
1442
+ ``` cpp
1443
+ void f() {
1444
+ int i{5};
1445
+ function g = [&](double) { return i; }; // deduces function<int(double)>
1446
+ }
1447
+ ```
1448
+
1449
+ — *end example*]
1450
+
1451
  ``` cpp
1452
  function& operator=(const function& f);
1453
  ```
1454
 
1455
+ *Effects:* As if by `function(f).swap(*this);`
1456
 
1457
+ *Returns:* `*this`.
1458
 
1459
  ``` cpp
1460
  function& operator=(function&& f);
1461
  ```
1462
 
1463
  *Effects:* Replaces the target of `*this` with the target of `f`.
1464
 
1465
+ *Returns:* `*this`.
1466
 
1467
  ``` cpp
1468
+ function& operator=(nullptr_t) noexcept;
1469
  ```
1470
 
1471
  *Effects:* If `*this != nullptr`, destroys the target of `this`.
1472
 
1473
  *Postconditions:* `!(*this)`.
1474
 
1475
+ *Returns:* `*this`.
1476
 
1477
  ``` cpp
1478
  template<class F> function& operator=(F&& f);
1479
  ```
1480
 
1481
+ *Effects:* As if by: `function(std::forward<F>(f)).swap(*this);`
1482
 
1483
+ *Returns:* `*this`.
1484
 
1485
  *Remarks:* This assignment operator shall not participate in overload
1486
+ resolution unless `decay_t<F>` is Lvalue-Callable ([[func.wrap.func]])
1487
+ for argument types `ArgTypes...` and return type `R`.
 
1488
 
1489
  ``` cpp
1490
  template<class F> function& operator=(reference_wrapper<F> f) noexcept;
1491
  ```
1492
 
1493
+ *Effects:* As if by: `function(f).swap(*this);`
1494
 
1495
+ *Returns:* `*this`.
1496
 
1497
  ``` cpp
1498
  ~function();
1499
  ```
1500
 
 
1506
  void swap(function& other) noexcept;
1507
  ```
1508
 
1509
  *Effects:* interchanges the targets of `*this` and `other`.
1510
 
 
 
 
 
 
 
 
1511
  ##### `function` capacity <a id="func.wrap.func.cap">[[func.wrap.func.cap]]</a>
1512
 
1513
  ``` cpp
1514
  explicit operator bool() const noexcept;
1515
  ```
 
1517
  *Returns:* `true` if `*this` has a target, otherwise `false`.
1518
 
1519
  ##### `function` invocation <a id="func.wrap.func.inv">[[func.wrap.func.inv]]</a>
1520
 
1521
  ``` cpp
1522
+ R operator()(ArgTypes... args) const;
1523
  ```
1524
 
1525
+ *Returns:* *INVOKE*\<R\>(f,
1526
+ std::forward\<ArgTypes\>(args)...) ([[func.require]]), where `f` is the
1527
+ target object ([[func.def]]) of `*this`.
 
 
 
1528
 
1529
  *Throws:* `bad_function_call` if `!*this`; otherwise, any exception
1530
  thrown by the wrapped callable object.
1531
 
1532
+ ##### `function` target access <a id="func.wrap.func.targ">[[func.wrap.func.targ]]</a>
1533
 
1534
  ``` cpp
1535
+ const type_info& target_type() const noexcept;
1536
  ```
1537
 
1538
  *Returns:* If `*this` has a target of type `T`, `typeid(T)`; otherwise,
1539
  `typeid(void)`.
1540
 
1541
  ``` cpp
1542
  template<class T> T* target() noexcept;
1543
  template<class T> const T* target() const noexcept;
1544
  ```
1545
 
 
 
 
1546
  *Returns:* If `target_type() == typeid(T)` a pointer to the stored
1547
  function target; otherwise a null pointer.
1548
 
1549
+ ##### null pointer comparison functions <a id="func.wrap.func.nullptr">[[func.wrap.func.nullptr]]</a>
1550
 
1551
  ``` cpp
1552
  template <class R, class... ArgTypes>
1553
  bool operator==(const function<R(ArgTypes...)>& f, nullptr_t) noexcept;
1554
  template <class R, class... ArgTypes>
 
1568
 
1569
  ##### specialized algorithms <a id="func.wrap.func.alg">[[func.wrap.func.alg]]</a>
1570
 
1571
  ``` cpp
1572
  template<class R, class... ArgTypes>
1573
+ void swap(function<R(ArgTypes...)>& f1, function<R(ArgTypes...)>& f2) noexcept;
1574
  ```
1575
 
1576
+ *Effects:* As if by: `f1.swap(f2);`
1577
+
1578
+ ### Searchers <a id="func.search">[[func.search]]</a>
1579
+
1580
+ This subclause provides function object types ([[function.objects]])
1581
+ for operations that search for a sequence \[`pat``first`, `pat_last`) in
1582
+ another sequence \[`first`, `last`) that is provided to the object’s
1583
+ function call operator. The first sequence (the pattern to be searched
1584
+ for) is provided to the object’s constructor, and the second (the
1585
+ sequence to be searched) is provided to the function call operator.
1586
+
1587
+ Each specialization of a class template specified in this subclause
1588
+ [[func.search]] shall meet the `CopyConstructible` and `CopyAssignable`
1589
+ requirements. Template parameters named
1590
+
1591
+ - `ForwardIterator`,
1592
+ - `ForwardIterator1`,
1593
+ - `ForwardIterator2`,
1594
+ - `RandomAccessIterator`,
1595
+ - `RandomAccessIterator1`,
1596
+ - `RandomAccessIterator2`, and
1597
+ - `BinaryPredicate`
1598
+
1599
+ of templates specified in this subclause [[func.search]] shall meet the
1600
+ same requirements and semantics as specified in [[algorithms.general]].
1601
+ Template parameters named `Hash` shall meet the requirements as
1602
+ specified in [[hash.requirements]].
1603
+
1604
+ The Boyer-Moore searcher implements the Boyer-Moore search algorithm.
1605
+ The Boyer-Moore-Horspool searcher implements the Boyer-Moore-Horspool
1606
+ search algorithm. In general, the Boyer-Moore searcher will use more
1607
+ memory and give better runtime performance than Boyer-Moore-Horspool.
1608
+
1609
+ #### Class template `default_searcher` <a id="func.search.default">[[func.search.default]]</a>
1610
+
1611
+ ``` cpp
1612
+ template <class ForwardIterator1, class BinaryPredicate = equal_to<>>
1613
+ class default_searcher {
1614
+ public:
1615
+ default_searcher(ForwardIterator1 pat_first, ForwardIterator1 pat_last,
1616
+ BinaryPredicate pred = BinaryPredicate());
1617
+
1618
+ template <class ForwardIterator2>
1619
+ pair<ForwardIterator2, ForwardIterator2>
1620
+ operator()(ForwardIterator2 first, ForwardIterator2 last) const;
1621
+
1622
+ private:
1623
+ ForwardIterator1 pat_first_; // exposition only
1624
+ ForwardIterator1 pat_last_; // exposition only
1625
+ BinaryPredicate pred_; // exposition only
1626
+ };
1627
+ ```
1628
+
1629
+ ``` cpp
1630
+ default_searcher(ForwardIterator pat_first, ForwardIterator pat_last,
1631
+ BinaryPredicate pred = BinaryPredicate());
1632
+ ```
1633
+
1634
+ *Effects:* Constructs a `default_searcher` object, initializing
1635
+ `pat_first_` with `pat_first`, \texttt{pat_last\_} with `pat_last`, and
1636
+ `pred_` with `pred`.
1637
+
1638
+ *Throws:* Any exception thrown by the copy constructor of
1639
+ `BinaryPredicate` or `ForwardIterator1`.
1640
+
1641
+ ``` cpp
1642
+ template<class ForwardIterator2>
1643
+ pair<ForwardIterator2, ForwardIterator2>
1644
+ operator()(ForwardIterator2 first, ForwardIterator2 last) const;
1645
+ ```
1646
+
1647
+ *Effects:* Returns a pair of iterators `i` and `j` such that
1648
+
1649
+ - `i == search(first, last, pat_first_, pat_last_, pred_)`, and
1650
+ - if `i == last`, then `j == last`, otherwise
1651
+ `j == next(i, distance(pat_first_, pat_last_))`.
1652
+
1653
+ #### Class template `boyer_moore_searcher` <a id="func.search.bm">[[func.search.bm]]</a>
1654
+
1655
+ ``` cpp
1656
+ template <class RandomAccessIterator1,
1657
+ class Hash = hash<typename iterator_traits<RandomAccessIterator1>::value_type>,
1658
+ class BinaryPredicate = equal_to<>>
1659
+ class boyer_moore_searcher {
1660
+ public:
1661
+ boyer_moore_searcher(RandomAccessIterator1 pat_first,
1662
+ RandomAccessIterator1 pat_last,
1663
+ Hash hf = Hash(),
1664
+ BinaryPredicate pred = BinaryPredicate());
1665
+
1666
+ template <class RandomAccessIterator2>
1667
+ pair<RandomAccessIterator2, RandomAccessIterator2>
1668
+ operator()(RandomAccessIterator2 first, RandomAccessIterator2 last) const;
1669
+
1670
+ private:
1671
+ RandomAccessIterator1 pat_first_; // exposition only
1672
+ RandomAccessIterator1 pat_last_; // exposition only
1673
+ Hash hash_; // exposition only
1674
+ BinaryPredicate pred_; // exposition only
1675
+ };
1676
+ ```
1677
+
1678
+ ``` cpp
1679
+ boyer_moore_searcher(RandomAccessIterator1 pat_first,
1680
+ RandomAccessIterator1 pat_last,
1681
+ Hash hf = Hash(),
1682
+ BinaryPredicate pred = BinaryPredicate());
1683
+ ```
1684
+
1685
+ *Requires:* The value type of `RandomAccessIterator1` shall meet the
1686
+ `DefaultConstructible` requirements, the `CopyConstructible`
1687
+ requirements, and the `CopyAssignable` requirements.
1688
+
1689
+ *Requires:* For any two values `A` and `B` of the type
1690
+ `iterator_traits<RandomAccessIterator1>::value_type`, if
1691
+ `pred(A, B) == true`, then `hf(A) == hf(B)` shall be `true`.
1692
+
1693
+ *Effects:* Constructs a `boyer_moore_searcher` object, initializing
1694
+ `pat_first_` with `pat_first`, `pat_last_` with `pat_last`, `hash_` with
1695
+ `hf`, and `pred_` with `pred`.
1696
+
1697
+ *Throws:* Any exception thrown by the copy constructor of
1698
+ `RandomAccessIterator1`, or by the default constructor, copy
1699
+ constructor, or the copy assignment operator of the value type of
1700
+ `RandomAccessIterator1`, or the copy constructor or `operator()` of
1701
+ `BinaryPredicate` or `Hash`. May throw `bad_alloc` if additional memory
1702
+ needed for internal data structures cannot be allocated.
1703
+
1704
+ ``` cpp
1705
+ template <class RandomAccessIterator2>
1706
+ pair<RandomAccessIterator2, RandomAccessIterator2>
1707
+ operator()(RandomAccessIterator2 first, RandomAccessIterator2 last) const;
1708
+ ```
1709
+
1710
+ *Requires:* `RandomAccessIterator1` and `RandomAccessIterator2` shall
1711
+ have the same value type.
1712
+
1713
+ *Effects:* Finds a subsequence of equal values in a sequence.
1714
+
1715
+ *Returns:* A pair of iterators `i` and `j` such that
1716
+
1717
+ - `i` is the first iterator in the range \[`first`,
1718
+ `last - (pat_last_ - pat_first_)`) such that for every non-negative
1719
+ integer `n` less than `pat_last_ - pat_first_` the following condition
1720
+ holds: `pred(*(i + n), *(pat_first_ + n)) != false`, and
1721
+ - `j == next(i, distance(pat_first_, pat_last_))`.
1722
+
1723
+ Returns `make_pair(first, first)` if \[`pat_first_`, `pat_last_`) is
1724
+ empty, otherwise returns `make_pair(last, last)` if no such iterator is
1725
+ found.
1726
+
1727
+ *Complexity:* At most `(last - first) * (pat_last_ - pat_first_)`
1728
+ applications of the predicate.
1729
+
1730
+ #### Class template `boyer_moore_horspool_searcher` <a id="func.search.bmh">[[func.search.bmh]]</a>
1731
+
1732
+ ``` cpp
1733
+ template <class RandomAccessIterator1,
1734
+ class Hash = hash<typename iterator_traits<RandomAccessIterator1>::value_type>,
1735
+ class BinaryPredicate = equal_to<>>
1736
+ class boyer_moore_horspool_searcher {
1737
+ public:
1738
+ boyer_moore_horspool_searcher(RandomAccessIterator1 pat_first,
1739
+ RandomAccessIterator1 pat_last,
1740
+ Hash hf = Hash(),
1741
+ BinaryPredicate pred = BinaryPredicate());
1742
+
1743
+ template <class RandomAccessIterator2>
1744
+ pair<RandomAccessIterator2, RandomAccessIterator2>
1745
+ operator()(RandomAccessIterator2 first, RandomAccessIterator2 last) const;
1746
+
1747
+ private:
1748
+ RandomAccessIterator1 pat_first_; // exposition only
1749
+ RandomAccessIterator1 pat_last_; // exposition only
1750
+ Hash hash_; // exposition only
1751
+ BinaryPredicate pred_; // exposition only
1752
+ };
1753
+ ```
1754
+
1755
+ ``` cpp
1756
+ boyer_moore_horspool_searcher(RandomAccessIterator1 pat_first,
1757
+ RandomAccessIterator1 pat_last,
1758
+ Hash hf = Hash(),
1759
+ BinaryPredicate pred = BinaryPredicate());
1760
+ ```
1761
+
1762
+ *Requires:* The value type of `RandomAccessIterator1` shall meet the
1763
+ `DefaultConstructible`, `CopyConstructible`, and `CopyAssignable`
1764
+ requirements.
1765
+
1766
+ *Requires:* For any two values `A` and `B` of the type
1767
+ `iterator_traits<RandomAccessIterator1>::value_type`, if
1768
+ `pred(A, B) == true`, then `hf(A) == hf(B)` shall be `true`.
1769
+
1770
+ *Effects:* Constructs a `boyer_moore_horspool_searcher` object,
1771
+ initializing `pat_first_` with `pat_first`, `pat_last_` with `pat_last`,
1772
+ `hash_` with `hf`, and `pred_` with `pred`.
1773
+
1774
+ *Throws:* Any exception thrown by the copy constructor of
1775
+ `RandomAccessIterator1`, or by the default constructor, copy
1776
+ constructor, or the copy assignment operator of the value type of
1777
+ `RandomAccessIterator1` or the copy constructor or `operator()` of
1778
+ `BinaryPredicate` or `Hash`. May throw `bad_alloc` if additional memory
1779
+ needed for internal data structures cannot be allocated.
1780
+
1781
+ ``` cpp
1782
+ template <class RandomAccessIterator2>
1783
+ pair<RandomAccessIterator2, RandomAccessIterator2>
1784
+ operator()(RandomAccessIterator2 first, RandomAccessIterator2 last) const;
1785
+ ```
1786
+
1787
+ *Requires:* `RandomAccessIterator1` and `RandomAccessIterator2` shall
1788
+ have the same value type.
1789
+
1790
+ *Effects:* Finds a subsequence of equal values in a sequence.
1791
+
1792
+ *Returns:* A pair of iterators `i` and `j` such that
1793
+
1794
+ - `i` is the first iterator `i` in the range \[`first`,
1795
+ `last - (pat_last_ - pat_first_)`) such that for every non-negative
1796
+ integer `n` less than `pat_last_ - pat_first_` the following condition
1797
+ holds: `pred(*(i + n), *(pat_first_ + n)) != false`, and
1798
+ - `j == next(i, distance(pat_first_, pat_last_))`.
1799
+
1800
+ Returns `make_pair(first, first)` if \[`pat_first_`, `pat_last_`) is
1801
+ empty, otherwise returns `make_pair(last, last)` if no such iterator is
1802
+ found.
1803
+
1804
+ *Complexity:* At most `(last - first) * (pat_last_ - pat_first_)`
1805
+ applications of the predicate.
1806
 
1807
  ### Class template `hash` <a id="unord.hash">[[unord.hash]]</a>
1808
 
1809
  The unordered associative containers defined in [[unord]] use
1810
+ specializations of the class template `hash` ([[functional.syn]]) as
1811
+ the default hash function.
1812
+
1813
+ Each specialization of `hash` is either enabled or disabled, as
1814
+ described below.
1815
+
1816
+ [*Note 1*: Enabled specializations meet the requirements of `Hash`, and
1817
+ disabled specializations do not. — *end note*]
1818
+
1819
+ Each header that declares the template `hash` provides enabled
1820
+ specializations of `hash` for `nullptr_t` and all cv-unqualified
1821
+ arithmetic, enumeration, and pointer types. For any type `Key` for which
1822
+ neither the library nor the user provides an explicit or partial
1823
+ specialization of the class template `hash`, `hash<Key>` is disabled.
1824
+
1825
+ If the library provides an explicit or partial specialization of
1826
+ `hash<Key>`, that specialization is enabled except as noted otherwise,
1827
+ and its member functions are `noexcept` except as noted otherwise.
1828
+
1829
+ If `H` is a disabled specialization of `hash`, these values are `false`:
1830
+ `is_default_constructible_v<H>`, `is_copy_constructible_v<H>`,
1831
+ `is_move_constructible_v<H>`, `is_copy_assignable_v<H>`, and
1832
+ `is_move_assignable_v<H>`. Disabled specializations of `hash` are not
1833
+ function object types ([[function.objects]]).
1834
+
1835
+ [*Note 2*: This means that the specialization of `hash` exists, but any
1836
+ attempts to use it as a `Hash` will be ill-formed. — *end note*]
1837
+
1838
+ An enabled specialization `hash<Key>` will:
1839
 
1840
  - satisfy the `Hash` requirements ([[hash.requirements]]), with `Key`
1841
  as the function call argument type, the `DefaultConstructible`
1842
+ requirements (Table  [[tab:defaultconstructible]]), the
1843
+ `CopyAssignable` requirements (Table  [[tab:copyassignable]]),
1844
  - be swappable ([[swappable.requirements]]) for lvalues,
1845
+ - satisfy the requirement that if `k1 == k2` is `true`, `h(k1) == h(k2)`
1846
+ is also `true`, where `h` is an object of type `hash<Key>` and `k1`
1847
+ and `k2` are objects of type `Key`;
 
 
1848
  - satisfy the requirement that the expression `h(k)`, where `h` is an
1849
  object of type `hash<Key>` and `k` is an object of type `Key`, shall
1850
  not throw an exception unless `hash<Key>` is a user-defined
1851
  specialization that depends on at least one user-defined type.
1852