public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
From: Patrick Palka <ppalka@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org
Subject: [gcc r14-7258] libstdc++: Implement P2836R1 changes to const_iterator
Date: Mon, 15 Jan 2024 20:14:06 +0000 (GMT)	[thread overview]
Message-ID: <20240115201406.E08883858C74@sourceware.org> (raw)

https://gcc.gnu.org/g:731444b3c39e3dc3dd8778f430a38742861dcca1

commit r14-7258-g731444b3c39e3dc3dd8778f430a38742861dcca1
Author: Patrick Palka <ppalka@redhat.com>
Date:   Mon Jan 15 15:13:53 2024 -0500

    libstdc++: Implement P2836R1 changes to const_iterator
    
    libstdc++-v3/ChangeLog:
    
            * include/bits/stl_iterator.h (const_iterator): Define conversion
            operators as per P2836R1.
            * include/bits/version.def (ranges_as_const): Update value.
            * include/bits/version.h: Regenerate.
            * testsuite/24_iterators/const_iterator/1.cc (test04): New test.
            * testsuite/std/ranges/adaptors/as_const/1.cc: Adjust expected
            value of __cpp_lib_ranges_as_const.
            * testsuite/std/ranges/version_c++23.cc: Likewise.
    
    Reviewed-by: Jonathan Wakely <jwakely@redhat.com>

Diff:
---
 libstdc++-v3/include/bits/stl_iterator.h           | 12 ++++++++++++
 libstdc++-v3/include/bits/version.def              |  2 +-
 libstdc++-v3/include/bits/version.h                |  4 ++--
 .../testsuite/24_iterators/const_iterator/1.cc     | 22 ++++++++++++++++++++++
 .../testsuite/std/ranges/adaptors/as_const/1.cc    |  2 +-
 libstdc++-v3/testsuite/std/ranges/version_c++23.cc |  2 +-
 6 files changed, 39 insertions(+), 5 deletions(-)

diff --git a/libstdc++-v3/include/bits/stl_iterator.h b/libstdc++-v3/include/bits/stl_iterator.h
index 6434ef64750..d71a793e10d 100644
--- a/libstdc++-v3/include/bits/stl_iterator.h
+++ b/libstdc++-v3/include/bits/stl_iterator.h
@@ -2775,6 +2775,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       noexcept(noexcept(_M_current == __s))
       { return _M_current == __s; }
 
+    template<__detail::__not_a_const_iterator _CIt>
+      requires __detail::__constant_iterator<_CIt> && convertible_to<_It, _CIt>
+    constexpr
+    operator _CIt() const&
+    { return _M_current; }
+
+    template<__detail::__not_a_const_iterator _CIt>
+      requires __detail::__constant_iterator<_CIt> && convertible_to<_It, _CIt>
+    constexpr
+    operator _CIt() &&
+    { return std::move(_M_current); }
+
     constexpr bool
     operator<(const basic_const_iterator& __y) const
     noexcept(noexcept(_M_current < __y._M_current))
diff --git a/libstdc++-v3/include/bits/version.def b/libstdc++-v3/include/bits/version.def
index 21cdc65121b..afbec6c3e6a 100644
--- a/libstdc++-v3/include/bits/version.def
+++ b/libstdc++-v3/include/bits/version.def
@@ -1548,7 +1548,7 @@ ftms = {
 ftms = {
   name = ranges_as_const;
   values = {
-    v = 202207;
+    v = 202311;
     cxxmin = 23;
   };
 };
diff --git a/libstdc++-v3/include/bits/version.h b/libstdc++-v3/include/bits/version.h
index f8dd16416a4..9688b246ef4 100644
--- a/libstdc++-v3/include/bits/version.h
+++ b/libstdc++-v3/include/bits/version.h
@@ -1875,9 +1875,9 @@
 // from version.def line 1549
 #if !defined(__cpp_lib_ranges_as_const)
 # if (__cplusplus >= 202100L)
-#  define __glibcxx_ranges_as_const 202207L
+#  define __glibcxx_ranges_as_const 202311L
 #  if defined(__glibcxx_want_all) || defined(__glibcxx_want_ranges_as_const)
-#   define __cpp_lib_ranges_as_const 202207L
+#   define __cpp_lib_ranges_as_const 202311L
 #  endif
 # endif
 #endif /* !defined(__cpp_lib_ranges_as_const) && defined(__glibcxx_want_ranges_as_const) */
diff --git a/libstdc++-v3/testsuite/24_iterators/const_iterator/1.cc b/libstdc++-v3/testsuite/24_iterators/const_iterator/1.cc
index 8b74d110fdf..fe952bfad14 100644
--- a/libstdc++-v3/testsuite/24_iterators/const_iterator/1.cc
+++ b/libstdc++-v3/testsuite/24_iterators/const_iterator/1.cc
@@ -1,6 +1,7 @@
 // { dg-do run { target c++23 } }
 
 #include <iterator>
+#include <ranges>
 #include <array>
 #include <concepts>
 #include <string_view>
@@ -97,6 +98,26 @@ test03()
 			     std::unreachable_sentinel_t> );
 }
 
+void
+test04()
+{
+  // Example from P2836R1
+  auto f = [](std::vector<int>::const_iterator i) {};
+
+  auto v = std::vector<int>();
+  {
+    auto i1 = ranges::cbegin(v); // returns vector<T>::const_iterator
+    f(i1); // okay
+  }
+
+  auto t = v | std::views::take_while([](int const x) { return x < 100; });
+  {
+    auto i2 = ranges::cbegin(t); // returns basic_const_iterator<vector<T>::iterator>
+    f(i2); // was an error in C++23 before P2836R1
+    f(std::move(i2)); // same
+  }
+}
+
 int
 main()
 {
@@ -136,4 +157,5 @@ main()
   test02<const std::vector<bool>, true>();
 
   test03();
+  test04();
 }
diff --git a/libstdc++-v3/testsuite/std/ranges/adaptors/as_const/1.cc b/libstdc++-v3/testsuite/std/ranges/adaptors/as_const/1.cc
index 2d36e0a4712..c36786a8c5f 100644
--- a/libstdc++-v3/testsuite/std/ranges/adaptors/as_const/1.cc
+++ b/libstdc++-v3/testsuite/std/ranges/adaptors/as_const/1.cc
@@ -3,7 +3,7 @@
 
 #include <ranges>
 
-#if __cpp_lib_ranges_as_const != 202207L
+#if __cpp_lib_ranges_as_const != 202311L
 # error "Feature-test macro __cpp_lib_ranges_as_const has wrong value in <ranges>"
 #endif
 
diff --git a/libstdc++-v3/testsuite/std/ranges/version_c++23.cc b/libstdc++-v3/testsuite/std/ranges/version_c++23.cc
index 823264f32aa..d475d3dc114 100644
--- a/libstdc++-v3/testsuite/std/ranges/version_c++23.cc
+++ b/libstdc++-v3/testsuite/std/ranges/version_c++23.cc
@@ -45,7 +45,7 @@
 # error "Feature-test macro __cpp_lib_ranges_as_rvalue has wrong value in <version>"
 #endif
 
-#if __cpp_lib_ranges_as_const != 202207L
+#if __cpp_lib_ranges_as_const != 202311L
 # error "Feature-test macro __cpp_lib_ranges_as_const has wrong value in <version>"
 #endif

                 reply	other threads:[~2024-01-15 20:14 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=20240115201406.E08883858C74@sourceware.org \
    --to=ppalka@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    --cc=libstdc++-cvs@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).