From: Patrick Palka <ppalka@redhat.com>
To: gcc-patches@gcc.gnu.org
Cc: libstdc++@gcc.gnu.org, Patrick Palka <ppalka@redhat.com>
Subject: [PATCH] libstdc++: Give split_view::_Sentinel a default ctor [PR101214]
Date: Tue, 13 Jul 2021 14:04:29 -0400 [thread overview]
Message-ID: <20210713180429.645823-1-ppalka@redhat.com> (raw)
This gives the new split_view's sentinel type a defaulted default
constructor, something which was overlooked in r12-1665. This patch
also fixes a couple of other issues with the new split_view as reported
in the PR.
Tested on x86_64-pc-linux-gnu, does this look OK for trunk?
PR libstdc++/101214
libstdc++-v3/ChangeLog:
* include/std/ranges (split_view::split_view): Use std::move.
(split_view::_Iterator::_Iterator): Remove redundant
default_initializable constraint.
(split_view::_Sentinel::_Sentinel): Declare.
* testsuite/std/ranges/adaptors/split.cc (test02): New test.
---
libstdc++-v3/include/std/ranges | 6 ++++--
libstdc++-v3/testsuite/std/ranges/adaptors/split.cc | 11 +++++++++++
2 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges
index f552caa9d5b..df74ac9dc19 100644
--- a/libstdc++-v3/include/std/ranges
+++ b/libstdc++-v3/include/std/ranges
@@ -3306,7 +3306,7 @@ namespace views::__adaptor
&& constructible_from<_Pattern, single_view<range_value_t<_Range>>>
constexpr
split_view(_Range&& __r, range_value_t<_Range> __e)
- : _M_pattern(views::single(__e)),
+ : _M_pattern(views::single(std::move(__e))),
_M_base(views::all(std::forward<_Range>(__r)))
{ }
@@ -3364,7 +3364,7 @@ namespace views::__adaptor
using value_type = subrange<iterator_t<_Vp>>;
using difference_type = range_difference_t<_Vp>;
- _Iterator() requires default_initializable<iterator_t<_Vp>> = default;
+ _Iterator() = default;
constexpr
_Iterator(split_view* __parent,
@@ -3429,6 +3429,8 @@ namespace views::__adaptor
{ return __x._M_cur == _M_end && !__x._M_trailing_empty; }
public:
+ _Sentinel() = default;
+
constexpr explicit
_Sentinel(split_view* __parent)
: _M_end(ranges::end(__parent->_M_base))
diff --git a/libstdc++-v3/testsuite/std/ranges/adaptors/split.cc b/libstdc++-v3/testsuite/std/ranges/adaptors/split.cc
index 02c6073a503..b4e01fea6e4 100644
--- a/libstdc++-v3/testsuite/std/ranges/adaptors/split.cc
+++ b/libstdc++-v3/testsuite/std/ranges/adaptors/split.cc
@@ -46,6 +46,16 @@ test01()
VERIFY( ranges::equal(ints, (int[]){1,2,3,4}) );
}
+void
+test02()
+{
+ // PR libstdc++/101214
+ auto v = views::iota(0) | views::take(5) | views::split(0);
+ static_assert(!ranges::common_range<decltype(v)>);
+ static_assert(std::default_initializable<decltype(v.end())>);
+ static_assert(std::sentinel_for<decltype(v.end()), decltype(v.begin())>);
+}
+
// The following testcases are adapted from lazy_split.cc.
namespace from_lazy_split_cc
{
@@ -189,6 +199,7 @@ int
main()
{
test01();
+ test02();
from_lazy_split_cc::test01();
from_lazy_split_cc::test02();
--
2.32.0.170.gd486ca60a5
next reply other threads:[~2021-07-13 18:04 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-13 18:04 Patrick Palka [this message]
2021-07-15 20:01 ` Jonathan Wakely
2021-07-13 19:05 Patrick Palka
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=20210713180429.645823-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).