From Jason Turner

[alg.foreach]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp24mbuocw/{from.md → to.md} +82 -27
tmp/tmp24mbuocw/{from.md → to.md} RENAMED
@@ -1,25 +1,25 @@
1
  ### For each <a id="alg.foreach">[[alg.foreach]]</a>
2
 
3
  ``` cpp
4
  template<class InputIterator, class Function>
5
- Function for_each(InputIterator first, InputIterator last, Function f);
6
  ```
7
 
8
- *Requires:* `Function` shall meet the requirements of
9
- `MoveConstructible` (Table  [[tab:moveconstructible]]).
10
 
11
  [*Note 1*: `Function` need not meet the requirements of
12
- `CopyConstructible` (Table  [[tab:copyconstructible]]). — *end note*]
13
 
14
  *Effects:* Applies `f` to the result of dereferencing every iterator in
15
  the range \[`first`, `last`), starting from `first` and proceeding to
16
  `last - 1`.
17
 
18
- [*Note 2*: If the type of `first` satisfies the requirements of a
19
- mutable iterator, `f` may apply non-constant functions through the
20
- dereferenced iterator. — *end note*]
21
 
22
  *Returns:* `f`.
23
 
24
  *Complexity:* Applies `f` exactly `last - first` times.
25
 
@@ -30,19 +30,19 @@ template<class ExecutionPolicy, class ForwardIterator, class Function>
30
  void for_each(ExecutionPolicy&& exec,
31
  ForwardIterator first, ForwardIterator last,
32
  Function f);
33
  ```
34
 
35
- *Requires:* `Function` shall meet the requirements of
36
- `CopyConstructible`.
37
 
38
  *Effects:* Applies `f` to the result of dereferencing every iterator in
39
  the range \[`first`, `last`).
40
 
41
- [*Note 3*: If the type of `first` satisfies the requirements of a
42
- mutable iterator, `f` may apply non-constant functions through the
43
- dereferenced iterator. — *end note*]
44
 
45
  *Complexity:* Applies `f` exactly `last - first` times.
46
 
47
  *Remarks:* If `f` returns a result, the result is ignored.
48
  Implementations do not have the freedom granted under
@@ -51,29 +51,59 @@ the input sequence.
51
 
52
  [*Note 4*: Does not return a copy of its `Function` parameter, since
53
  parallelization may not permit efficient state
54
  accumulation. — *end note*]
55
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  ``` cpp
57
  template<class InputIterator, class Size, class Function>
58
- InputIterator for_each_n(InputIterator first, Size n, Function f);
59
  ```
60
 
61
- *Requires:* `Function` shall meet the requirements of
62
- `MoveConstructible`
63
 
64
- [*Note 5*: `Function` need not meet the requirements of
65
- `CopyConstructible`. — *end note*]
66
 
67
- *Requires:* `n >= 0`.
 
 
 
68
 
69
  *Effects:* Applies `f` to the result of dereferencing every iterator in
70
  the range \[`first`, `first + n`) in order.
71
 
72
- [*Note 6*: If the type of `first` satisfies the requirements of a
73
- mutable iterator, `f` may apply non-constant functions through the
74
- dereferenced iterator. — *end note*]
75
 
76
  *Returns:* `first + n`.
77
 
78
  *Remarks:* If `f` returns a result, the result is ignored.
79
 
@@ -81,24 +111,49 @@ dereferenced iterator. — *end note*]
81
  template<class ExecutionPolicy, class ForwardIterator, class Size, class Function>
82
  ForwardIterator for_each_n(ExecutionPolicy&& exec, ForwardIterator first, Size n,
83
  Function f);
84
  ```
85
 
86
- *Requires:* `Function` shall meet the requirements of
87
- `CopyConstructible`.
88
 
89
- *Requires:* `n >= 0`.
 
 
 
90
 
91
  *Effects:* Applies `f` to the result of dereferencing every iterator in
92
  the range \[`first`, `first + n`).
93
 
94
- [*Note 7*: If the type of `first` satisfies the requirements of a
95
- mutable iterator, `f` may apply non-constant functions through the
96
- dereferenced iterator. — *end note*]
97
 
98
  *Returns:* `first + n`.
99
 
100
  *Remarks:* If `f` returns a result, the result is ignored.
101
  Implementations do not have the freedom granted under
102
  [[algorithms.parallel.exec]] to make arbitrary copies of elements from
103
  the input sequence.
104
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ### For each <a id="alg.foreach">[[alg.foreach]]</a>
2
 
3
  ``` cpp
4
  template<class InputIterator, class Function>
5
+ constexpr Function for_each(InputIterator first, InputIterator last, Function f);
6
  ```
7
 
8
+ *Preconditions:* `Function` meets the *Cpp17MoveConstructible*
9
+ requirements ([[cpp17.moveconstructible]]).
10
 
11
  [*Note 1*: `Function` need not meet the requirements of
12
+ *Cpp17CopyConstructible* ([[cpp17.copyconstructible]]). — *end note*]
13
 
14
  *Effects:* Applies `f` to the result of dereferencing every iterator in
15
  the range \[`first`, `last`), starting from `first` and proceeding to
16
  `last - 1`.
17
 
18
+ [*Note 2*: If the type of `first` meets the requirements of a mutable
19
+ iterator, `f` may apply non-constant functions through the dereferenced
20
+ iterator. — *end note*]
21
 
22
  *Returns:* `f`.
23
 
24
  *Complexity:* Applies `f` exactly `last - first` times.
25
 
 
30
  void for_each(ExecutionPolicy&& exec,
31
  ForwardIterator first, ForwardIterator last,
32
  Function f);
