public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
From: Alexandre Oliva <aoliva@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org
Subject: [gcc(refs/users/aoliva/heads/testme)] libstdc++: Implement P1994R1 changes to ranges::elements_view
Date: Thu,  3 Sep 2020 16:03:04 +0000 (GMT)	[thread overview]
Message-ID: <20200903160304.10B0E3985827@sourceware.org> (raw)

https://gcc.gnu.org/g:97ab5daa6c1186d3b10872cc1d5b05da247d102c

commit 97ab5daa6c1186d3b10872cc1d5b05da247d102c
Author: Patrick Palka <ppalka@redhat.com>
Date:   Wed Aug 26 21:49:51 2020 -0400

    libstdc++: Implement P1994R1 changes to ranges::elements_view
    
    The example from the paper doesn't compile without the proposed
    resolution for LWG 3406, so we'll add a testcase for this once the
    proposed resolution is implemented.
    
    libstdc++-v3/ChangeLog:
    
            * include/std/ranges (elements_view::end): Replace these two
            overloads with four new overloads.
            (elements_view::_Iterator::operator==): Remove.
            (elements_view::_Iterator::operator-): Likewise.
            (elements_view::_Sentinel): Define.

Diff:
---
 libstdc++-v3/include/std/ranges | 74 +++++++++++++++++++++++++++++++++--------
 1 file changed, 60 insertions(+), 14 deletions(-)

diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges
index 9d22b138082..efa8d2cf9f4 100644
--- a/libstdc++-v3/include/std/ranges
+++ b/libstdc++-v3/include/std/ranges
@@ -3366,12 +3366,20 @@ namespace views
       { return _Iterator<true>(ranges::begin(_M_base)); }
 
       constexpr auto
-      end() requires (!__detail::__simple_view<_Vp>)
-      { return ranges::end(_M_base); }
+      end()
+      { return _Sentinel<false>{ranges::end(_M_base)}; }
 
       constexpr auto
-      end() const requires __detail::__simple_view<_Vp>
-      { return ranges::end(_M_base); }
+      end() requires common_range<_Vp>
+      { return _Iterator<false>{ranges::end(_M_base)}; }
+
+      constexpr auto
+      end() const requires range<const _Vp>
+      { return _Sentinel<true>{ranges::end(_M_base)}; }
+
+      constexpr auto
+      end() const requires common_range<const _Vp>
+      { return _Iterator<true>{ranges::end(_M_base)}; }
 
       constexpr auto
       size() requires sized_range<_Vp>
@@ -3382,6 +3390,9 @@ namespace views
       { return ranges::size(_M_base); }
 
     private:
+      template<bool _Const>
+	struct _Sentinel;
+
       template<bool _Const>
 	struct _Iterator
 	{
@@ -3484,10 +3495,6 @@ namespace views
 	    requires equality_comparable<iterator_t<_Base>>
 	  { return __x._M_current == __y._M_current; }
 
-	  friend constexpr bool
-	  operator==(const _Iterator& __x, const sentinel_t<_Base>& __y)
-	  { return __x._M_current == __y; }
-
 	  friend constexpr bool
 	  operator<(const _Iterator& __x, const _Iterator& __y)
 	    requires random_access_range<_Base>
@@ -3536,15 +3543,54 @@ namespace views
 	    requires random_access_range<_Base>
 	  { return __x._M_current - __y._M_current; }
 
-	  friend constexpr difference_type
-	  operator-(const _Iterator<_Const>& __x, const sentinel_t<_Base>& __y)
+	  friend _Sentinel<_Const>;
+	};
+
+      template<bool _Const>
+	struct _Sentinel
+	{
+	private:
+	  constexpr bool
+	  _M_equal(const _Iterator<_Const>& __x) const
+	  { return __x._M_current == _M_end; }
+
+	  using _Base = __detail::__maybe_const_t<_Const, _Vp>;
+	  sentinel_t<_Base> _M_end = sentinel_t<_Base>();
+
+	public:
+	  _Sentinel() = default;
+
+	  constexpr explicit
+	  _Sentinel(sentinel_t<_Base> __end)
+	    : _M_end(std::move(__end))
+	  { }
+
+	  constexpr
+	  _Sentinel(_Sentinel<!_Const> __other)
+	    requires _Const
+	      && convertible_to<sentinel_t<_Vp>, sentinel_t<_Base>>
+	    : _M_end(std::move(__other._M_end))
+	  { }
+
+	  constexpr sentinel_t<_Base>
+	  base() const
+	  { return _M_end; }
+
+	  friend constexpr bool
+	  operator==(const _Iterator<_Const>& __x, const _Sentinel& __y)
+	  { return __y._M_equal(__x); }
+
+	  friend constexpr range_difference_t<_Base>
+	  operator-(const _Iterator<_Const>& __x, const _Sentinel& __y)
 	    requires sized_sentinel_for<sentinel_t<_Base>, iterator_t<_Base>>
-	  { return __x._M_current - __y; }
+	  { return __x._M_current - __y._M_end; }
 
-	  friend constexpr difference_type
-	  operator-(const sentinel_t<_Base>& __x, const _Iterator<_Const>& __y)
+	  friend constexpr range_difference_t<_Base>
+	  operator-(const _Sentinel& __x, const _Iterator<_Const>& __y)
 	    requires sized_sentinel_for<sentinel_t<_Base>, iterator_t<_Base>>
-	  { return -(__y - __x); }
+	  { return __x._M_end - __y._M_current; }
+
+	  friend _Sentinel<!_Const>;
 	};
 
       _Vp _M_base = _Vp();


                 reply	other threads:[~2020-09-03 16:03 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=20200903160304.10B0E3985827@sourceware.org \
    --to=aoliva@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).