From cceff617612c65257696a829f7fa7a0aa0895627 Mon Sep 17 00:00:00 2001 From: Michael Schellenberger Costa Date: Mon, 28 Dec 2020 21:06:23 +0100 Subject: [PATCH 1/5] Fix uninitialized_meow memcopy optimization --- stl/inc/memory | 2 +- stl/inc/xmemory | 2 +- .../test.cpp | 16 ++++++++++++++++ .../test.cpp | 16 ++++++++++++++++ .../test.cpp | 16 ++++++++++++++++ .../test.cpp | 16 ++++++++++++++++ 6 files changed, 66 insertions(+), 2 deletions(-) diff --git a/stl/inc/memory b/stl/inc/memory index 279effbcc6b..1b574ddfa98 100644 --- a/stl/inc/memory +++ b/stl/inc/memory @@ -79,7 +79,7 @@ namespace ranges { _STL_INTERNAL_STATIC_ASSERT(constructible_from, iter_reference_t<_It>>); if constexpr (is_same_v<_Se, _It> && _Ptr_copy_cat<_It, _Out>::_Really_trivial) { - return _Copy_memcpy_common(_IFirst, _ILast, _OFirst, _OLast); + return {_ILast, _Copy_memcpy_common(_IFirst, _ILast, _OFirst, _OLast)}; } else { _Uninitialized_backout _Backout{_STD move(_OFirst)}; diff --git a/stl/inc/xmemory b/stl/inc/xmemory index 9550df6676a..714a70fb1d4 100644 --- a/stl/inc/xmemory +++ b/stl/inc/xmemory @@ -1564,7 +1564,7 @@ namespace ranges { _It _IFirst, const _Se _ILast, _Out _OFirst, const _OSe _OLast) { // clang-format on if constexpr (is_same_v<_Se, _It> && _Ptr_move_cat<_It, _Out>::_Really_trivial) { - return _Copy_memcpy_common(_IFirst, _ILast, _OFirst, _OLast); + return {_ILast, _Copy_memcpy_common(_IFirst, _ILast, _OFirst, _OLast)}; } else { _Uninitialized_backout _Backout{_STD move(_OFirst)}; diff --git a/tests/std/tests/P0896R4_ranges_alg_uninitialized_copy/test.cpp b/tests/std/tests/P0896R4_ranges_alg_uninitialized_copy/test.cpp index f2c607162fe..6972248a9cd 100644 --- a/tests/std/tests/P0896R4_ranges_alg_uninitialized_copy/test.cpp +++ b/tests/std/tests/P0896R4_ranges_alg_uninitialized_copy/test.cpp @@ -160,6 +160,21 @@ struct throwing_test { } }; +struct memcopy_test { + static constexpr int expected_output[] = {13, 55, 12345}; + static constexpr int expected_input[] = {13, 55, 12345}; + + static void call() { + // Validate only range overload (one is plenty since they both use the same backend) + int input[] = {13, 55, 12345}; + int output[] = {-1, -1, -1}; + + ranges::uninitialized_copy(input, output); + assert(ranges::equal(input, expected_input)); + assert(ranges::equal(output, expected_output)); + } +}; + template using test_input = test::range; @@ -174,4 +189,5 @@ int main() { instantiator::call, test_output>(); throwing_test::call, test_output>(); throwing_test::call, test_output>(); + memcopy_test::call(); } diff --git a/tests/std/tests/P0896R4_ranges_alg_uninitialized_copy_n/test.cpp b/tests/std/tests/P0896R4_ranges_alg_uninitialized_copy_n/test.cpp index 9e86c952d8d..b5f2073a47c 100644 --- a/tests/std/tests/P0896R4_ranges_alg_uninitialized_copy_n/test.cpp +++ b/tests/std/tests/P0896R4_ranges_alg_uninitialized_copy_n/test.cpp @@ -126,6 +126,21 @@ struct throwing_test { } }; +struct memcopy_test { + static constexpr int expected_output[] = {13, 55, 12345, -1}; + static constexpr int expected_input[] = {13, 55, 12345, 42}; + + static void call() { + // Validate only range overload (one is plenty since they both use the same backend) + int input[] = {13, 55, 12345, 42}; + int output[] = {-1, -1, -1, -1}; + + ranges::uninitialized_copy_n(input, 3, output, output + 4); + assert(ranges::equal(input, expected_input)); + assert(ranges::equal(output, expected_output)); + } +}; + template using test_input = test::range; @@ -140,4 +155,5 @@ int main() { instantiator::call, test_output>(); throwing_test::call, test_output>(); throwing_test::call, test_output>(); + memcopy_test::call(); } diff --git a/tests/std/tests/P0896R4_ranges_alg_uninitialized_move/test.cpp b/tests/std/tests/P0896R4_ranges_alg_uninitialized_move/test.cpp index 8be0b1e8de3..9d2961db58a 100644 --- a/tests/std/tests/P0896R4_ranges_alg_uninitialized_move/test.cpp +++ b/tests/std/tests/P0896R4_ranges_alg_uninitialized_move/test.cpp @@ -154,6 +154,21 @@ struct throwing_test { } }; +struct memcopy_test { + static constexpr int expected_output[] = {13, 55, 12345}; + static constexpr int expected_input[] = {13, 55, 12345}; + + static void call() { + // Validate only range overload (one is plenty since they both use the same backend) + int input[] = {13, 55, 12345}; + int output[] = {-1, -1, -1}; + + ranges::uninitialized_move(input, output); + assert(ranges::equal(input, expected_input)); + assert(ranges::equal(output, expected_output)); + } +}; + template using test_input = test::range; @@ -168,4 +183,5 @@ int main() { instantiator::call, test_output>(); throwing_test::call, test_output>(); throwing_test::call, test_output>(); + memcopy_test::call(); } diff --git a/tests/std/tests/P0896R4_ranges_alg_uninitialized_move_n/test.cpp b/tests/std/tests/P0896R4_ranges_alg_uninitialized_move_n/test.cpp index eef82b952c4..9836847c0a6 100644 --- a/tests/std/tests/P0896R4_ranges_alg_uninitialized_move_n/test.cpp +++ b/tests/std/tests/P0896R4_ranges_alg_uninitialized_move_n/test.cpp @@ -128,6 +128,21 @@ struct throwing_test { } }; +struct memcopy_test { + static constexpr int expected_output[] = {13, 55, 12345, -1}; + static constexpr int expected_input[] = {13, 55, 12345, 42}; + + static void call() { + // Validate only range overload (one is plenty since they both use the same backend) + int input[] = {13, 55, 12345, 42}; + int output[] = {-1, -1, -1, -1}; + + ranges::uninitialized_move_n(input, 3, output, output + 4); + assert(ranges::equal(input, expected_input)); + assert(ranges::equal(output, expected_output)); + } +}; + template using test_input = test::range; @@ -142,4 +157,5 @@ int main() { instantiator::call, test_output>(); throwing_test::call, test_output>(); throwing_test::call, test_output>(); + memcopy_test::call(); } From 342b4317c3fc70c62c5f4eba67c22a4859fdd41e Mon Sep 17 00:00:00 2001 From: Michael Schellenberger Costa Date: Fri, 8 Jan 2021 14:07:39 +0100 Subject: [PATCH 2/5] Improve _Copy_memcpy_common return type --- stl/inc/memory | 6 +- stl/inc/xmemory | 14 +- stl/inc/xutility | 11 -- .../test.cpp | 105 +++++++++++--- .../test.cpp | 130 +++++++++++++----- .../test.cpp | 92 +++++++++++-- .../test.cpp | 129 ++++++++++++----- 7 files changed, 369 insertions(+), 118 deletions(-) diff --git a/stl/inc/memory b/stl/inc/memory index 1b574ddfa98..8364561c27a 100644 --- a/stl/inc/memory +++ b/stl/inc/memory @@ -79,7 +79,7 @@ namespace ranges { _STL_INTERNAL_STATIC_ASSERT(constructible_from, iter_reference_t<_It>>); if constexpr (is_same_v<_Se, _It> && _Ptr_copy_cat<_It, _Out>::_Really_trivial) { - return {_ILast, _Copy_memcpy_common(_IFirst, _ILast, _OFirst, _OLast)}; + return _Copy_memcpy_common(_IFirst, _ILast, _OFirst, _OLast); } else { _Uninitialized_backout _Backout{_STD move(_OFirst)}; @@ -149,7 +149,7 @@ namespace ranges { auto _OFirst = _Get_unwrapped(_STD move(_First2)); const auto _OLast = _Get_unwrapped(_STD move(_Last2)); if constexpr (_Ptr_copy_cat<_It, _Out>::_Really_trivial) { - _OFirst = _Copy_memcpy_common(_IFirst, _IFirst + _Count, _OFirst, _OLast); + return _Copy_memcpy_common(_IFirst, _IFirst + _Count, _OFirst, _OLast); } else { _Uninitialized_backout _Backout{_STD move(_OFirst)}; @@ -283,7 +283,7 @@ namespace ranges { auto _OFirst = _Get_unwrapped(_STD move(_First2)); const auto _OLast = _Get_unwrapped(_STD move(_Last2)); if constexpr (_Ptr_move_cat<_It, _Out>::_Really_trivial) { - _OFirst = _Copy_memcpy_common(_IFirst, _IFirst + _Count, _OFirst, _OLast); + return _Copy_memcpy_common(_IFirst, _IFirst + _Count, _OFirst, _OLast); } else { _Uninitialized_backout _Backout{_STD move(_OFirst)}; diff --git a/stl/inc/xmemory b/stl/inc/xmemory index 714a70fb1d4..a222c7e55c3 100644 --- a/stl/inc/xmemory +++ b/stl/inc/xmemory @@ -1551,6 +1551,18 @@ namespace ranges { && _No_throw_forward_iterator>; // clang-format on + template + in_out_result<_InIt, _OutIt> _Copy_memcpy_common( + _InIt _IFirst, _InIt _ILast, _OutIt _OFirst, _OutIt _OLast) noexcept { + const auto _IFirst_ch = const_cast(reinterpret_cast(_IFirst)); + const auto _ILast_ch = const_cast(reinterpret_cast(_ILast)); + const auto _OFirst_ch = const_cast(reinterpret_cast(_OFirst)); + const auto _OLast_ch = const_cast(reinterpret_cast(_OLast)); + const auto _Count = static_cast((_STD min)(_ILast_ch - _IFirst_ch, _OLast_ch - _OFirst_ch)); + _CSTD memcpy(_OFirst_ch, _IFirst_ch, _Count); + return {reinterpret_cast<_InIt>(_IFirst_ch + _Count), reinterpret_cast<_OutIt>(_OFirst_ch + _Count)}; + } + // ALIAS TEMPLATE uninitialized_move_result template using uninitialized_move_result = in_out_result<_In, _Out>; @@ -1564,7 +1576,7 @@ namespace ranges { _It _IFirst, const _Se _ILast, _Out _OFirst, const _OSe _OLast) { // clang-format on if constexpr (is_same_v<_Se, _It> && _Ptr_move_cat<_It, _Out>::_Really_trivial) { - return {_ILast, _Copy_memcpy_common(_IFirst, _ILast, _OFirst, _OLast)}; + return _Copy_memcpy_common(_IFirst, _ILast, _OFirst, _OLast); } else { _Uninitialized_backout _Backout{_STD move(_OFirst)}; diff --git a/stl/inc/xutility b/stl/inc/xutility index eb2a04cadf3..66e6cbd227b 100644 --- a/stl/inc/xutility +++ b/stl/inc/xutility @@ -4102,17 +4102,6 @@ _OutIt _Copy_memmove(move_iterator<_InIt> _First, move_iterator<_InIt> _Last, _O return _Copy_memmove(_First.base(), _Last.base(), _Dest); } -template -_OutIt _Copy_memcpy_common(_InIt _IFirst, _InIt _ILast, _OutIt _OFirst, _OutIt _OLast) noexcept { - const auto _IFirst_ch = const_cast(reinterpret_cast(_IFirst)); - const auto _ILast_ch = const_cast(reinterpret_cast(_ILast)); - const auto _OFirst_ch = const_cast(reinterpret_cast(_OFirst)); - const auto _OLast_ch = const_cast(reinterpret_cast(_OLast)); - const auto _Count = static_cast((_STD min)(_ILast_ch - _IFirst_ch, _OLast_ch - _OFirst_ch)); - _CSTD memcpy(_OFirst_ch, _IFirst_ch, _Count); - return reinterpret_cast<_OutIt>(_OFirst_ch + _Count); -} - // VARIABLE TEMPLATE _Is_vb_iterator template _INLINE_VAR constexpr bool _Is_vb_iterator = false; diff --git a/tests/std/tests/P0896R4_ranges_alg_uninitialized_copy/test.cpp b/tests/std/tests/P0896R4_ranges_alg_uninitialized_copy/test.cpp index 6972248a9cd..6b5f9c064c2 100644 --- a/tests/std/tests/P0896R4_ranges_alg_uninitialized_copy/test.cpp +++ b/tests/std/tests/P0896R4_ranges_alg_uninitialized_copy/test.cpp @@ -76,21 +76,16 @@ struct holder { } }; -template -void not_ranges_destroy(R&& r) { // TRANSITION, ranges::destroy - for (auto& e : r) { - destroy_at(&e); - } -} - struct instantiator { - static constexpr int expected_output[] = {13, 55, 12345}; - static constexpr int expected_input[] = {13, 55, 12345}; + static constexpr int expected_output[] = {13, 55, 12345}; + static constexpr int expected_output_long[] = {13, 55, 12345, -1}; + static constexpr int expected_input[] = {13, 55, 12345}; + static constexpr int expected_input_long[] = {13, 55, 12345, 42}; template static void call() { - using ranges::uninitialized_copy, ranges::uninitialized_copy_result, ranges::equal, ranges::equal_to, - ranges::iterator_t; + using ranges::destroy, ranges::uninitialized_copy, ranges::uninitialized_copy_result, ranges::equal, + ranges::equal_to, ranges::iterator_t; { // Validate range overload int_wrapper input[3] = {13, 55, 12345}; @@ -107,7 +102,7 @@ struct instantiator { assert(result.out == wrapped_output.end()); assert(equal(wrapped_output, expected_output, equal_to{}, &int_wrapper::val)); assert(equal(input, expected_input, equal_to{}, &int_wrapper::val)); - not_ranges_destroy(wrapped_output); + destroy(wrapped_output); assert(int_wrapper::constructions == 3); assert(int_wrapper::destructions == 3); } @@ -127,10 +122,51 @@ struct instantiator { assert(result.out == wrapped_output.end()); assert(equal(wrapped_output, expected_output, equal_to{}, &int_wrapper::val)); assert(equal(input, expected_input, equal_to{}, &int_wrapper::val)); - not_ranges_destroy(wrapped_output); + destroy(wrapped_output); + assert(int_wrapper::constructions == 3); + assert(int_wrapper::destructions == 3); + } + + { // Validate range overload shorter output + int_wrapper input[4] = {13, 55, 12345, 42}; + R wrapped_input{input}; + holder mem; + W wrapped_output{mem.as_span()}; + + int_wrapper::clear_counts(); + same_as, iterator_t>> auto result = + uninitialized_copy(wrapped_input, wrapped_output); + assert(int_wrapper::constructions == 3); + assert(int_wrapper::destructions == 0); + assert(++result.in == wrapped_input.end()); + assert(result.out == wrapped_output.end()); + assert(equal(wrapped_output, expected_output, equal_to{}, &int_wrapper::val)); + assert(equal(input, expected_input_long, equal_to{}, &int_wrapper::val)); + destroy(wrapped_output); assert(int_wrapper::constructions == 3); assert(int_wrapper::destructions == 3); } + + { // Validate range overload shorter input + int_wrapper input[3] = {13, 55, 12345}; + R wrapped_input{input}; + holder mem; + W wrapped_output{mem.as_span()}; + + int_wrapper::clear_counts(); + same_as, iterator_t>> auto result = + uninitialized_copy(wrapped_input, wrapped_output); + assert(int_wrapper::constructions == 3); + assert(int_wrapper::destructions == 0); + assert(result.in == wrapped_input.end()); + construct_at(addressof(*result.out), -1); // Need to construct non written element for comparison + assert(++result.out == wrapped_output.end()); + assert(equal(wrapped_output, expected_output_long, equal_to{}, &int_wrapper::val)); + assert(equal(input, expected_input, equal_to{}, &int_wrapper::val)); + destroy(wrapped_output); + assert(int_wrapper::constructions == 4); + assert(int_wrapper::destructions == 4); + } } }; @@ -161,17 +197,44 @@ struct throwing_test { }; struct memcopy_test { - static constexpr int expected_output[] = {13, 55, 12345}; - static constexpr int expected_input[] = {13, 55, 12345}; + static constexpr int expected_output[] = {13, 55, 12345}; + static constexpr int expected_output_long[] = {13, 55, 12345, -1}; + static constexpr int expected_input[] = {13, 55, 12345}; + static constexpr int expected_input_long[] = {13, 55, 12345, 42}; static void call() { - // Validate only range overload (one is plenty since they both use the same backend) - int input[] = {13, 55, 12345}; - int output[] = {-1, -1, -1}; + { // Validate only range overload + int input[] = {13, 55, 12345}; + int output[] = {-1, -1, -1}; + + const auto result = ranges::uninitialized_copy(input, output); + assert(result.in == end(input)); + assert(result.out == end(output)); + assert(ranges::equal(input, expected_input)); + assert(ranges::equal(output, expected_output)); + } + + { // Validate input shorter + int input[] = {13, 55, 12345}; + int output[] = {-1, -1, -1, -1}; - ranges::uninitialized_copy(input, output); - assert(ranges::equal(input, expected_input)); - assert(ranges::equal(output, expected_output)); + auto result = ranges::uninitialized_copy(input, output); + assert(result.in == end(input)); + assert(++result.out == end(output)); + assert(ranges::equal(input, expected_input)); + assert(ranges::equal(output, expected_output_long)); + } + + { // Validate output shorter + int input[] = {13, 55, 12345, 42}; + int output[] = {-1, -1, -1}; + + auto result = ranges::uninitialized_copy(input, output); + assert(++result.in == end(input)); + assert(result.out == end(output)); + assert(ranges::equal(input, expected_input_long)); + assert(ranges::equal(output, expected_output)); + } } }; diff --git a/tests/std/tests/P0896R4_ranges_alg_uninitialized_copy_n/test.cpp b/tests/std/tests/P0896R4_ranges_alg_uninitialized_copy_n/test.cpp index b5f2073a47c..e48f1383271 100644 --- a/tests/std/tests/P0896R4_ranges_alg_uninitialized_copy_n/test.cpp +++ b/tests/std/tests/P0896R4_ranges_alg_uninitialized_copy_n/test.cpp @@ -66,39 +66,77 @@ struct holder { } }; -template -void not_ranges_destroy(R&& r) { // TRANSITION, ranges::destroy - for (auto& e : r) { - destroy_at(&e); - } -} - struct instantiator { - static constexpr int expected_output[] = {13, 55, 12345}; - static constexpr int expected_input[] = {13, 55, 12345}; + static constexpr int expected_output[] = {13, 55, 12345}; + static constexpr int expected_output_long[] = {13, 55, 12345, -1}; + static constexpr int expected_input[] = {13, 55, 12345}; + static constexpr int expected_input_long[] = {13, 55, 12345, 42}; template static void call() { - using ranges::uninitialized_copy_n, ranges::uninitialized_copy_n_result, ranges::equal, ranges::equal_to, - ranges::iterator_t; + using ranges::destroy, ranges::uninitialized_copy_n, ranges::uninitialized_copy_n_result, ranges::equal, + ranges::equal_to, ranges::iterator_t; + + { // Validate equal ranges + int_wrapper input[3] = {13, 55, 12345}; + Read wrapped_input{input}; + holder mem; + Write wrapped_output{mem.as_span()}; + + int_wrapper::clear_counts(); + const same_as, iterator_t>> auto result = + uninitialized_copy_n(wrapped_input.begin(), 3, wrapped_output.begin(), wrapped_output.end()); + assert(int_wrapper::constructions == 3); + assert(int_wrapper::destructions == 0); + assert(result.in == wrapped_input.end()); + assert(result.out == wrapped_output.end()); + assert(equal(wrapped_output, expected_output, equal_to{}, &int_wrapper::val)); + assert(equal(input, expected_input, equal_to{}, &int_wrapper::val)); + destroy(wrapped_output); + assert(int_wrapper::constructions == 3); + assert(int_wrapper::destructions == 3); + } - int_wrapper input[3] = {13, 55, 12345}; - Read wrapped_input{input}; - holder mem; - Write wrapped_output{mem.as_span()}; + { // Validate shorter output + int_wrapper input[4] = {13, 55, 12345, 42}; + Read wrapped_input{input}; + holder mem; + Write wrapped_output{mem.as_span()}; + + int_wrapper::clear_counts(); + same_as, iterator_t>> auto result = + uninitialized_copy_n(wrapped_input.begin(), 3, wrapped_output.begin(), wrapped_output.end()); + assert(int_wrapper::constructions == 3); + assert(int_wrapper::destructions == 0); + assert(++result.in == wrapped_input.end()); + assert(result.out == wrapped_output.end()); + assert(equal(wrapped_output, expected_output, equal_to{}, &int_wrapper::val)); + assert(equal(input, expected_input_long, equal_to{}, &int_wrapper::val)); + destroy(wrapped_output); + assert(int_wrapper::constructions == 3); + assert(int_wrapper::destructions == 3); + } - int_wrapper::clear_counts(); - const same_as, iterator_t>> auto result = - uninitialized_copy_n(wrapped_input.begin(), 3, wrapped_output.begin(), wrapped_output.end()); - assert(int_wrapper::constructions == 3); - assert(int_wrapper::destructions == 0); - assert(result.in == wrapped_input.end()); - assert(result.out == wrapped_output.end()); - assert(equal(wrapped_output, expected_output, equal_to{}, &int_wrapper::val)); - assert(equal(input, expected_input, equal_to{}, &int_wrapper::val)); - not_ranges_destroy(wrapped_output); - assert(int_wrapper::constructions == 3); - assert(int_wrapper::destructions == 3); + { // Validate shorter input + int_wrapper input[3] = {13, 55, 12345}; + Read wrapped_input{input}; + holder mem; + Write wrapped_output{mem.as_span()}; + + int_wrapper::clear_counts(); + same_as, iterator_t>> auto result = + uninitialized_copy_n(wrapped_input.begin(), 3, wrapped_output.begin(), wrapped_output.end()); + assert(int_wrapper::constructions == 3); + assert(int_wrapper::destructions == 0); + assert(result.in == wrapped_input.end()); + construct_at(addressof(*result.out), -1); // Need to construct non written element for comparison + assert(++result.out == wrapped_output.end()); + assert(equal(wrapped_output, expected_output_long, equal_to{}, &int_wrapper::val)); + assert(equal(input, expected_input, equal_to{}, &int_wrapper::val)); + destroy(wrapped_output); + assert(int_wrapper::constructions == 4); + assert(int_wrapper::destructions == 4); + } } }; @@ -127,17 +165,39 @@ struct throwing_test { }; struct memcopy_test { - static constexpr int expected_output[] = {13, 55, 12345, -1}; - static constexpr int expected_input[] = {13, 55, 12345, 42}; + static constexpr int expected_output[] = {13, 55, 12345, -1}; + static constexpr int expected_output_long[] = {13, 55, -1, -1}; + static constexpr int expected_input[] = {13, 55, 12345, 42}; + static constexpr int expected_input_short[] = {13, 55}; + static constexpr int expected_input_long[] = {13, 55, 12345, 42}; static void call() { - // Validate only range overload (one is plenty since they both use the same backend) - int input[] = {13, 55, 12345, 42}; - int output[] = {-1, -1, -1, -1}; + { // Validate range overload + int input[] = {13, 55, 12345, 42}; + int output[] = {-1, -1, -1, -1}; + + ranges::uninitialized_copy_n(input, 3, begin(output), end(output)); + assert(ranges::equal(input, expected_input)); + assert(ranges::equal(output, expected_output)); + } + + { // Validate shorter input + int input[] = {13, 55}; + int output[] = {-1, -1, -1, -1}; - ranges::uninitialized_copy_n(input, 3, output, output + 4); - assert(ranges::equal(input, expected_input)); - assert(ranges::equal(output, expected_output)); + ranges::uninitialized_copy_n(input, 2, begin(output), end(output)); + assert(ranges::equal(input, expected_input_short)); + assert(ranges::equal(output, expected_output_long)); + } + + { // Validate shorter output + int input[] = {13, 55, 12345, 42}; + int output[] = {-1, -1}; + + ranges::uninitialized_copy_n(input, 3, begin(output), end(output)); + assert(ranges::equal(input, expected_input)); + assert(ranges::equal(output, expected_input_short)); + } } }; diff --git a/tests/std/tests/P0896R4_ranges_alg_uninitialized_move/test.cpp b/tests/std/tests/P0896R4_ranges_alg_uninitialized_move/test.cpp index 9d2961db58a..faab56bb711 100644 --- a/tests/std/tests/P0896R4_ranges_alg_uninitialized_move/test.cpp +++ b/tests/std/tests/P0896R4_ranges_alg_uninitialized_move/test.cpp @@ -78,13 +78,15 @@ struct holder { }; struct instantiator { - static constexpr int expected_output[] = {13, 55, 12345}; - static constexpr int expected_input[] = {-1, -1, -1}; + static constexpr int expected_output[] = {13, 55, 12345}; + static constexpr int expected_output_long[] = {13, 55, 12345, -1}; + static constexpr int expected_input[] = {-1, -1, -1}; + static constexpr int expected_input_long[] = {-1, -1, -1, 42}; template static void call() { - using ranges::uninitialized_move, ranges::uninitialized_move_result, ranges::destroy, ranges::equal, - ranges::equal_to, ranges::iterator_t; + using ranges::destroy, ranges::uninitialized_move, ranges::uninitialized_move_result, ranges::destroy, + ranges::equal, ranges::equal_to, ranges::iterator_t; { // Validate range overload int_wrapper input[3] = {13, 55, 12345}; @@ -125,6 +127,47 @@ struct instantiator { assert(int_wrapper::constructions == 3); assert(int_wrapper::destructions == 3); } + + { // Validate range overload shorter output + int_wrapper input[4] = {13, 55, 12345, 42}; + R wrapped_input{input}; + holder mem; + W wrapped_output{mem.as_span()}; + + int_wrapper::clear_counts(); + same_as, iterator_t>> auto result = + uninitialized_move(wrapped_input, wrapped_output); + assert(int_wrapper::constructions == 3); + assert(int_wrapper::destructions == 0); + assert(++result.in == wrapped_input.end()); + assert(result.out == wrapped_output.end()); + assert(equal(wrapped_output, expected_output, equal_to{}, &int_wrapper::val)); + assert(equal(input, expected_input_long, equal_to{}, &int_wrapper::val)); + destroy(wrapped_output); + assert(int_wrapper::constructions == 3); + assert(int_wrapper::destructions == 3); + } + + { // Validate range overload shorter input + int_wrapper input[3] = {13, 55, 12345}; + R wrapped_input{input}; + holder mem; + W wrapped_output{mem.as_span()}; + + int_wrapper::clear_counts(); + same_as, iterator_t>> auto result = + uninitialized_move(wrapped_input, wrapped_output); + assert(int_wrapper::constructions == 3); + assert(int_wrapper::destructions == 0); + assert(result.in == wrapped_input.end()); + construct_at(addressof(*result.out), -1); // Need to construct non written element for comparison + assert(++result.out == wrapped_output.end()); + assert(equal(wrapped_output, expected_output_long, equal_to{}, &int_wrapper::val)); + assert(equal(input, expected_input, equal_to{}, &int_wrapper::val)); + destroy(wrapped_output); + assert(int_wrapper::constructions == 4); + assert(int_wrapper::destructions == 4); + } } }; @@ -155,17 +198,42 @@ struct throwing_test { }; struct memcopy_test { - static constexpr int expected_output[] = {13, 55, 12345}; - static constexpr int expected_input[] = {13, 55, 12345}; + static constexpr int expected_output[] = {13, 55, 12345}; + static constexpr int expected_output_long[] = {13, 55, 12345, -1}; + static constexpr int expected_input[] = {13, 55, 12345}; + static constexpr int expected_input_long[] = {13, 55, 12345, 42}; static void call() { - // Validate only range overload (one is plenty since they both use the same backend) - int input[] = {13, 55, 12345}; - int output[] = {-1, -1, -1}; + { // Validate range + int input[] = {13, 55, 12345}; + int output[] = {-1, -1, -1}; + + ranges::uninitialized_move(input, output); + assert(ranges::equal(input, expected_input)); + assert(ranges::equal(output, expected_output)); + } + + { // Validate input shorter + int input[] = {13, 55, 12345}; + int output[] = {-1, -1, -1, -1}; - ranges::uninitialized_move(input, output); - assert(ranges::equal(input, expected_input)); - assert(ranges::equal(output, expected_output)); + auto result = ranges::uninitialized_move(input, output); + assert(result.in == end(input)); + assert(++result.out == end(output)); + assert(ranges::equal(input, expected_input)); + assert(ranges::equal(output, expected_output_long)); + } + + { // Validate output shorter + int input[] = {13, 55, 12345, 42}; + int output[] = {-1, -1, -1}; + + auto result = ranges::uninitialized_move(input, output); + assert(++result.in == end(input)); + assert(result.out == end(output)); + assert(ranges::equal(input, expected_input_long)); + assert(ranges::equal(output, expected_output)); + } } }; diff --git a/tests/std/tests/P0896R4_ranges_alg_uninitialized_move_n/test.cpp b/tests/std/tests/P0896R4_ranges_alg_uninitialized_move_n/test.cpp index 9836847c0a6..498ed9dcf90 100644 --- a/tests/std/tests/P0896R4_ranges_alg_uninitialized_move_n/test.cpp +++ b/tests/std/tests/P0896R4_ranges_alg_uninitialized_move_n/test.cpp @@ -67,39 +67,76 @@ struct holder { } }; -template -void not_ranges_destroy(R&& r) { // TRANSITION, ranges::destroy - for (auto& e : r) { - destroy_at(&e); - } -} - struct instantiator { - static constexpr int expected_output[] = {13, 55, 12345}; - static constexpr int expected_input[] = {-1, -1, -1}; + static constexpr int expected_output[] = {13, 55, 12345}; + static constexpr int expected_output_long[] = {13, 55, 12345, -1}; + static constexpr int expected_input[] = {-1, -1, -1}; + static constexpr int expected_input_long[] = {-1, -1, -1, 42}; template static void call() { - using ranges::uninitialized_move_n, ranges::uninitialized_move_n_result, ranges::equal, ranges::equal_to, - ranges::iterator_t; + using ranges::destroy, ranges::uninitialized_move_n, ranges::uninitialized_move_n_result, ranges::equal, + ranges::equal_to, ranges::iterator_t; + { // Validate matching ranges + int_wrapper input[3] = {13, 55, 12345}; + Read wrapped_input{input}; + holder mem; + Write wrapped_output{mem.as_span()}; + + int_wrapper::clear_counts(); + const same_as, iterator_t>> auto result = + uninitialized_move_n(wrapped_input.begin(), 3, wrapped_output.begin(), wrapped_output.end()); + assert(int_wrapper::constructions == 3); + assert(int_wrapper::destructions == 0); + assert(result.in == wrapped_input.end()); + assert(result.out == wrapped_output.end()); + assert(equal(wrapped_output, expected_output, equal_to{}, &int_wrapper::val)); + assert(equal(input, expected_input, equal_to{}, &int_wrapper::val)); + destroy(wrapped_output); + assert(int_wrapper::constructions == 3); + assert(int_wrapper::destructions == 3); + } - int_wrapper input[3] = {13, 55, 12345}; - Read wrapped_input{input}; - holder mem; - Write wrapped_output{mem.as_span()}; + { // Validate shorter output + int_wrapper input[4] = {13, 55, 12345, 42}; + Read wrapped_input{input}; + holder mem; + Write wrapped_output{mem.as_span()}; + + int_wrapper::clear_counts(); + same_as, iterator_t>> auto result = + uninitialized_move_n(wrapped_input.begin(), 3, wrapped_output.begin(), wrapped_output.end()); + assert(int_wrapper::constructions == 3); + assert(int_wrapper::destructions == 0); + assert(++result.in == wrapped_input.end()); + assert(result.out == wrapped_output.end()); + assert(equal(wrapped_output, expected_output, equal_to{}, &int_wrapper::val)); + assert(equal(input, expected_input_long, equal_to{}, &int_wrapper::val)); + destroy(wrapped_output); + assert(int_wrapper::constructions == 3); + assert(int_wrapper::destructions == 3); + } - int_wrapper::clear_counts(); - const same_as, iterator_t>> auto result = - uninitialized_move_n(wrapped_input.begin(), 3, wrapped_output.begin(), wrapped_output.end()); - assert(int_wrapper::constructions == 3); - assert(int_wrapper::destructions == 0); - assert(result.in == wrapped_input.end()); - assert(result.out == wrapped_output.end()); - assert(equal(wrapped_output, expected_output, equal_to{}, &int_wrapper::val)); - assert(equal(input, expected_input, equal_to{}, &int_wrapper::val)); - not_ranges_destroy(wrapped_output); - assert(int_wrapper::constructions == 3); - assert(int_wrapper::destructions == 3); + { // Validate shorter input + int_wrapper input[3] = {13, 55, 12345}; + Read wrapped_input{input}; + holder mem; + Write wrapped_output{mem.as_span()}; + + int_wrapper::clear_counts(); + same_as, iterator_t>> auto result = + uninitialized_move_n(wrapped_input.begin(), 3, wrapped_output.begin(), wrapped_output.end()); + assert(int_wrapper::constructions == 3); + assert(int_wrapper::destructions == 0); + assert(result.in == wrapped_input.end()); + construct_at(addressof(*result.out), -1); // Need to construct non written element for comparison + assert(++result.out == wrapped_output.end()); + assert(equal(wrapped_output, expected_output_long, equal_to{}, &int_wrapper::val)); + assert(equal(input, expected_input, equal_to{}, &int_wrapper::val)); + destroy(wrapped_output); + assert(int_wrapper::constructions == 4); + assert(int_wrapper::destructions == 4); + } } }; @@ -129,17 +166,39 @@ struct throwing_test { }; struct memcopy_test { - static constexpr int expected_output[] = {13, 55, 12345, -1}; - static constexpr int expected_input[] = {13, 55, 12345, 42}; + static constexpr int expected_output[] = {13, 55, 12345, -1}; + static constexpr int expected_output_long[] = {13, 55, -1, -1}; + static constexpr int expected_input[] = {13, 55, 12345, 42}; + static constexpr int expected_input_short[] = {13, 55}; + static constexpr int expected_input_long[] = {13, 55, 12345, 42}; static void call() { - // Validate only range overload (one is plenty since they both use the same backend) - int input[] = {13, 55, 12345, 42}; - int output[] = {-1, -1, -1, -1}; + { // Validate range overload + int input[] = {13, 55, 12345, 42}; + int output[] = {-1, -1, -1, -1}; + + ranges::uninitialized_move_n(input, 3, begin(output), end(output)); + assert(ranges::equal(input, expected_input)); + assert(ranges::equal(output, expected_output)); + } + + { // Validate shorter input + int input[] = {13, 55}; + int output[] = {-1, -1, -1, -1}; - ranges::uninitialized_move_n(input, 3, output, output + 4); - assert(ranges::equal(input, expected_input)); - assert(ranges::equal(output, expected_output)); + ranges::uninitialized_move_n(input, 2, begin(output), end(output)); + assert(ranges::equal(input, expected_input_short)); + assert(ranges::equal(output, expected_output_long)); + } + + { // Validate shorter output + int input[] = {13, 55, 12345, 42}; + int output[] = {-1, -1}; + + ranges::uninitialized_move_n(input, 3, begin(output), end(output)); + assert(ranges::equal(input, expected_input)); + assert(ranges::equal(output, expected_input_short)); + } } }; From d5025c34a66bafd9a8a9fb49a33acb3e53645c2b Mon Sep 17 00:00:00 2001 From: Michael Schellenberger Costa Date: Sat, 13 Feb 2021 10:51:35 +0100 Subject: [PATCH 3/5] Fix ranges::uninitialized_meow_n algorithms --- stl/inc/memory | 8 +++- .../test.cpp | 40 +++++++++++++------ .../test.cpp | 40 +++++++++++++------ 3 files changed, 62 insertions(+), 26 deletions(-) diff --git a/stl/inc/memory b/stl/inc/memory index 8364561c27a..ae479ece7bb 100644 --- a/stl/inc/memory +++ b/stl/inc/memory @@ -149,7 +149,9 @@ namespace ranges { auto _OFirst = _Get_unwrapped(_STD move(_First2)); const auto _OLast = _Get_unwrapped(_STD move(_Last2)); if constexpr (_Ptr_copy_cat<_It, _Out>::_Really_trivial) { - return _Copy_memcpy_common(_IFirst, _IFirst + _Count, _OFirst, _OLast); + auto _UResult = _Copy_memcpy_common(_IFirst, _IFirst + _Count, _OFirst, _OLast); + _IFirst = _UResult.in; + _OFirst = _UResult.out; } else { _Uninitialized_backout _Backout{_STD move(_OFirst)}; @@ -283,7 +285,9 @@ namespace ranges { auto _OFirst = _Get_unwrapped(_STD move(_First2)); const auto _OLast = _Get_unwrapped(_STD move(_Last2)); if constexpr (_Ptr_move_cat<_It, _Out>::_Really_trivial) { - return _Copy_memcpy_common(_IFirst, _IFirst + _Count, _OFirst, _OLast); + auto _UResult = _Copy_memcpy_common(_IFirst, _IFirst + _Count, _OFirst, _OLast); + _IFirst = _UResult.in; + _OFirst = _UResult.out; } else { _Uninitialized_backout _Backout{_STD move(_OFirst)}; diff --git a/tests/std/tests/P0896R4_ranges_alg_uninitialized_copy_n/test.cpp b/tests/std/tests/P0896R4_ranges_alg_uninitialized_copy_n/test.cpp index e48f1383271..b4ecf6ac0f5 100644 --- a/tests/std/tests/P0896R4_ranges_alg_uninitialized_copy_n/test.cpp +++ b/tests/std/tests/P0896R4_ranges_alg_uninitialized_copy_n/test.cpp @@ -172,31 +172,47 @@ struct memcopy_test { static constexpr int expected_input_long[] = {13, 55, 12345, 42}; static void call() { + using ranges::uninitialized_copy_n, ranges::uninitialized_copy_n_result, ranges::equal, ranges::iterator_t; { // Validate range overload int input[] = {13, 55, 12345, 42}; int output[] = {-1, -1, -1, -1}; - - ranges::uninitialized_copy_n(input, 3, begin(output), end(output)); - assert(ranges::equal(input, expected_input)); - assert(ranges::equal(output, expected_output)); + span wrapped_input{input}; + span wrapped_output{output}; + + const same_as>, iterator_t>>> auto result = + uninitialized_copy_n(wrapped_input.begin(), 3, begin(wrapped_output), end(wrapped_output)); + assert(next(result.in) == end(wrapped_input)); + assert(next(result.out) == end(wrapped_output)); + assert(equal(input, expected_input)); + assert(equal(output, expected_output)); } { // Validate shorter input int input[] = {13, 55}; int output[] = {-1, -1, -1, -1}; - - ranges::uninitialized_copy_n(input, 2, begin(output), end(output)); - assert(ranges::equal(input, expected_input_short)); - assert(ranges::equal(output, expected_output_long)); + span wrapped_input{input}; + span wrapped_output{output}; + + const same_as>, iterator_t>>> auto result = + uninitialized_copy_n(wrapped_input.begin(), 2, begin(wrapped_output), end(wrapped_output)); + assert(result.in == end(wrapped_input)); + assert(next(result.out, 2) == end(wrapped_output)); + assert(equal(input, expected_input_short)); + assert(equal(output, expected_output_long)); } { // Validate shorter output int input[] = {13, 55, 12345, 42}; int output[] = {-1, -1}; - - ranges::uninitialized_copy_n(input, 3, begin(output), end(output)); - assert(ranges::equal(input, expected_input)); - assert(ranges::equal(output, expected_input_short)); + span wrapped_input{input}; + span wrapped_output{output}; + + const same_as>, iterator_t>>> auto result = + uninitialized_copy_n(wrapped_input.begin(), 2, begin(wrapped_output), end(wrapped_output)); + assert(next(result.in, 2) == end(wrapped_input)); + assert(result.out == end(wrapped_output)); + assert(equal(input, expected_input)); + assert(equal(output, expected_input_short)); } } }; diff --git a/tests/std/tests/P0896R4_ranges_alg_uninitialized_move_n/test.cpp b/tests/std/tests/P0896R4_ranges_alg_uninitialized_move_n/test.cpp index 498ed9dcf90..f4cd71ab702 100644 --- a/tests/std/tests/P0896R4_ranges_alg_uninitialized_move_n/test.cpp +++ b/tests/std/tests/P0896R4_ranges_alg_uninitialized_move_n/test.cpp @@ -173,31 +173,47 @@ struct memcopy_test { static constexpr int expected_input_long[] = {13, 55, 12345, 42}; static void call() { + using ranges::uninitialized_move_n, ranges::uninitialized_move_n_result, ranges::equal, ranges::iterator_t; { // Validate range overload int input[] = {13, 55, 12345, 42}; int output[] = {-1, -1, -1, -1}; - - ranges::uninitialized_move_n(input, 3, begin(output), end(output)); - assert(ranges::equal(input, expected_input)); - assert(ranges::equal(output, expected_output)); + span wrapped_input{input}; + span wrapped_output{output}; + + const same_as>, iterator_t>>> auto result = + uninitialized_move_n(wrapped_input.begin(), 3, begin(wrapped_output), end(wrapped_output)); + assert(next(result.in) == end(wrapped_input)); + assert(next(result.out) == end(wrapped_output)); + assert(equal(input, expected_input)); + assert(equal(output, expected_output)); } { // Validate shorter input int input[] = {13, 55}; int output[] = {-1, -1, -1, -1}; - - ranges::uninitialized_move_n(input, 2, begin(output), end(output)); - assert(ranges::equal(input, expected_input_short)); - assert(ranges::equal(output, expected_output_long)); + span wrapped_input{input}; + span wrapped_output{output}; + + const same_as>, iterator_t>>> auto result = + uninitialized_move_n(wrapped_input.begin(), 2, begin(wrapped_output), end(wrapped_output)); + assert(result.in == end(wrapped_input)); + assert(next(result.out, 2) == end(wrapped_output)); + assert(equal(input, expected_input_short)); + assert(equal(output, expected_output_long)); } { // Validate shorter output int input[] = {13, 55, 12345, 42}; int output[] = {-1, -1}; - - ranges::uninitialized_move_n(input, 3, begin(output), end(output)); - assert(ranges::equal(input, expected_input)); - assert(ranges::equal(output, expected_input_short)); + span wrapped_input{input}; + span wrapped_output{output}; + + const same_as>, iterator_t>>> auto result = + uninitialized_move_n(wrapped_input.begin(), 2, begin(wrapped_output), end(wrapped_output)); + assert(next(result.in, 2) == end(wrapped_input)); + assert(result.out == end(wrapped_output)); + assert(equal(input, expected_input)); + assert(equal(output, expected_input_short)); } } }; From cc06ff4430f36082e0cfa5ca81e690de963893ee Mon Sep 17 00:00:00 2001 From: Michael Schellenberger Costa Date: Sat, 13 Feb 2021 14:08:19 +0100 Subject: [PATCH 4/5] Somebody made span::iterator an aggregate so use vector instead --- .../test.cpp | 49 +++++++++---------- .../test.cpp | 48 ++++++++---------- 2 files changed, 43 insertions(+), 54 deletions(-) diff --git a/tests/std/tests/P0896R4_ranges_alg_uninitialized_copy_n/test.cpp b/tests/std/tests/P0896R4_ranges_alg_uninitialized_copy_n/test.cpp index b4ecf6ac0f5..dd4bb527303 100644 --- a/tests/std/tests/P0896R4_ranges_alg_uninitialized_copy_n/test.cpp +++ b/tests/std/tests/P0896R4_ranges_alg_uninitialized_copy_n/test.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include @@ -174,43 +175,37 @@ struct memcopy_test { static void call() { using ranges::uninitialized_copy_n, ranges::uninitialized_copy_n_result, ranges::equal, ranges::iterator_t; { // Validate range overload - int input[] = {13, 55, 12345, 42}; - int output[] = {-1, -1, -1, -1}; - span wrapped_input{input}; - span wrapped_output{output}; - - const same_as>, iterator_t>>> auto result = - uninitialized_copy_n(wrapped_input.begin(), 3, begin(wrapped_output), end(wrapped_output)); - assert(next(result.in) == end(wrapped_input)); - assert(next(result.out) == end(wrapped_output)); + vector input = {13, 55, 12345, 42}; + vector output = {-1, -1, -1, -1}; + + const same_as>, iterator_t>>> auto result = + uninitialized_copy_n(input.begin(), 3, output.begin(), output.end()); + assert(next(result.in) == input.end()); + assert(next(result.out) == output.end()); assert(equal(input, expected_input)); assert(equal(output, expected_output)); } { // Validate shorter input - int input[] = {13, 55}; - int output[] = {-1, -1, -1, -1}; - span wrapped_input{input}; - span wrapped_output{output}; - - const same_as>, iterator_t>>> auto result = - uninitialized_copy_n(wrapped_input.begin(), 2, begin(wrapped_output), end(wrapped_output)); - assert(result.in == end(wrapped_input)); - assert(next(result.out, 2) == end(wrapped_output)); + vector input = {13, 55}; + vector output = {-1, -1, -1, -1}; + + const same_as>, iterator_t>>> auto result = + uninitialized_copy_n(input.begin(), 2, output.begin(), output.end()); + assert(result.in == input.end()); + assert(next(result.out, 2) == output.end()); assert(equal(input, expected_input_short)); assert(equal(output, expected_output_long)); } { // Validate shorter output - int input[] = {13, 55, 12345, 42}; - int output[] = {-1, -1}; - span wrapped_input{input}; - span wrapped_output{output}; - - const same_as>, iterator_t>>> auto result = - uninitialized_copy_n(wrapped_input.begin(), 2, begin(wrapped_output), end(wrapped_output)); - assert(next(result.in, 2) == end(wrapped_input)); - assert(result.out == end(wrapped_output)); + vector input = {13, 55, 12345, 42}; + vector output = {-1, -1}; + + const same_as>, iterator_t>>> auto result = + uninitialized_copy_n(input.begin(), 2, output.begin(), output.end()); + assert(next(result.in, 2) == input.end()); + assert(result.out == output.end()); assert(equal(input, expected_input)); assert(equal(output, expected_input_short)); } diff --git a/tests/std/tests/P0896R4_ranges_alg_uninitialized_move_n/test.cpp b/tests/std/tests/P0896R4_ranges_alg_uninitialized_move_n/test.cpp index f4cd71ab702..4259527c3e5 100644 --- a/tests/std/tests/P0896R4_ranges_alg_uninitialized_move_n/test.cpp +++ b/tests/std/tests/P0896R4_ranges_alg_uninitialized_move_n/test.cpp @@ -175,43 +175,37 @@ struct memcopy_test { static void call() { using ranges::uninitialized_move_n, ranges::uninitialized_move_n_result, ranges::equal, ranges::iterator_t; { // Validate range overload - int input[] = {13, 55, 12345, 42}; - int output[] = {-1, -1, -1, -1}; - span wrapped_input{input}; - span wrapped_output{output}; - - const same_as>, iterator_t>>> auto result = - uninitialized_move_n(wrapped_input.begin(), 3, begin(wrapped_output), end(wrapped_output)); - assert(next(result.in) == end(wrapped_input)); - assert(next(result.out) == end(wrapped_output)); + vector input = {13, 55, 12345, 42}; + vector output = {-1, -1, -1, -1}; + + const same_as>, iterator_t>>> auto result = + uninitialized_move_n(input.begin(), 3, output.begin(), output.end()); + assert(next(result.in) == input.end()); + assert(next(result.out) == output.end()); assert(equal(input, expected_input)); assert(equal(output, expected_output)); } { // Validate shorter input - int input[] = {13, 55}; - int output[] = {-1, -1, -1, -1}; - span wrapped_input{input}; - span wrapped_output{output}; - - const same_as>, iterator_t>>> auto result = - uninitialized_move_n(wrapped_input.begin(), 2, begin(wrapped_output), end(wrapped_output)); - assert(result.in == end(wrapped_input)); - assert(next(result.out, 2) == end(wrapped_output)); + vector input = {13, 55}; + vector output = {-1, -1, -1, -1}; + + const same_as>, iterator_t>>> auto result = + uninitialized_move_n(input.begin(), 2, output.begin(), output.end()); + assert(result.in == input.end()); + assert(next(result.out, 2) == output.end()); assert(equal(input, expected_input_short)); assert(equal(output, expected_output_long)); } { // Validate shorter output - int input[] = {13, 55, 12345, 42}; - int output[] = {-1, -1}; - span wrapped_input{input}; - span wrapped_output{output}; - - const same_as>, iterator_t>>> auto result = - uninitialized_move_n(wrapped_input.begin(), 2, begin(wrapped_output), end(wrapped_output)); - assert(next(result.in, 2) == end(wrapped_input)); - assert(result.out == end(wrapped_output)); + vector input = {13, 55, 12345, 42}; + vector output = {-1, -1}; + + const same_as>, iterator_t>>> auto result = + uninitialized_move_n(input.begin(), 2, output.begin(), output.end()); + assert(next(result.in, 2) == input.end()); + assert(result.out == output.end()); assert(equal(input, expected_input)); assert(equal(output, expected_input_short)); } From 8692d16c3a4afbdf5a832cee50961b5e4ac90659 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Wed, 17 Feb 2021 17:45:37 -0800 Subject: [PATCH 5/5] Code review feedback. --- .../tests/P0896R4_ranges_alg_uninitialized_copy/test.cpp | 4 ++-- .../P0896R4_ranges_alg_uninitialized_copy_n/test.cpp | 4 ++-- .../tests/P0896R4_ranges_alg_uninitialized_move/test.cpp | 8 ++++---- .../P0896R4_ranges_alg_uninitialized_move_n/test.cpp | 5 +++-- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/tests/std/tests/P0896R4_ranges_alg_uninitialized_copy/test.cpp b/tests/std/tests/P0896R4_ranges_alg_uninitialized_copy/test.cpp index 6b5f9c064c2..38c0d687d54 100644 --- a/tests/std/tests/P0896R4_ranges_alg_uninitialized_copy/test.cpp +++ b/tests/std/tests/P0896R4_ranges_alg_uninitialized_copy/test.cpp @@ -196,7 +196,7 @@ struct throwing_test { } }; -struct memcopy_test { +struct memcpy_test { static constexpr int expected_output[] = {13, 55, 12345}; static constexpr int expected_output_long[] = {13, 55, 12345, -1}; static constexpr int expected_input[] = {13, 55, 12345}; @@ -252,5 +252,5 @@ int main() { instantiator::call, test_output>(); throwing_test::call, test_output>(); throwing_test::call, test_output>(); - memcopy_test::call(); + memcpy_test::call(); } diff --git a/tests/std/tests/P0896R4_ranges_alg_uninitialized_copy_n/test.cpp b/tests/std/tests/P0896R4_ranges_alg_uninitialized_copy_n/test.cpp index dd4bb527303..3096d91b16a 100644 --- a/tests/std/tests/P0896R4_ranges_alg_uninitialized_copy_n/test.cpp +++ b/tests/std/tests/P0896R4_ranges_alg_uninitialized_copy_n/test.cpp @@ -165,7 +165,7 @@ struct throwing_test { } }; -struct memcopy_test { +struct memcpy_test { static constexpr int expected_output[] = {13, 55, 12345, -1}; static constexpr int expected_output_long[] = {13, 55, -1, -1}; static constexpr int expected_input[] = {13, 55, 12345, 42}; @@ -226,5 +226,5 @@ int main() { instantiator::call, test_output>(); throwing_test::call, test_output>(); throwing_test::call, test_output>(); - memcopy_test::call(); + memcpy_test::call(); } diff --git a/tests/std/tests/P0896R4_ranges_alg_uninitialized_move/test.cpp b/tests/std/tests/P0896R4_ranges_alg_uninitialized_move/test.cpp index faab56bb711..865dcffcccf 100644 --- a/tests/std/tests/P0896R4_ranges_alg_uninitialized_move/test.cpp +++ b/tests/std/tests/P0896R4_ranges_alg_uninitialized_move/test.cpp @@ -85,8 +85,8 @@ struct instantiator { template static void call() { - using ranges::destroy, ranges::uninitialized_move, ranges::uninitialized_move_result, ranges::destroy, - ranges::equal, ranges::equal_to, ranges::iterator_t; + using ranges::uninitialized_move, ranges::uninitialized_move_result, ranges::destroy, ranges::equal, + ranges::equal_to, ranges::iterator_t; { // Validate range overload int_wrapper input[3] = {13, 55, 12345}; @@ -197,7 +197,7 @@ struct throwing_test { } }; -struct memcopy_test { +struct memcpy_test { static constexpr int expected_output[] = {13, 55, 12345}; static constexpr int expected_output_long[] = {13, 55, 12345, -1}; static constexpr int expected_input[] = {13, 55, 12345}; @@ -251,5 +251,5 @@ int main() { instantiator::call, test_output>(); throwing_test::call, test_output>(); throwing_test::call, test_output>(); - memcopy_test::call(); + memcpy_test::call(); } diff --git a/tests/std/tests/P0896R4_ranges_alg_uninitialized_move_n/test.cpp b/tests/std/tests/P0896R4_ranges_alg_uninitialized_move_n/test.cpp index 4259527c3e5..60d6a79c732 100644 --- a/tests/std/tests/P0896R4_ranges_alg_uninitialized_move_n/test.cpp +++ b/tests/std/tests/P0896R4_ranges_alg_uninitialized_move_n/test.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include @@ -165,7 +166,7 @@ struct throwing_test { } }; -struct memcopy_test { +struct memcpy_test { static constexpr int expected_output[] = {13, 55, 12345, -1}; static constexpr int expected_output_long[] = {13, 55, -1, -1}; static constexpr int expected_input[] = {13, 55, 12345, 42}; @@ -226,5 +227,5 @@ int main() { instantiator::call, test_output>(); throwing_test::call, test_output>(); throwing_test::call, test_output>(); - memcopy_test::call(); + memcpy_test::call(); }