From Jason Turner

[func.wrap.func.con]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpbottwk9p/{from.md → to.md} +44 -27
tmp/tmpbottwk9p/{from.md → to.md} RENAMED
@@ -14,70 +14,87 @@ function(nullptr_t) noexcept;
14
 
15
  ``` cpp
16
  function(const function& f);
17
  ```
18
 
19
- *Ensures:* `!*this` if `!f`; otherwise, `*this` targets a copy of
20
- `f.target()`.
21
 
22
  *Throws:* Nothing if `f`’s target is a specialization of
23
  `reference_wrapper` or a function pointer. Otherwise, may throw
24
  `bad_alloc` or any exception thrown by the copy constructor of the
25
  stored callable object.
26
 
27
- [*Note 1*: Implementations should avoid the use of dynamically
28
- allocated memory for small callable objects, for example, where `f`’s
29
- target is an object holding only a pointer or reference to an object and
30
- a member function pointer. — *end note*]
31
 
32
  ``` cpp
33
  function(function&& f) noexcept;
34
  ```
35
 
36
  *Ensures:* If `!f`, `*this` has no target; otherwise, the target of
37
  `*this` is equivalent to the target of `f` before the construction, and
38
  `f` is in a valid state with an unspecified value.
39
 
40
- [*Note 2*: Implementations should avoid the use of dynamically
41
- allocated memory for small callable objects, for example, where `f`’s
42
- target is an object holding only a pointer or reference to an object and
43
- a member function pointer. — *end note*]
44
 
45
  ``` cpp
46
- template<class F> function(F f);
47
  ```
48
 
49
- *Constraints:* `F` is Lvalue-Callable [[func.wrap.func]] for argument
50
- types `ArgTypes...` and return type `R`.
51
 
52
- *Preconditions:* `F` meets the *Cpp17CopyConstructible* requirements.
53
 
54
- *Ensures:* `!*this` if any of the following hold:
 
 
 
 
 
 
 
 
 
 
 
55
 
56
  - `f` is a null function pointer value.
57
  - `f` is a null member pointer value.
58
- - `F` is an instance of the `function` class template, and `!f`.
 
59
 
60
- Otherwise, `*this` targets a copy of `f` initialized with
61
- `std::move(f)`.
62
 
63
- [*Note 3*: Implementations should avoid the use of dynamically
64
- allocated memory for small callable objects, for example, where `f` is
65
- an object holding only a pointer or reference to an object and a member
66
- function pointer. — *end note*]
67
 
68
- *Throws:* Nothing if `f` is a specialization of `reference_wrapper` or a
69
- function pointer. Otherwise, may throw `bad_alloc` or any exception
70
- thrown by `F`’s copy or move constructor.
 
71
 
72
  ``` cpp
73
  template<class F> function(F) -> function<see below>;
74
  ```
75
 
76
  *Constraints:* `&F::operator()` is well-formed when treated as an
77
- unevaluated operand and `decltype(&F::operator())` is of the form
78
- `R(G::*)(A...)` cv \\ₒₚₜ ` `noexceptₒₚₜ for a class type `G`.
 
 
 
 
 
 
79
 
80
  *Remarks:* The deduced type is `function<R(A...)>`.
81
 
82
  [*Example 1*:
83
 
 
14
 
15
  ``` cpp
16
  function(const function& f);
17
  ```
18
 
19
+ *Ensures:* `!*this` if `!f`; otherwise, the target object of `*this` is
20
+ a copy of `f.target()`.
21
 
22
  *Throws:* Nothing if `f`’s target is a specialization of
23
  `reference_wrapper` or a function pointer. Otherwise, may throw
24
  `bad_alloc` or any exception thrown by the copy constructor of the
25
  stored callable object.
26
 
27
+ *Recommended practice:* Implementations should avoid the use of
28
+ dynamically allocated memory for small callable objects, for example,
29
+ where `f`’s target is an object holding only a pointer or reference to
30
+ an object and a member function pointer.
31
 
32
  ``` cpp
33
  function(function&& f) noexcept;
34
  ```
35
 
36
  *Ensures:* If `!f`, `*this` has no target; otherwise, the target of
37
  `*this` is equivalent to the target of `f` before the construction, and
38
  `f` is in a valid state with an unspecified value.
39
 
40
+ *Recommended practice:* Implementations should avoid the use of
41
+ dynamically allocated memory for small callable objects, for example,
42
+ where `f`’s target is an object holding only a pointer or reference to
43
+ an object and a member function pointer.
44
 
45
  ``` cpp
46
+ template<class F> function(F&& f);
47
  ```
48
 
49
+ Let `FD` be `decay_t<F>`.
 
50
 
51
+ *Constraints:*
52
 
53
+ - `is_same_v<remove_cvref_t<F>, function>` is `false`, and
54
+ - `FD` is Lvalue-Callable [[func.wrap.func]] for argument types
55
+ `ArgTypes...` and return type `R`.
56
+
57
+ *Mandates:*
58
+
59
+ - `is_copy_constructible_v<FD>` is `true`, and
60
+ - `is_constructible_v<FD, F>` is `true`.
61
+
62
+ *Preconditions:* `FD` meets the *Cpp17CopyConstructible* requirements.
63
+
64
+ *Ensures:* `!*this` is `true` if any of the following hold:
65
 
66
  - `f` is a null function pointer value.
67
  - `f` is a null member pointer value.
68
+ - `remove_cvref_t<F>` is a specialization of the `function` class
69
+ template, and `!f` is `true`.
70
 
71
+ Otherwise, `*this` has a target object of type `FD`
72
+ direct-non-list-initialized with `std::forward<F>(f)`.
73
 
74
+ *Throws:* Nothing if `FD` is a specialization of `reference_wrapper` or
75
+ a function pointer type. Otherwise, may throw `bad_alloc` or any
76
+ exception thrown by the initialization of the target object.
 
77
 
78
+ *Recommended practice:* Implementations should avoid the use of
79
+ dynamically allocated memory for small callable objects, for example,
80
+ where `f` refers to an object holding only a pointer or reference to an
81
+ object and a member function pointer.
82
 
83
  ``` cpp
84
  template<class F> function(F) -> function<see below>;
85
  ```
86
 
87
  *Constraints:* `&F::operator()` is well-formed when treated as an
88
+ unevaluated operand and either
89
+
90
+ - `F::operator()` is a non-static member function and
91
+ `decltype(&F::operator())` is either of the form
92
+ `R(G::*)(A...)` cv \\ₒₚₜ ` `noexceptₒₚₜ or of the form
93
+ `R(*)(G, A...) `noexceptₒₚₜ for a type `G`, or
94
+ - `F::operator()` is a static member function and
95
+ `decltype(&F::operator())` is of the form `R(*)(A...) `noexceptₒₚₜ .
96
 
97
  *Remarks:* The deduced type is `function<R(A...)>`.
98
 
99
  [*Example 1*:
100