From Jason Turner

[func.wrap]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpu6_q5h8z/{from.md → to.md} +558 -18
tmp/tmpu6_q5h8z/{from.md → to.md} RENAMED
@@ -3,10 +3,31 @@
3
  #### General <a id="func.wrap.general">[[func.wrap.general]]</a>
4
 
5
  Subclause [[func.wrap]] describes polymorphic wrapper classes that
6
  encapsulate arbitrary callable objects.
7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  #### Class `bad_function_call` <a id="func.wrap.badcall">[[func.wrap.badcall]]</a>
9
 
10
  An exception of type `bad_function_call` is thrown by
11
  `function::operator()` [[func.wrap.func.inv]] when the function wrapper
12
  object has no target.
@@ -31,12 +52,10 @@ const char* what() const noexcept override;
31
 
32
  ##### General <a id="func.wrap.func.general">[[func.wrap.func.general]]</a>
33
 
34
  ``` cpp
35
  namespace std {
36
- template<class> class function; // not defined
37
-
38
  template<class R, class... ArgTypes>
39
  class function<R(ArgTypes...)> {
40
  public:
41
  using result_type = R;
42
 
@@ -80,16 +99,10 @@ namespace std {
80
  The `function` class template provides polymorphic wrappers that
81
  generalize the notion of a function pointer. Wrappers can store, copy,
82
  and call arbitrary callable objects [[func.def]], given a call signature
83
  [[func.def]].
84
 
85
- A callable type [[func.def]] `F` is *Lvalue-Callable* for argument types
86
- `ArgTypes` and return type `R` if the expression
87
- `INVOKE<R>(declval<F&>(), declval<ArgTypes>()...)`, considered as an
88
- unevaluated operand [[term.unevaluated.operand]], is well-formed
89
- [[func.require]].
90
-
91
  The `function` class template is a call wrapper [[func.def]] whose call
92
  signature [[func.def]] is `R(ArgTypes...)`.
93
 
94
  [*Note 1*: The types deduced by the deduction guides for `function`
95
  might change in future revisions of C++. — *end note*]
@@ -111,11 +124,11 @@ function(nullptr_t) noexcept;
111
  ``` cpp
112
  function(const function& f);
113
  ```
114
 
115
  *Ensures:* `!*this` if `!f`; otherwise, the target object of `*this` is
116
- a copy of `f.target()`.
117
 
118
  *Throws:* Nothing if `f`’s target is a specialization of
119
  `reference_wrapper` or a function pointer. Otherwise, may throw
120
  `bad_alloc` or any exception thrown by the copy constructor of the
121
  stored callable object.
@@ -145,12 +158,11 @@ template<class F> function(F&& f);
145
  Let `FD` be `decay_t<F>`.
146
 
147
  *Constraints:*
148
 
149
  - `is_same_v<remove_cvref_t<F>, function>` is `false`, and
150
- - `FD` is Lvalue-Callable [[func.wrap.func]] for argument types
151
- `ArgTypes...` and return type `R`.
152
 
153
  *Mandates:*
154
 
155
  - `is_copy_constructible_v<FD>` is `true`, and
156
  - `is_constructible_v<FD, F>` is `true`.
@@ -231,12 +243,12 @@ function& operator=(nullptr_t) noexcept;
231
 
232
  ``` cpp
233
  template<class F> function& operator=(F&& f);
234
  ```
235
 
236
- *Constraints:* `decay_t<F>` is Lvalue-Callable [[func.wrap.func]] for
237
- argument types `ArgTypes...` and return type `R`.
238
 
239
  *Effects:* As if by: `function(std::forward<F>(f)).swap(*this);`
240
 
241
  *Returns:* `*this`.
242
 
@@ -316,11 +328,11 @@ template<class R, class... ArgTypes>
316
  void swap(function<R(ArgTypes...)>& f1, function<R(ArgTypes...)>& f2) noexcept;
317
  ```
318
 
319
  *Effects:* As if by: `f1.swap(f2);`
320
 
321
- #### Move only wrapper <a id="func.wrap.move">[[func.wrap.move]]</a>
322
 
323
  ##### General <a id="func.wrap.move.general">[[func.wrap.move.general]]</a>
324
 
325
  The header provides partial specializations of `move_only_function` for
326
  each combination of the possible replacements of the placeholders cv,
@@ -338,18 +350,16 @@ above, there is a placeholder *inv-quals* defined as follows:
338
 
