]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Implement remaining piece of LWG 3448
authorPatrick Palka <ppalka@redhat.com>
Thu, 27 Aug 2020 01:51:48 +0000 (21:51 -0400)
committerPatrick Palka <ppalka@redhat.com>
Wed, 21 Oct 2020 01:55:52 +0000 (21:55 -0400)
Almost all of the proposed resolution for LWG 3448 is already
implemented; the only part left is to adjust the return type of
transform_view::sentinel::operator-.

libstdc++-v3/ChangeLog:

PR libstdc++/95322
* include/std/ranges (transform_view::sentinel::__distance_from):
Give this a deduced return type.
(transform_view::sentinel::operator-): Adjust the return type so
that it's based on the constness of the iterator rather than
that of the sentinel.
* testsuite/std/ranges/adaptors/95322.cc: Refer to LWG 3488.

(cherry picked from commit 3ae0cd94abc15e33dc06ca7a5f76f14b1d74129f)

libstdc++-v3/include/std/ranges
libstdc++-v3/testsuite/std/ranges/adaptors/95322.cc

index 41f35d1d1083f6e9ca5bcdcc8c3e6d08723d5dd9..98aa0d6a7c8665d7d8d1320dddf68440365255bd 100644 (file)
@@ -1864,7 +1864,7 @@ namespace views
          using _Base = __detail::__maybe_const_t<_Const, _Vp>;
 
          template<bool _Const2>
-           constexpr range_difference_t<_Base>
+           constexpr auto
            __distance_from(const _Iterator<_Const2>& __i) const
            { return _M_end - __i._M_current; }
 
@@ -1901,17 +1901,17 @@ namespace views
            operator==(const _Iterator<_Const2>& __x, const _Sentinel& __y)
            { return __y.__equal(__x); }
 
-         template<bool _Const2>
-           requires sized_sentinel_for<sentinel_t<_Base>,
-                      iterator_t<__detail::__maybe_const_t<_Const2, _Vp>>>
-           friend constexpr range_difference_t<_Base>
+         template<bool _Const2,
+                  typename _Base2 = __detail::__maybe_const_t<_Const2, _Vp>>
+           requires sized_sentinel_for<sentinel_t<_Base>, iterator_t<_Base2>>
+           friend constexpr range_difference_t<_Base2>
            operator-(const _Iterator<_Const2>& __x, const _Sentinel& __y)
            { return -__y.__distance_from(__x); }
 
-         template<bool _Const2>
-           requires sized_sentinel_for<sentinel_t<_Base>,
-                      iterator_t<__detail::__maybe_const_t<_Const2, _Vp>>>
-           friend constexpr range_difference_t<_Base>
+         template<bool _Const2,
+                  typename _Base2 = __detail::__maybe_const_t<_Const2, _Vp>>
+           requires sized_sentinel_for<sentinel_t<_Base>, iterator_t<_Base2>>
+           friend constexpr range_difference_t<_Base2>
            operator-(const _Sentinel& __y, const _Iterator<_Const2>& __x)
            { return __y.__distance_from(__x); }
 
index 9279d5520a870b85ebfca8371975bcacb8038959..67bc7d33917bac840fb54c06c9718d61d49ef003 100644 (file)
@@ -26,7 +26,7 @@ using __gnu_test::test_forward_range;
 void
 test01()
 {
-  // PR libstdc++/95322
+  // PR libstdc++/95322 and LWG 3488
   int a[2]{1, 2};
   test_forward_range<int> v{a};
   auto view1 = v | std::views::take(2);