public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely@redhat.com>
To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: [committed] libstdc++: Add missing move in ranges::copy
Date: Thu,  3 Nov 2022 11:41:52 +0000	[thread overview]
Message-ID: <20221103114152.708336-1-jwakely@redhat.com> (raw)

Tested x86_64-linux. Pushed to trunk.

-- >8 --

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.
---
 libstdc++-v3/include/bits/ranges_algobase.h   |  2 +-
 .../25_algorithms/copy/constrained.cc         | 24 +++++++++++++++++++
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/bits/ranges_algobase.h b/libstdc++-v3/include/bits/ranges_algobase.h
index f6f0b9c83b0..443ad52ecc6 100644
--- a/libstdc++-v3/include/bits/ranges_algobase.h
+++ b/libstdc++-v3/include/bits/ranges_algobase.h
@@ -239,7 +239,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 98f038a6c5f..444dfa78894 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();
 }
-- 
2.38.1


                 reply	other threads:[~2022-11-03 11:41 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221103114152.708336-1-jwakely@redhat.com \
    --to=jwakely@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=libstdc++@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).