339
  ##### Class template `move_only_function` <a id="func.wrap.move.class">[[func.wrap.move.class]]</a>
340
 
341
  ``` cpp
342
  namespace std {
343
- template<class... S> class move_only_function; // not defined
344
-
345
  template<class R, class... ArgTypes>
346
  class move_only_function<R(ArgTypes...) cv ref noexcept(noex)> {
347
  public:
348
  using result_type = R;
349
 
350
- // [func.wrap.move.ctor], constructors, assignment, and destructor
351
  move_only_function() noexcept;
352
  move_only_function(nullptr_t) noexcept;
353
  move_only_function(move_only_function&&) noexcept;
354
  template<class F> move_only_function(F&&);
355
  template<class T, class... Args>
@@ -389,11 +399,11 @@ dynamically allocated memory for a small contained value.
389
 
390
  [*Note 1*: Such small-object optimization can only be applied to a type
391
  `T` for which `is_nothrow_move_constructible_v<T>` is
392
  `true`. — *end note*]
393
 
394
- ##### Constructors, assignment, and destructor <a id="func.wrap.move.ctor">[[func.wrap.move.ctor]]</a>
395
 
396
  ``` cpp
397
  template<class VT>
398
  static constexpr bool is-callable-from = see below;
399
  ```
@@ -582,5 +592,535 @@ friend void swap(move_only_function& f1, move_only_function& f2) noexcept;
582
  friend bool operator==(const move_only_function& f, nullptr_t) noexcept;
583
  ```
584
 
585
  *Returns:* `true` if `f` has no target object, otherwise `false`.
586
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  #### General <a id="func.wrap.general">[[func.wrap.general]]</a>
4
 
5
  Subclause [[func.wrap]] describes polymorphic wrapper classes that
6
  encapsulate arbitrary callable objects.
7
 
8
+ Let `t` be an object of a type that is a specialization of `function`,
9
+ `copyable_function`, or `move_only_function`, such that the target
10
+ object `x` of `t` has a type that is a specialization of `function`,
11
+ `copyable_function`, or `move_only_function`. Each argument of the
12
+ invocation of `x` evaluated as part of the invocation of `t` may alias
13
+ an argument in the same position in the invocation of `t` that has the
14
+ same type, even if the corresponding parameter is not of reference type.
15
+
16
+ [*Example 1*:
17
+
18
+ ``` cpp
19
+ move_only_function<void(T)> f{copyable_function<void(T)>{[](T) {}}};
20
+ T t;
21
+ f(t); // it is unspecified how many copies of T are made
22
+ ```
23
+
24
+ — *end example*]
25
+
26
+ *Recommended practice:* Implementations should avoid double wrapping
27
+ when constructing polymorphic wrappers from one another.
28
+
29
  #### Class `bad_function_call` <a id="func.wrap.badcall">[[func.wrap.badcall]]</a>
30
 
31
  An exception of type `bad_function_call` is thrown by
32
  `function::operator()` [[func.wrap.func.inv]] when the function wrapper
33
  object has no target.
 
52
 
53
  ##### General <a id="func.wrap.func.general">[[func.wrap.func.general]]</a>
54
 
55
  ``` cpp
56
  namespace std {
 
 
57
  template<class R, class... ArgTypes>
58
  class function<R(ArgTypes...)> {
59
  public:
60
  using result_type = R;
61
 
 
99
  The `function` class template provides polymorphic wrappers that
100
  generalize the notion of a function pointer. Wrappers can store, copy,
101
  and call arbitrary callable objects [[func.def]], given a call signature
102
  [[func.def]].
103
 
 
 
 
 
 
 
104
  The `function` class template is a call wrapper [[func.def]] whose call
105
  signature [[func.def]] is `R(ArgTypes...)`.
106
 
107
  [*Note 1*: The types deduced by the deduction guides for `function`
108
  might change in future revisions of C++. — *end note*]
 
124
  ``` cpp
125
  function(const function& f);
