From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1888) id 85C183858C98; Wed, 17 Jan 2024 02:21:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 85C183858C98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1705458097; bh=lBfflAjgY5DXkehl368z2KyMCSv1KGSUQinmqwrkULY=; h=From:To:Subject:Date:From; b=P6MlzespKNBgdRb+VfyuSZx7fzxPcYfrFhOWp7Nq3W+GvcDXFx4C8pm4i8A6RCNdg R92oXr2wcDdf3m/7EIcfDKt/B2wuL9LxQXGNr2KDArIMxv1vCJFHVOY/HRlNskz910 BBx2QfBEbeeCmO+u9QZ4zjoC39r4eS2kl2+2PZBk= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Patrick Palka To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r14-8170] libstdc++: Implement P2540R1 change to views::cartesian_product() X-Act-Checkin: gcc X-Git-Author: Patrick Palka X-Git-Refname: refs/heads/master X-Git-Oldrev: 1a17797496f72982c1c802725704a9aaf01218b5 X-Git-Newrev: 98966f32f906303cd7d2e1c418f320c483e6dcbe Message-Id: <20240117022137.85C183858C98@sourceware.org> Date: Wed, 17 Jan 2024 02:21:37 +0000 (GMT) List-Id: https://gcc.gnu.org/g:98966f32f906303cd7d2e1c418f320c483e6dcbe commit r14-8170-g98966f32f906303cd7d2e1c418f320c483e6dcbe Author: Patrick Palka Date: Tue Jan 16 21:20:12 2024 -0500 libstdc++: Implement P2540R1 change to views::cartesian_product() This paper changes the identity element of views::cartesian_product to a singleton range instead of an empty range. It was approved alongside the main cartesian_product paper P2374R4, but unfortunately was overlooked when implementing the main paper. 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. Reviewed-by: Jonathan Wakely Diff: --- 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>; + return views::single(tuple{}); else return cartesian_product_view...>(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 );