diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2022-11-03 09:17:57 +0000 |
---|---|---|
committer | Jonathan Wakely <jwakely@redhat.com> | 2023-05-16 11:15:01 +0100 |
commit | ccd8faeecfa8042f808eaed9fa1afebdfe6b19c4 (patch) | |
tree | 35593d6872edb01cbe303919fd6c22c04572c8c0 | |
parent | 9578570e305e77b8c105583506781158c137f743 (diff) | |
download | gcc-ccd8faeecfa8042f808eaed9fa1afebdfe6b19c4.tar.gz |
libstdc++: Add missing move in ranges::copy
This is needed to support a move-only output iterator when the input
iterators are specializations of __normal_iterator.
libstdc++-v3/ChangeLog:
* include/bits/ranges_algobase.h (__detail::__copy_or_move):
Move output iterator.
* testsuite/25_algorithms/copy/constrained.cc: Check copying to
move-only output iterator.
(cherry picked from commit 2ff0e62275b1c322a8b65f38f8336f37d31c30e4)
-rw-r--r-- | libstdc++-v3/include/bits/ranges_algobase.h | 2 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/25_algorithms/copy/constrained.cc | 24 |
2 files changed, 25 insertions, 1 deletions
diff --git a/libstdc++-v3/include/bits/ranges_algobase.h b/libstdc++-v3/include/bits/ranges_algobase.h index de8afd16582..08f536f4fce 100644 --- a/libstdc++-v3/include/bits/ranges_algobase.h +++ b/libstdc++-v3/include/bits/ranges_algobase.h @@ -238,7 +238,7 @@ namespace ranges { auto [__in,__out] = ranges::__copy_or_move<_IsMove>(__first.base(), __last.base(), - __result); + std::move(__result)); return {decltype(__first){__in}, std::move(__out)}; } else if constexpr (__is_normal_iterator<_Out>) diff --git a/libstdc++-v3/testsuite/25_algorithms/copy/constrained.cc b/libstdc++-v3/testsuite/25_algorithms/copy/constrained.cc index a05948a49c6..91f742dca76 100644 --- a/libstdc++-v3/testsuite/25_algorithms/copy/constrained.cc +++ b/libstdc++-v3/testsuite/25_algorithms/copy/constrained.cc @@ -226,6 +226,29 @@ test06() VERIFY( ranges::equal(v, (int[]){1,2,3,0}) ); } +void +test07() +{ + struct move_only_output_iterator + { + using value_type = int; + using difference_type = short; + using iterator_category = std::output_iterator_tag; + + move_only_output_iterator() = default; + move_only_output_iterator(move_only_output_iterator&&) = default; + move_only_output_iterator& operator=(move_only_output_iterator&&) = default; + + move_only_output_iterator& operator*() { return *this; } + move_only_output_iterator& operator++() { return *this; } + move_only_output_iterator operator++(int) { return std::move(*this); } + + void operator=(int) { } + }; + + ranges::copy(std::vector<int>{1,2,3}, move_only_output_iterator{}); +} + int main() { @@ -235,4 +258,5 @@ main() test04(); static_assert(test05()); test06(); + test07(); } |