Skip to content

Commit d5025c3

Browse files
committed
Fix ranges::uninitialized_meow_n algorithms
1 parent 342b431 commit d5025c3

File tree

3 files changed

+62
-26
lines changed
  • stl/inc
  • tests/std/tests
    • P0896R4_ranges_alg_uninitialized_copy_n
    • P0896R4_ranges_alg_uninitialized_move_n

3 files changed

+62
-26
lines changed

stl/inc/memory

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,9 @@ namespace ranges {
149149
auto _OFirst = _Get_unwrapped(_STD move(_First2));
150150
const auto _OLast = _Get_unwrapped(_STD move(_Last2));
151151
if constexpr (_Ptr_copy_cat<_It, _Out>::_Really_trivial) {
152-
return _Copy_memcpy_common(_IFirst, _IFirst + _Count, _OFirst, _OLast);
152+
auto _UResult = _Copy_memcpy_common(_IFirst, _IFirst + _Count, _OFirst, _OLast);
153+
_IFirst = _UResult.in;
154+
_OFirst = _UResult.out;
153155
} else {
154156
_Uninitialized_backout _Backout{_STD move(_OFirst)};
155157

@@ -283,7 +285,9 @@ namespace ranges {
283285
auto _OFirst = _Get_unwrapped(_STD move(_First2));
284286
const auto _OLast = _Get_unwrapped(_STD move(_Last2));
285287
if constexpr (_Ptr_move_cat<_It, _Out>::_Really_trivial) {
286-
return _Copy_memcpy_common(_IFirst, _IFirst + _Count, _OFirst, _OLast);
288+
auto _UResult = _Copy_memcpy_common(_IFirst, _IFirst + _Count, _OFirst, _OLast);
289+
_IFirst = _UResult.in;
290+
_OFirst = _UResult.out;
287291
} else {
288292
_Uninitialized_backout _Backout{_STD move(_OFirst)};
289293

tests/std/tests/P0896R4_ranges_alg_uninitialized_copy_n/test.cpp

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -172,31 +172,47 @@ struct memcopy_test {
172172
static constexpr int expected_input_long[] = {13, 55, 12345, 42};
173173

174174
static void call() {
175+
using ranges::uninitialized_copy_n, ranges::uninitialized_copy_n_result, ranges::equal, ranges::iterator_t;
175176
{ // Validate range overload
176177
int input[] = {13, 55, 12345, 42};
177178
int output[] = {-1, -1, -1, -1};
178-
179-
ranges::uninitialized_copy_n(input, 3, begin(output), end(output));
180-
assert(ranges::equal(input, expected_input));
181-
assert(ranges::equal(output, expected_output));
179+
span<int> wrapped_input{input};
180+
span<int> wrapped_output{output};
181+
182+
const same_as<uninitialized_copy_n_result<iterator_t<span<int>>, iterator_t<span<int>>>> auto result =
183+
uninitialized_copy_n(wrapped_input.begin(), 3, begin(wrapped_output), end(wrapped_output));
184+
assert(next(result.in) == end(wrapped_input));
185+
assert(next(result.out) == end(wrapped_output));
186+
assert(equal(input, expected_input));
187+
assert(equal(output, expected_output));
182188
}
183189

184190
{ // Validate shorter input
185191
int input[] = {13, 55};
186192
int output[] = {-1, -1, -1, -1};
187-
188-
ranges::uninitialized_copy_n(input, 2, begin(output), end(output));
189-
assert(ranges::equal(input, expected_input_short));
190-
assert(ranges::equal(output, expected_output_long));
193+
span<int> wrapped_input{input};
194+
span<int> wrapped_output{output};
195+
196+
const same_as<uninitialized_copy_n_result<iterator_t<span<int>>, iterator_t<span<int>>>> auto result =
197+
uninitialized_copy_n(wrapped_input.begin(), 2, begin(wrapped_output), end(wrapped_output));
198+
assert(result.in == end(wrapped_input));
199+
assert(next(result.out, 2) == end(wrapped_output));
200+
assert(equal(input, expected_input_short));
201+
assert(equal(output, expected_output_long));
191202
}
192203

193204
{ // Validate shorter output
194205
int input[] = {13, 55, 12345, 42};
195206
int output[] = {-1, -1};
196-
197-
ranges::uninitialized_copy_n(input, 3, begin(output), end(output));
198-
assert(ranges::equal(input, expected_input));
199-
assert(ranges::equal(output, expected_input_short));
207+
span<int> wrapped_input{input};
208+
span<int> wrapped_output{output};
209+
210+
const same_as<uninitialized_copy_n_result<iterator_t<span<int>>, iterator_t<span<int>>>> auto result =
211+
uninitialized_copy_n(wrapped_input.begin(), 2, begin(wrapped_output), end(wrapped_output));
212+
assert(next(result.in, 2) == end(wrapped_input));
213+
assert(result.out == end(wrapped_output));
214+
assert(equal(input, expected_input));
215+
assert(equal(output, expected_input_short));
200216
}
201217
}
202218
};

tests/std/tests/P0896R4_ranges_alg_uninitialized_move_n/test.cpp

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -173,31 +173,47 @@ struct memcopy_test {
173173
static constexpr int expected_input_long[] = {13, 55, 12345, 42};
174174

175175
static void call() {
176+
using ranges::uninitialized_move_n, ranges::uninitialized_move_n_result, ranges::equal, ranges::iterator_t;
176177
{ // Validate range overload
177178
int input[] = {13, 55, 12345, 42};
178179
int output[] = {-1, -1, -1, -1};
179-
180-
ranges::uninitialized_move_n(input, 3, begin(output), end(output));
181-
assert(ranges::equal(input, expected_input));
182-
assert(ranges::equal(output, expected_output));
180+
span<int> wrapped_input{input};
181+
span<int> wrapped_output{output};
182+
183+
const same_as<uninitialized_move_n_result<iterator_t<span<int>>, iterator_t<span<int>>>> auto result =
184+
uninitialized_move_n(wrapped_input.begin(), 3, begin(wrapped_output), end(wrapped_output));
185+
assert(next(result.in) == end(wrapped_input));
186+
assert(next(result.out) == end(wrapped_output));
187+
assert(equal(input, expected_input));
188+
assert(equal(output, expected_output));
183189
}
184190

185191
{ // Validate shorter input
186192
int input[] = {13, 55};
187193
int output[] = {-1, -1, -1, -1};
188-
189-
ranges::uninitialized_move_n(input, 2, begin(output), end(output));
190-
assert(ranges::equal(input, expected_input_short));
191-
assert(ranges::equal(output, expected_output_long));
194+
span<int> wrapped_input{input};
195+
span<int> wrapped_output{output};
196+
197+
const same_as<uninitialized_move_n_result<iterator_t<span<int>>, iterator_t<span<int>>>> auto result =
198+
uninitialized_move_n(wrapped_input.begin(), 2, begin(wrapped_output), end(wrapped_output));
199+
assert(result.in == end(wrapped_input));
200+
assert(next(result.out, 2) == end(wrapped_output));
201+
assert(equal(input, expected_input_short));
202+
assert(equal(output, expected_output_long));
192203
}
193204

194205
{ // Validate shorter output
195206
int input[] = {13, 55, 12345, 42};
196207
int output[] = {-1, -1};
197-
198-
ranges::uninitialized_move_n(input, 3, begin(output), end(output));
199-
assert(ranges::equal(input, expected_input));
200-
assert(ranges::equal(output, expected_input_short));
208+
span<int> wrapped_input{input};
209+
span<int> wrapped_output{output};
210+
211+
const same_as<uninitialized_move_n_result<iterator_t<span<int>>, iterator_t<span<int>>>> auto result =
212+
uninitialized_move_n(wrapped_input.begin(), 2, begin(wrapped_output), end(wrapped_output));
213+
assert(next(result.in, 2) == end(wrapped_input));
214+
assert(result.out == end(wrapped_output));
215+
assert(equal(input, expected_input));
216+
assert(equal(output, expected_input_short));
201217
}
202218
}
203219
};

0 commit comments

Comments
 (0)