From: Patrick Palka <ppalka@redhat.com>
To: gcc-patches@gcc.gnu.org
Cc: libstdc++@gcc.gnu.org, Patrick Palka <ppalka@redhat.com>
Subject: [PATCH 1/2] libstdc++: Implement LWG 3523 changes to ranges::iota_view
Date: Tue, 19 Oct 2021 08:17:03 -0400 [thread overview]
Message-ID: <20211019121704.1510908-1-ppalka@redhat.com> (raw)
libstdc++-v3/ChangeLog:
* include/std/ranges (iota_view::_Iterator): Befriend iota_view.
(iota_view::_Sentinel): Likewise.
(iota_view::iota_view): Add three overloads each taking an
iterator/sentinel pair as per LWG 3523.
* testsuite/std/ranges/iota/iota_view.cc (test06): New test.
---
libstdc++-v3/include/std/ranges | 21 +++++++++++++++++++
.../testsuite/std/ranges/iota/iota_view.cc | 21 +++++++++++++++++++
2 files changed, 42 insertions(+)
diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges
index b8de400dfbb..85f232d8fb9 100644
--- a/libstdc++-v3/include/std/ranges
+++ b/libstdc++-v3/include/std/ranges
@@ -532,6 +532,7 @@ namespace ranges
private:
_Winc _M_value = _Winc();
+ friend iota_view;
friend _Sentinel;
};
@@ -568,6 +569,8 @@ namespace ranges
operator-(const _Sentinel& __x, const _Iterator& __y)
requires sized_sentinel_for<_Bound, _Winc>
{ return __x._M_distance_from(__y); }
+
+ friend iota_view;
};
_Winc _M_value = _Winc();
@@ -590,6 +593,24 @@ namespace ranges
__glibcxx_assert( bool(__value <= __bound) );
}
+ constexpr
+ iota_view(_Iterator __first, _Iterator __last)
+ requires same_as<_Winc, _Bound>
+ : iota_view(__first._M_value, __last._M_value)
+ { }
+
+ constexpr
+ iota_view(_Iterator __first, unreachable_sentinel_t __last)
+ requires same_as<_Bound, unreachable_sentinel_t>
+ : iota_view(__first._M_value, __last)
+ { }
+
+ constexpr
+ iota_view(_Iterator __first, _Sentinel __last)
+ requires (!same_as<_Winc, _Bound>) && (!same_as<_Bound, unreachable_sentinel_t>)
+ : iota_view(__first._M_value, __last._M_bound)
+ { }
+
constexpr _Iterator
begin() const { return _Iterator{_M_value}; }
diff --git a/libstdc++-v3/testsuite/std/ranges/iota/iota_view.cc b/libstdc++-v3/testsuite/std/ranges/iota/iota_view.cc
index 362ef1f7f78..5bebe4be693 100644
--- a/libstdc++-v3/testsuite/std/ranges/iota/iota_view.cc
+++ b/libstdc++-v3/testsuite/std/ranges/iota/iota_view.cc
@@ -18,6 +18,7 @@
// { dg-options "-std=gnu++2a" }
// { dg-do run { target c++2a } }
+#include <algorithm>
#include <ranges>
#include <testsuite_hooks.h>
@@ -90,6 +91,25 @@ test05()
VERIFY( r.begin() - r.end() == -3 );
}
+void
+test06()
+{
+ // Verify LWG 3523 changes.
+ auto v1 = std::views::iota(0, 5);
+ auto w1 = decltype(v1)(v1.begin(), v1.end());
+ VERIFY( std::ranges::equal(v1, w1) );
+
+ auto v2 = std::views::iota(0);
+ auto w2 = decltype(v2)(v2.begin(), v2.end());
+ static_assert(std::same_as<decltype(w2.end()), std::unreachable_sentinel_t>);
+ VERIFY( *w2.begin() == 0 );
+
+ auto v3 = std::views::iota(0, 5l);
+ auto w3 = decltype(v3)(v3.begin(), v3.end());
+ static_assert(!std::ranges::common_range<decltype(w3)>);
+ VERIFY( std::ranges::equal(v3, w3) );
+}
+
int
main()
{
@@ -98,4 +118,5 @@ main()
test03();
test04();
test05();
+ test06();
}
--
2.33.1.637.gf443b226ca
next reply other threads:[~2021-10-19 12:17 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-19 12:17 Patrick Palka [this message]
2021-10-19 12:17 ` [PATCH 2/2] libstdc++: Implement P1739R4 changes to views::take/drop/counted Patrick Palka
2021-10-21 15:22 ` Jonathan Wakely
2021-10-19 12:37 ` [PATCH 1/2] libstdc++: Implement LWG 3523 changes to ranges::iota_view Jonathan Wakely
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=20211019121704.1510908-1-ppalka@redhat.com \
--to=ppalka@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).