126
  ```
127
 
128
  *Ensures:* `!*this` if `!f`; otherwise, the target object of `*this` is
129
+ a copy of the target object of `f`.
130
 
131
  *Throws:* Nothing if `f`’s target is a specialization of
132
  `reference_wrapper` or a function pointer. Otherwise, may throw
133
  `bad_alloc` or any exception thrown by the copy constructor of the
134
  stored callable object.
 
158
  Let `FD` be `decay_t<F>`.
159
 
160
  *Constraints:*
161
 
162
  - `is_same_v<remove_cvref_t<F>, function>` is `false`, and
163
+ - `is_invocable_r_v<R, FD&, ArgTypes...>` is `true`.
 
164
 
165
  *Mandates:*
166
 
167
  - `is_copy_constructible_v<FD>` is `true`, and
168
  - `is_constructible_v<FD, F>` is `true`.
 
243
 
244
  ``` cpp
245
  template<class F> function& operator=(F&& f);
246
  ```
247
 
248
+ *Constraints:* `is_invocable_r_v<R, decay_t<F>&, ArgTypes...>` is
249
+ `true`.
250
 
251
  *Effects:* As if by: `function(std::forward<F>(f)).swap(*this);`
252
 
253
  *Returns:* `*this`.
254
 
 
328
  void swap(function<R(ArgTypes...)>& f1, function<R(ArgTypes...)>& f2) noexcept;
329
  ```
330
 
331
  *Effects:* As if by: `f1.swap(f2);`
332
 
333
+ #### Move-only wrapper <a id="func.wrap.move">[[func.wrap.move]]</a>
334
 
335
  ##### General <a id="func.wrap.move.general">[[func.wrap.move.general]]</a>
336
 
337
  The header provides partial specializations of `move_only_function` for
338
  each combination of the possible replacements of the placeholders cv,
 
350
 
351
  ##### Class template `move_only_function` <a id="func.wrap.move.class">[[func.wrap.move.class]]</a>
352
 
353
  ``` cpp
354
  namespace std {
 
 
355
  template<class R, class... ArgTypes>
356
  class move_only_function<R(ArgTypes...) cv ref noexcept(noex)> {
357
  public:
358
  using result_type = R;
359
 
360
+ // [func.wrap.move.ctor], constructors, assignments, and destructor
361
  move_only_function() noexcept;
362
  move_only_function(nullptr_t) noexcept;
363
  move_only_function(move_only_function&&) noexcept;
364
  template<class F> move_only_function(F&&);
365
  template<class T, class... Args>
 
399
 
400
  [*Note 1*: Such small-object optimization can only be applied to a type
401
  `T` for which `is_nothrow_move_constructible_v<T>` is
402
  `true`. — *end note*]
403
 
404
+ ##### Constructors, assignments, and destructor <a id="func.wrap.move.ctor">[[func.wrap.move.ctor]]</a>
405
 
406
  ``` cpp
407
  template<class VT>
408
  static constexpr bool is-callable-from = see below;
409
  ```
 
592
  friend bool operator==(const move_only_function& f, nullptr_t) noexcept;
593
  ```
594
 
595
  *Returns:* `true` if `f` has no target object, otherwise `false`.
596
 
