* [PATCH] libstdc++: Implement P2540R1 change to views::cartesian_product()
@ 2024-01-16 14:38 Patrick Palka
2024-01-16 14:41 ` Jonathan Wakely
0 siblings, 1 reply; 3+ messages in thread
From: Patrick Palka @ 2024-01-16 14:38 UTC (permalink / raw)
To: gcc-patches; +Cc: libstdc++, Patrick Palka
Tested on x86_64-pc-linux-gnu, does this look OK for trunk/13?
-- >8 --
This paper changes the identity element of views::cartesian_product to
be a single empty tuple instead of an empty range.
libstdc++-v3/ChangeLog:
* include/std/ranges (views::_CartesianProduct::operator()):
Adjust identity case as per P2540R1.
* testsuite/std/ranges/cartesian_product/1.cc (test01):
Adjust expected result of the identity case.
---
libstdc++-v3/include/std/ranges | 2 +-
libstdc++-v3/testsuite/std/ranges/cartesian_product/1.cc | 6 +++---
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges
index 3135e6f0c08..7ef835f486a 100644
--- a/libstdc++-v3/include/std/ranges
+++ b/libstdc++-v3/include/std/ranges
@@ -8748,7 +8748,7 @@ namespace views::__adaptor
operator() [[nodiscard]] (_Ts&&... __ts) const
{
if constexpr (sizeof...(_Ts) == 0)
- return views::empty<tuple<>>;
+ return views::single(tuple{});
else
return cartesian_product_view<all_t<_Ts>...>(std::forward<_Ts>(__ts)...);
}
diff --git a/libstdc++-v3/testsuite/std/ranges/cartesian_product/1.cc b/libstdc++-v3/testsuite/std/ranges/cartesian_product/1.cc
index f69f965c0ce..7281cd8a2f4 100644
--- a/libstdc++-v3/testsuite/std/ranges/cartesian_product/1.cc
+++ b/libstdc++-v3/testsuite/std/ranges/cartesian_product/1.cc
@@ -24,9 +24,9 @@ test01()
int w[] = {9};
auto v0 = views::cartesian_product();
- VERIFY( ranges::end(v0) - ranges::begin(v0) == 0 );
- VERIFY( ranges::size(v0) == 0 );
- VERIFY( ranges::empty(v0) );
+ VERIFY( ranges::end(v0) - ranges::begin(v0) == 1 );
+ VERIFY( ranges::size(v0) == 1 );
+ VERIFY( !ranges::empty(v0) );
auto v1 = views::cartesian_product(x);
VERIFY( ranges::end(v1) - ranges::begin(v1) == 3 );
--
2.43.0.334.gd4dbce1db5
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] libstdc++: Implement P2540R1 change to views::cartesian_product()
2024-01-16 14:38 [PATCH] libstdc++: Implement P2540R1 change to views::cartesian_product() Patrick Palka
@ 2024-01-16 14:41 ` Jonathan Wakely
2024-01-16 14:49 ` Patrick Palka
0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Wakely @ 2024-01-16 14:41 UTC (permalink / raw)
To: Patrick Palka; +Cc: gcc-patches, libstdc++
On Tue, 16 Jan 2024 at 14:39, Patrick Palka wrote:
>
> Tested on x86_64-pc-linux-gnu, does this look OK for trunk/13?
Oh! I thought this went in as part of the original cartesian_product
commit. I would have asked you to do it at the same time otherwise,
sorry.
Yes, OK for trunk and gcc-13, thanks.
>
> -- >8 --
>
> This paper changes the identity element of views::cartesian_product to
> be a single empty tuple instead of an empty range.
>
> libstdc++-v3/ChangeLog:
>
> * include/std/ranges (views::_CartesianProduct::operator()):
> Adjust identity case as per P2540R1.
> * testsuite/std/ranges/cartesian_product/1.cc (test01):
> Adjust expected result of the identity case.
> ---
> libstdc++-v3/include/std/ranges | 2 +-
> libstdc++-v3/testsuite/std/ranges/cartesian_product/1.cc | 6 +++---
> 2 files changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges
> index 3135e6f0c08..7ef835f486a 100644
> --- a/libstdc++-v3/include/std/ranges
> +++ b/libstdc++-v3/include/std/ranges
> @@ -8748,7 +8748,7 @@ namespace views::__adaptor
> operator() [[nodiscard]] (_Ts&&... __ts) const
> {
> if constexpr (sizeof...(_Ts) == 0)
> - return views::empty<tuple<>>;
> + return views::single(tuple{});
> else
> return cartesian_product_view<all_t<_Ts>...>(std::forward<_Ts>(__ts)...);
> }
> diff --git a/libstdc++-v3/testsuite/std/ranges/cartesian_product/1.cc b/libstdc++-v3/testsuite/std/ranges/cartesian_product/1.cc
> index f69f965c0ce..7281cd8a2f4 100644
> --- a/libstdc++-v3/testsuite/std/ranges/cartesian_product/1.cc
> +++ b/libstdc++-v3/testsuite/std/ranges/cartesian_product/1.cc
> @@ -24,9 +24,9 @@ test01()
> int w[] = {9};
>
> auto v0 = views::cartesian_product();
> - VERIFY( ranges::end(v0) - ranges::begin(v0) == 0 );
> - VERIFY( ranges::size(v0) == 0 );
> - VERIFY( ranges::empty(v0) );
> + VERIFY( ranges::end(v0) - ranges::begin(v0) == 1 );
> + VERIFY( ranges::size(v0) == 1 );
> + VERIFY( !ranges::empty(v0) );
>
> auto v1 = views::cartesian_product(x);
> VERIFY( ranges::end(v1) - ranges::begin(v1) == 3 );
> --
> 2.43.0.334.gd4dbce1db5
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] libstdc++: Implement P2540R1 change to views::cartesian_product()
2024-01-16 14:41 ` Jonathan Wakely
@ 2024-01-16 14:49 ` Patrick Palka
0 siblings, 0 replies; 3+ messages in thread
From: Patrick Palka @ 2024-01-16 14:49 UTC (permalink / raw)
To: Jonathan Wakely; +Cc: Patrick Palka, gcc-patches, libstdc++
On Tue, 16 Jan 2024, Jonathan Wakely wrote:
> On Tue, 16 Jan 2024 at 14:39, Patrick Palka wrote:
> >
> > Tested on x86_64-pc-linux-gnu, does this look OK for trunk/13?
>
> Oh! I thought this went in as part of the original cartesian_product
> commit. I would have asked you to do it at the same time otherwise,
> sorry.
>
> Yes, OK for trunk and gcc-13, thanks.
Thanks, and sorry for letting this slip through the cracks. I made
sure to include relevant LWG issue resolutions as part of the original
commit, but I managed to miss this paper.
>
>
> >
> > -- >8 --
> >
> > This paper changes the identity element of views::cartesian_product to
> > be a single empty tuple instead of an empty range.
> >
> > libstdc++-v3/ChangeLog:
> >
> > * include/std/ranges (views::_CartesianProduct::operator()):
> > Adjust identity case as per P2540R1.
> > * testsuite/std/ranges/cartesian_product/1.cc (test01):
> > Adjust expected result of the identity case.
> > ---
> > libstdc++-v3/include/std/ranges | 2 +-
> > libstdc++-v3/testsuite/std/ranges/cartesian_product/1.cc | 6 +++---
> > 2 files changed, 4 insertions(+), 4 deletions(-)
> >
> > diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges
> > index 3135e6f0c08..7ef835f486a 100644
> > --- a/libstdc++-v3/include/std/ranges
> > +++ b/libstdc++-v3/include/std/ranges
> > @@ -8748,7 +8748,7 @@ namespace views::__adaptor
> > operator() [[nodiscard]] (_Ts&&... __ts) const
> > {
> > if constexpr (sizeof...(_Ts) == 0)
> > - return views::empty<tuple<>>;
> > + return views::single(tuple{});
> > else
> > return cartesian_product_view<all_t<_Ts>...>(std::forward<_Ts>(__ts)...);
> > }
> > diff --git a/libstdc++-v3/testsuite/std/ranges/cartesian_product/1.cc b/libstdc++-v3/testsuite/std/ranges/cartesian_product/1.cc
> > index f69f965c0ce..7281cd8a2f4 100644
> > --- a/libstdc++-v3/testsuite/std/ranges/cartesian_product/1.cc
> > +++ b/libstdc++-v3/testsuite/std/ranges/cartesian_product/1.cc
> > @@ -24,9 +24,9 @@ test01()
> > int w[] = {9};
> >
> > auto v0 = views::cartesian_product();
> > - VERIFY( ranges::end(v0) - ranges::begin(v0) == 0 );
> > - VERIFY( ranges::size(v0) == 0 );
> > - VERIFY( ranges::empty(v0) );
> > + VERIFY( ranges::end(v0) - ranges::begin(v0) == 1 );
> > + VERIFY( ranges::size(v0) == 1 );
> > + VERIFY( !ranges::empty(v0) );
> >
> > auto v1 = views::cartesian_product(x);
> > VERIFY( ranges::end(v1) - ranges::begin(v1) == 3 );
> > --
> > 2.43.0.334.gd4dbce1db5
> >
>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-01-16 14:49 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-16 14:38 [PATCH] libstdc++: Implement P2540R1 change to views::cartesian_product() Patrick Palka
2024-01-16 14:41 ` Jonathan Wakely
2024-01-16 14:49 ` 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).