public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] libstdc++: Give split_view::_Sentinel a default ctor [PR101214]
@ 2021-07-13 18:04 Patrick Palka
  2021-07-15 20:01 ` Jonathan Wakely
  0 siblings, 1 reply; 3+ messages in thread
From: Patrick Palka @ 2021-07-13 18:04 UTC (permalink / raw)
  To: gcc-patches; +Cc: libstdc++, Patrick Palka

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] libstdc++: Give split_view::_Sentinel a default ctor [PR101214]
  2021-07-13 18:04 [PATCH] libstdc++: Give split_view::_Sentinel a default ctor [PR101214] Patrick Palka
@ 2021-07-15 20:01 ` Jonathan Wakely
  0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Wakely @ 2021-07-15 20:01 UTC (permalink / raw)
  To: Patrick Palka; +Cc: gcc-patches, libstdc++

On Tue, 13 Jul 2021 at 19:05, Patrick Palka via Libstdc++
<libstdc++@gcc.gnu.org> wrote:
>
> 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?

Yes, thanks.

>
>         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
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] libstdc++: Give split_view::_Sentinel a default ctor [PR101214]
@ 2021-07-13 19:05 Patrick Palka
  0 siblings, 0 replies; 3+ messages in thread
From: Patrick Palka @ 2021-07-13 19:05 UTC (permalink / raw)
  To: gcc-patches; +Cc: libstdc++, Patrick Palka

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-07-15 20:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-13 18:04 [PATCH] libstdc++: Give split_view::_Sentinel a default ctor [PR101214] Patrick Palka
2021-07-15 20:01 ` Jonathan Wakely
2021-07-13 19:05 Patrick Palka

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).