597
+ #### Copyable wrapper <a id="func.wrap.copy">[[func.wrap.copy]]</a>
598
+
599
+ ##### General <a id="func.wrap.copy.general">[[func.wrap.copy.general]]</a>
600
+
601
+ The header provides partial specializations of `copyable_function` for
602
+ each combination of the possible replacements of the placeholders cv,
603
+ *ref*, and *noex* where
604
+
605
+ - cv is either const or empty,
606
+ - *ref* is either `&`, `&&`, or empty, and
607
+ - *noex* is either `true` or `false`.
608
+
609
+ For each of the possible combinations of the placeholders mentioned
610
+ above, there is a placeholder *inv-quals* defined as follows:
611
+
612
+ - If *ref* is empty, let *inv-quals* be cv`&`,
613
+ - otherwise, let *inv-quals* be cv *ref*.
614
+
615
+ ##### Class template `copyable_function` <a id="func.wrap.copy.class">[[func.wrap.copy.class]]</a>
616
+
617
+ ``` cpp
618
+ namespace std {
619
+ template<class R, class... ArgTypes>
620
+ class copyable_function<R(ArgTypes...) cv ref noexcept(noex)> {
621
+ public:
622
+ using result_type = R;
623
+
624
+ // [func.wrap.copy.ctor], constructors, assignments, and destructor
625
+ copyable_function() noexcept;
626
+ copyable_function(nullptr_t) noexcept;
627
+ copyable_function(const copyable_function&);
628
+ copyable_function(copyable_function&&) noexcept;
629
+ template<class F> copyable_function(F&&);
630
+ template<class T, class... Args>
631
+ explicit copyable_function(in_place_type_t<T>, Args&&...);
632
+ template<class T, class U, class... Args>
633
+ explicit copyable_function(in_place_type_t<T>, initializer_list<U>, Args&&...);
634
+
635
+ copyable_function& operator=(const copyable_function&);
636
+ copyable_function& operator=(copyable_function&&);
637
+ copyable_function& operator=(nullptr_t) noexcept;
638
+ template<class F> copyable_function& operator=(F&&);
639
+
640
+ ~copyable_function();
641
+
642
+ // [func.wrap.copy.inv], invocation
643
+ explicit operator bool() const noexcept;
644
+ R operator()(ArgTypes...) cv ref noexcept(noex);
645
+
646
+ // [func.wrap.copy.util], utility
647
+ void swap(copyable_function&) noexcept;
648
+ friend void swap(copyable_function&, copyable_function&) noexcept;
649
+ friend bool operator==(const copyable_function&, nullptr_t) noexcept;
650
+
651
+ private:
652
+ template<class VT>
653
+ static constexpr bool is-callable-from = see below; // exposition only
654
+ };
655
+ }
656
+ ```
657
+
658
+ The `copyable_function` class template provides polymorphic wrappers
659
+ that generalize the notion of a callable object [[func.def]]. These
660
+ wrappers can store, copy, move, and call arbitrary callable objects,
661
+ given a call signature.
662
+
663
+ *Recommended practice:* Implementations should avoid the use of
664
+ dynamically allocated memory for a small contained value.
665
+
666
+ [*Note 1*: Such small-object optimization can only be applied to a type
667
+ `T` for which `is_nothrow_move_constructible_v<T>` is
668
+ `true`. — *end note*]
669
+
670
+ ##### Constructors, assignments, and destructor <a id="func.wrap.copy.ctor">[[func.wrap.copy.ctor]]</a>
671
+
672
+ ``` cpp
673
+ template<class VT>
674
+ static constexpr bool is-callable-from = see below;
675
+ ```
676
+
677
+ If *noex* is `true`, *`is-callable-from`*`<VT>` is equal to:
678
+
679
+ ``` cpp
680
+ is_nothrow_invocable_r_v<R, VT cv ref, ArgTypes...> &&
681
+ is_nothrow_invocable_r_v<R, VT inv-quals, ArgTypes...>
682
+ ```
683
+
684
+ Otherwise, *`is-callable-from`*`<VT>` is equal to:
685
+
686
+ ``` cpp
687
+ is_invocable_r_v<R, VT cv ref, ArgTypes...> &&
688
+ is_invocable_r_v<R, VT inv-quals, ArgTypes...>
689
+ ```
690
+
691
+ ``` cpp
692
+ copyable_function() noexcept;
693
+ copyable_function(nullptr_t) noexcept;
694
+ ```
695
+
696
+ *Ensures:* `*this` has no target object.
697
+
698
+ ``` cpp
699
+ copyable_function(const copyable_function& f);
700
+ ```
701
+
702
+ *Ensures:* `*this` has no target object if `f` had no target object.
703
+ Otherwise, the target object of `*this` is a copy of the target object
704
+ of `f`.
705
+
706
+ *Throws:* Any exception thrown by the initialization of the target
707
+ object. May throw `bad_alloc`.
708
+
709
+ ``` cpp
710
+ copyable_function(copyable_function&& f) noexcept;
711
+ ```
712
+
713
+ *Ensures:* The target object of `*this` is the target object `f` had
714
+ before construction, and `f` is in a valid state with an unspecified
715
+ value.
716
+
717
+ ``` cpp
718
+ template<class F> copyable_function(F&& f);
719
+ ```
720
+
721
+ Let `VT` be `decay_t<F>`.
722
+
723
+ *Constraints:*
724
+
725
+ - `remove_cvref_t<F>` is not the same type as `copyable_function`, and
726
+ - `remove_cvref_t<F>` is not a specialization of `in_place_type_t`, and
727
+ - *`is-callable-from`*`<VT>` is `true`.
728
+
729
+ *Mandates:*
730
+
731
+ - `is_constructible_v<VT, F>` is `true`, and
732
+ - `is_copy_constructible_v<VT>` is `true`.
733
+
734
+ *Preconditions:* `VT` meets the *Cpp17Destructible* and
735
+ *Cpp17CopyConstructible* requirements.
736
+
737
+ *Ensures:* `*this` has no target object if any of the following hold:
738
+
739
+ - `f` is a null function pointer value, or
740
+ - `f` is a null member pointer value, or
741
+ - `remove_cvref_t<F>` is a specialization of the `copyable_function`
742
+ class template, and `f` has no target object.
743
+
744
+ Otherwise, `*this` has a target object of type `VT`
745
+ direct-non-list-initialized with `std::forward<F>(f)`.
746
+
747
+ *Throws:* Any exception thrown by the initialization of the target
748
+ object. May throw `bad_alloc` unless `VT` is a function pointer or a
749
+ specialization of `reference_wrapper`.
750
+
751
+ ``` cpp
752
+ template<class T, class... Args>
753
+ explicit copyable_function(in_place_type_t<T>, Args&&... args);
754
+ ```
755
+
756
+ Let `VT` be `decay_t<T>`.
757
+
758
+ *Constraints:*
759
+
760
+ - `is_constructible_v<VT, Args...>` is `true`, and
761
+ - *`is-callable-from`*`<VT>` is `true`.
762
+
763
+ *Mandates:*
764
+
765
+ - `VT` is the same type as `T`, and
766
+ - `is_copy_constructible_v<VT>` is `true`.
767
+
768
+ *Preconditions:* `VT` meets the *Cpp17Destructible* and
769
+ *Cpp17CopyConstructible* requirements.
770
+
771
+ *Ensures:* `*this` has a target object of type `VT`
772
+ direct-non-list-initialized with `std::forward<Args>(args)...`.
773
+
774
+ *Throws:* Any exception thrown by the initialization of the target
775
+ object. May throw `bad_alloc` unless `VT` is a pointer or a
776
+ specialization of `reference_wrapper`.
777
+
778
+ ``` cpp
779
+ template<class T, class U, class... Args>
780
+ explicit copyable_function(in_place_type_t<T>, initializer_list<U> ilist, Args&&... args);
781
+ ```
782
+
783
+ Let `VT` be `decay_t<T>`.
784
+
785
+ *Constraints:*
786
+
787
+ - `is_constructible_v<VT, initializer_list<U>&, Args...>` is `true`, and
788
+ - *`is-callable-from`*`<VT>` is `true`.
789
+
790
+ *Mandates:*
791
+
792
+ - `VT` is the same type as `T`, and
793
+ - `is_copy_constructible_v<VT>` is `true`.
794
+
795
+ *Preconditions:* `VT` meets the *Cpp17Destructible* and
796
+ *Cpp17CopyConstructible* requirements.
797
+
798
+ *Ensures:* `*this` has a target object of type `VT`
799
+ direct-non-list-initialized with `ilist, std::forward<Args>(args)...`.
800
+
801
+ *Throws:* Any exception thrown by the initialization of the target
802
+ object. May throw `bad_alloc` unless `VT` is a pointer or a
803
+ specialization of `reference_wrapper`.
804
+
805
+ ``` cpp
806
+ copyable_function& operator=(const copyable_function& f);
807
+ ```
808
+
809
+ *Effects:* Equivalent to: `copyable_function(f).swap(*this);`
810
+
811
+ *Returns:* `*this`.
812
+
813
+ ``` cpp
814
+ copyable_function& operator=(copyable_function&& f);
815
+ ```
816
+
817
+ *Effects:* Equivalent to: `copyable_function(std::move(f)).swap(*this);`
818
+
819
+ *Returns:* `*this`.
820
+
821
+ ``` cpp
822
+ copyable_function& operator=(nullptr_t) noexcept;
823
+ ```
824
+
825
+ *Effects:* Destroys the target object of `*this`, if any.
826
+
827
+ *Returns:* `*this`.
828
+
829
+ ``` cpp
830
+ template<class F> copyable_function& operator=(F&& f);
831
+ ```
832
+
833
+ *Effects:* Equivalent to:
834
+ `copyable_function(std::forward<F>(f)).swap(*this);`
835
+
836
+ *Returns:* `*this`.
837
+
838
+ ``` cpp
839
+ ~copyable_function();
840
+ ```
841
+
842
+ *Effects:* Destroys the target object of `*this`, if any.
843
+
844
+ ##### Invocation <a id="func.wrap.copy.inv">[[func.wrap.copy.inv]]</a>
845
+
846
+ ``` cpp
847
+ explicit operator bool() const noexcept;
848
+ ```
849
+
850
+ *Returns:* `true` if `*this` has a target object, otherwise `false`.
851
+
852
+ ``` cpp
853
+ R operator()(ArgTypes... args) cv ref noexcept(noex);
854
+ ```
855
+
856
+ *Preconditions:* `*this` has a target object.
857
+
858
+ *Effects:* Equivalent to:
859
+
860
+ ``` cpp
861
+ return INVOKE<R>(static_cast<F inv-quals>(f), std::forward<ArgTypes>(args)...);
862
+ ```
863
+
864
+ where `f` is an lvalue designating the target object of `*this` and `F`
865
+ is the type of `f`.
866
+
867
+ ##### Utility <a id="func.wrap.copy.util">[[func.wrap.copy.util]]</a>
868
+
869
+ ``` cpp
870
+ void swap(copyable_function& other) noexcept;
871
+ ```
872
+
873
+ *Effects:* Exchanges the target objects of `*this` and `other`.
874
+
875
+ ``` cpp
876
+ friend void swap(copyable_function& f1, copyable_function& f2) noexcept;
877
+ ```
878
+
879
+ *Effects:* Equivalent to `f1.swap(f2)`.
880
+
881
+ ``` cpp
882
+ friend bool operator==(const copyable_function& f, nullptr_t) noexcept;
883
+ ```
884
+
885
+ *Returns:* `true` if `f` has no target object, otherwise `false`.
886
+
887
+ #### Non-owning wrapper <a id="func.wrap.ref">[[func.wrap.ref]]</a>
888
+
889
+ ##### General <a id="func.wrap.ref.general">[[func.wrap.ref.general]]</a>
890
+
891
+ The header provides partial specializations of `function_ref` for each
892
+ combination of the possible replacements of the placeholders cv and
893
+ *noex* where:
894
+
895
+ - cv is either const or empty, and
896
+ - *noex* is either `true` or `false`.
897
+
898
+ ##### Class template `function_ref` <a id="func.wrap.ref.class">[[func.wrap.ref.class]]</a>
899
+
900
+ ``` cpp
901
+ namespace std {
902
+ template<class R, class... ArgTypes>
903
+ class function_ref<R(ArgTypes...) cv noexcept(noex)> {
904
+ public:
905
+ // [func.wrap.ref.ctor], constructors and assignment operators
906
+ template<class F> function_ref(F*) noexcept;
907
+ template<class F> constexpr function_ref(F&&) noexcept;
908
+ template<auto f> constexpr function_ref(nontype_t<f>) noexcept;
909
+ template<auto f, class U> constexpr function_ref(nontype_t<f>, U&&) noexcept;
910
+ template<auto f, class T> constexpr function_ref(nontype_t<f>, cv T*) noexcept;
911
+
912
+ constexpr function_ref(const function_ref&) noexcept = default;
913
+ constexpr function_ref& operator=(const function_ref&) noexcept = default;
914
+ template<class T> function_ref& operator=(T) = delete;
915
+
916
+ // [func.wrap.ref.inv], invocation
917
+ R operator()(ArgTypes...) const noexcept(noex);
918
+
919
+ private:
920
+ template<class... T>
921
+ static constexpr bool is-invocable-using = see belownc; // exposition only
922
+
923
+ R (*thunk-ptr)(BoundEntityType, ArgTypes&&...) noexcept(noex); // exposition only
924
+ BoundEntityType bound-entity; // exposition only
925
+ };
926
+
927
+ // [func.wrap.ref.deduct], deduction guides
928
+ template<class F>
929
+ function_ref(F*) -> function_ref<F>;
930
+ template<auto f>
931
+ function_ref(nontype_t<f>) -> function_ref<see below>;
932
+ template<auto f, class T>
933
+ function_ref(nontype_t<f>, T&&) -> function_ref<see below>;
934
+ }
935
+ ```
936
+
937
+ An object of class `function_ref<R(Args...) cv noexcept(noex)>` stores a
938
+ pointer to function *`thunk-ptr`* and an object *`bound-entity`*. The
939
+ object *`bound-entity`* has an unspecified trivially copyable type
940
+ *`BoundEntityType`*, that models `copyable` and is capable of storing a
941
+ pointer to object value or a pointer to function value. The type of
942
+ *`thunk-ptr`* is `R(*)(BoundEntityType, Args&&...) noexcept(noex)`.
943
+
944
+ Each specialization of `function_ref` is a trivially copyable type
945
+ [[term.trivially.copyable.type]] that models `copyable`.
946
+
947
+ Within subclause  [[func.wrap.ref]], `call-args` is an argument pack
948
+ with elements such that
949
+
950
+ ``` cpp
951
+ decltype((call-args))...
952
+ ```
953
+
954
+ denote `ArgTypes&&...` respectively.
955
+
956
+ ##### Constructors and assignment operators <a id="func.wrap.ref.ctor">[[func.wrap.ref.ctor]]</a>
957
+
958
+ ``` cpp
959
+ template<class... T>
960
+ static constexpr bool is-invocable-using = see below;
961
+ ```
962
+
963
+ If *noex* is `true`, *`is-invocable-using`*`<T...>` is equal to:
964
+
965
+ ``` cpp
966
+ is_nothrow_invocable_r_v<R, T..., ArgTypes...>
967
+ ```
968
+
969
+ Otherwise, *`is-invocable-using`*`<T...>` is equal to:
970
+
971
+ ``` cpp
972
+ is_invocable_r_v<R, T..., ArgTypes...>
973
+ ```
974
+
975
+ ``` cpp
976
+ template<class F> function_ref(F* f) noexcept;
977
+ ```
978
+
979
+ *Constraints:*
980
+
981
+ - `is_function_v<F>` is `true`, and
982
+ - *`is-invocable-using`*`<F>` is `true`.
983
+
984
+ *Preconditions:* `f` is not a null pointer.
985
+
986
+ *Effects:* Initializes *bound-entity* with `f`, and *thunk-ptr* with the
987
+ address of a function *`thunk`* such that
988
+ *`thunk`*`(`*`bound-entity`*`, `*`call-args`*`...)` is
989
+ expression-equivalent [[defns.expression.equivalent]] to
990
+ `invoke_r<R>(f, `*`call-args`*`...)`.
991
+
992
+ ``` cpp
993
+ template<class F> constexpr function_ref(F&& f) noexcept;
994
+ ```
995
+
996
+ Let `T` be `remove_reference_t<F>`.
997
+
998
+ *Constraints:*
999
+
1000
+ - `remove_cvref_t<F>` is not the same type as `function_ref`,
1001
+ - `is_member_pointer_v<T>` is `false`, and
1002
+ - *`is-invocable-using`*`<cv T&>` is `true`.
1003
+
1004
+ *Effects:* Initializes *bound-entity* with `addressof(f)`, and
1005
+ *thunk-ptr* with the address of a function *`thunk`* such that
1006
+ *`thunk`*`(`*`bound-entity`*`, `*`call-args`*`...)` is
1007
+ expression-equivalent [[defns.expression.equivalent]] to
1008
+ `invoke_r<R>(static_cast<cv T&>(f), `*`call-args`*`...)`.
1009
+
1010
+ ``` cpp
1011
+ template<auto f> constexpr function_ref(nontype_t<f>) noexcept;
1012
+ ```
1013
+
1014
+ Let `F` be `decltype(f)`.
1015
+
1016
+ *Constraints:* *`is-invocable-using`*`<F>` is `true`.
1017
+
1018
+ *Mandates:* If `is_pointer_v<F> || is_member_pointer_v<F>` is `true`,
1019
+ then `f != nullptr` is `true`.
1020
+
1021
+ *Effects:* Initializes *bound-entity* with a pointer to an unspecified
1022
+ object or null pointer value, and *thunk-ptr* with the address of a
1023
+ function *`thunk`* such that
1024
+ *`thunk`*`(`*`bound-entity`*`, `*`call-args`*`...)` is
1025
+ expression-equivalent [[defns.expression.equivalent]] to
1026
+ `invoke_r<R>(f, `*`call-args`*`...)`.
1027
+
1028
+ ``` cpp
1029
+ template<auto f, class U>
1030
+ constexpr function_ref(nontype_t<f>, U&& obj) noexcept;
1031
+ ```
1032
+
1033
+ Let `T` be `remove_reference_t<U>` and `F` be `decltype(f)`.
1034
+
1035
+ *Constraints:*
1036
+
1037
+ - `is_rvalue_reference_v<U&&>` is `false`, and
1038
+ - *`is-invocable-using`*`<F, cv T&>` is `true`.
1039
+
1040
+ *Mandates:* If `is_pointer_v<F> || is_member_pointer_v<F>` is `true`,
1041
+ then `f != nullptr` is `true`.
1042
+
1043
+ *Effects:* Initializes *bound-entity* with `addressof(obj)`, and
1044
+ *thunk-ptr* with the address of a function *`thunk`* such that
1045
+ *`thunk`*`(`*`bound-entity`*`, `*`call-args`*`...)` is
1046
+ expression-equivalent [[defns.expression.equivalent]] to
1047
+ `invoke_r<R>(f, static_cast<cv T&>(obj), `*`call-args`*`...)`.
1048
+
1049
+ ``` cpp
1050
+ template<auto f, class T>
1051
+ constexpr function_ref(nontype_t<f>, cv T* obj) noexcept;
1052
+ ```
1053
+
1054
+ Let `F` be `decltype(f)`.
1055
+
1056
+ *Constraints:* *`is-invocable-using`*`<F, cv T*>` is `true`.
1057
+
1058
+ *Mandates:* If `is_pointer_v<F> || is_member_pointer_v<F>` is `true`,
1059
+ then `f != nullptr` is `true`.
1060
+
1061
+ *Preconditions:* If `is_member_pointer_v<F>` is `true`, `obj` is not a
1062
+ null pointer.
1063
+
1064
+ *Effects:* Initializes *bound-entity* with `obj`, and *thunk-ptr* with
1065
+ the address of a function *`thunk`* such that
1066
+ *`thunk`*`(`*`bound-entity`*`, `*`call-args`*`...)` is
1067
+ expression-equivalent [[defns.expression.equivalent]] to
1068
+ `invoke_r<R>(f, obj, `*`call-args`*`...)`.
1069
+
1070
+ ``` cpp
1071
+ template<class T> function_ref& operator=(T) = delete;
1072
+ ```
1073
+
1074
+ *Constraints:*
1075
+
1076
+ - `T` is not the same type as `function_ref`,
1077
+ - `is_pointer_v<T>` is `false`, and
1078
+ - `T` is not a specialization of `nontype_t`.
1079
+
1080
+ ##### Invocation <a id="func.wrap.ref.inv">[[func.wrap.ref.inv]]</a>
1081
+
1082
+ ``` cpp
1083
+ R operator()(ArgTypes... args) const noexcept(noex);
1084
+ ```
1085
+
1086
+ *Effects:* Equivalent to:
1087
+ `return `*`thunk-ptr`*`(`*`bound-entity`*`, std::forward<ArgTypes>(args)...);`
1088
+
1089
+ ##### Deduction guides <a id="func.wrap.ref.deduct">[[func.wrap.ref.deduct]]</a>
1090
+
1091
+ ``` cpp
1092
+ template<class F>
1093
+ function_ref(F*) -> function_ref<F>;
1094
+ ```
1095
+
1096
+ *Constraints:* `is_function_v<F>` is `true`.
1097
+
1098
+ ``` cpp
1099
+ template<auto f>
1100
+ function_ref(nontype_t<f>) -> function_ref<see below>;
1101
+ ```
1102
+
1103
+ Let `F` be `remove_pointer_t<decltype(f)>`.
1104
+
1105
+ *Constraints:* `is_function_v<F>` is `true`.
1106
+
1107
+ *Remarks:* The deduced type is `function_ref<F>`.
1108
+
1109
+ ``` cpp
1110
+ template<auto f, class T>
1111
+ function_ref(nontype_t<f>, T&&) -> function_ref<see below>;
1112
+ ```
1113
+
1114
+ Let `F` be `decltype(f)`.
1115
+
1116
+ *Constraints:*
1117
+
1118
+ - `F` is of the form `R(G::*)(A...) cv `\\ₒₚₜ ` noexcept(E)` for a type
1119
+ `G`, or
1120
+ - `F` is of the form `M G::*` for a type `G` and an object type `M`, in
1121
+ which case let `R` be `invoke_result_t<F, T&>`, `A...` be an empty
1122
+ pack, and `E` be `false`, or
1123
+ - `F` is of the form `R(*)(G, A...) noexcept(E)` for a type `G`.
1124
+
1125
+ *Remarks:* The deduced type is `function_ref<R(A...) noexcept(E)>`.
1126
+