33
  ```
34
 
35
+ *Preconditions:* `Function` meets the *Cpp17CopyConstructible*
36
+ requirements.
37
 
38
  *Effects:* Applies `f` to the result of dereferencing every iterator in
39
  the range \[`first`, `last`).
40
 
41
+ [*Note 3*: If the type of `first` meets the requirements of a mutable
42
+ iterator, `f` may apply non-constant functions through the dereferenced
43
+ iterator. — *end note*]
44
 
45
  *Complexity:* Applies `f` exactly `last - first` times.
46
 
47
  *Remarks:* If `f` returns a result, the result is ignored.
48
  Implementations do not have the freedom granted under
 
51
 
52
  [*Note 4*: Does not return a copy of its `Function` parameter, since
53
  parallelization may not permit efficient state
54
  accumulation. — *end note*]
55
 
56
+ ``` cpp
57
+ template<input_iterator I, sentinel_for<I> S, class Proj = identity,
58
+ indirectly_unary_invocable<projected<I, Proj>> Fun>
59
+ constexpr ranges::for_each_result<I, Fun>
60
+ ranges::for_each(I first, S last, Fun f, Proj proj = {});
61
+ template<input_range R, class Proj = identity,
62
+ indirectly_unary_invocable<projected<iterator_t<R>, Proj>> Fun>
63
+ constexpr ranges::for_each_result<borrowed_iterator_t<R>, Fun>
64
+ ranges::for_each(R&& r, Fun f, Proj proj = {});
65
+ ```
66
+
67
+ *Effects:* Calls `invoke(f, invoke(proj, *i))` for every iterator `i` in
68
+ the range \[`first`, `last`), starting from `first` and proceeding to
69
+ `last - 1`.
70
+
71
+ [*Note 5*: If the result of `invoke(proj, *i)` is a mutable reference,
72
+ `f` may apply non-constant functions. — *end note*]
73
+
74
+ *Returns:* `{last, std::move(f)}`.
75
+
76
+ *Complexity:* Applies `f` and `proj` exactly `last - first` times.
77
+
78
+ *Remarks:* If `f` returns a result, the result is ignored.
79
+
80
+ [*Note 6*: The overloads in namespace `ranges` require `Fun` to model
81
+ `copy_constructible`. — *end note*]
82
+
83
  ``` cpp
84
  template<class InputIterator, class Size, class Function>
85
+ constexpr InputIterator for_each_n(InputIterator first, Size n, Function f);
86
  ```
87
 
88
+ *Mandates:* The type `Size` is convertible to an integral
89
+ type ([[conv.integral]], [[class.conv]]).
90
 
91
+ *Preconditions:* `Function` meets the *Cpp17MoveConstructible*
92
+ requirements.
93
 
94
+ [*Note 7*: `Function` need not meet the requirements of
95
+ *Cpp17CopyConstructible*. — *end note*]
96
+
97
+ *Preconditions:* `n >= 0` is `true`.
98
 
99
  *Effects:* Applies `f` to the result of dereferencing every iterator in
100
  the range \[`first`, `first + n`) in order.
101
 
102
+ [*Note 8*: If the type of `first` meets the requirements of a mutable
103
+ iterator, `f` may apply non-constant functions through the dereferenced
104
+ iterator. — *end note*]
105
 
106
  *Returns:* `first + n`.
107
 
108
  *Remarks:* If `f` returns a result, the result is ignored.
109
 
 
111
  template<class ExecutionPolicy, class ForwardIterator, class Size, class Function>
112
  ForwardIterator for_each_n(ExecutionPolicy&& exec, ForwardIterator first, Size n,
113
  Function f);
114
  ```
115
 
116
+ *Mandates:* The type `Size` is convertible to an integral
117
+ type ([[conv.integral]], [[class.conv]]).
118
 
119
+ *Preconditions:* `Function` meets the *Cpp17CopyConstructible*
120
+ requirements.
121
+
122
+ *Preconditions:* `n >= 0` is `true`.
123
 
124
  *Effects:* Applies `f` to the result of dereferencing every iterator in
125
  the range \[`first`, `first + n`).
126
 
127
+ [*Note 9*: If the type of `first` meets the requirements of a mutable
128
+ iterator, `f` may apply non-constant functions through the dereferenced
129
+ iterator. — *end note*]
130
 
131
  *Returns:* `first + n`.
132
 
133
  *Remarks:* If `f` returns a result, the result is ignored.
134
  Implementations do not have the freedom granted under
135
  [[algorithms.parallel.exec]] to make arbitrary copies of elements from
136
  the input sequence.
137
 
138
+ ``` cpp
139
+ template<input_iterator I, class Proj = identity,
140
+ indirectly_unary_invocable<projected<I, Proj>> Fun>
141
+ constexpr ranges::for_each_n_result<I, Fun>
142
+ ranges::for_each_n(I first, iter_difference_t<I> n, Fun f, Proj proj = {});
143
+ ```
144
+
145
+ *Preconditions:* `n >= 0` is `true`.
146
+
147
+ *Effects:* Calls `invoke(f, invoke(proj, *i))` for every iterator `i` in
148
+ the range \[`first`, `first + n`) in order.
149
+
150
+ [*Note 10*: If the result of `invoke(proj, *i)` is a mutable reference,
151
+ `f` may apply non-constant functions. — *end note*]
152
+
153
+ *Returns:* `{first + n, std::move(f)}`.
154
+
155
+ *Remarks:* If `f` returns a result, the result is ignored.
156
+
157
+ [*Note 11*: The overload in namespace `ranges` requires `Fun` to model
158
+ `copy_constructible`. — *end note*]
159
+