]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Implement P2540R1 change to views::cartesian_product()
authorPatrick Palka <ppalka@redhat.com>
Wed, 17 Jan 2024 02:20:12 +0000 (21:20 -0500)
committerPatrick Palka <ppalka@redhat.com>
Wed, 17 Jan 2024 02:20:12 +0000 (21:20 -0500)
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 <jwakely@redhat.com>
libstdc++-v3/include/std/ranges
libstdc++-v3/testsuite/std/ranges/cartesian_product/1.cc

index 3135e6f0c0800a3269e550434844fca029bc7d7b..7ef835f486a7073fea234353e0be0d64561df0e6 100644 (file)
@@ -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)...);
        }
index f69f965c0ce3cb12ca38a392f147e6ad38142154..7281cd8a2f4999b48f86f9f2adc2db79b97bf109 100644 (file)
@@ -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 );