aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3
diff options
context:
space:
mode:
authorPatrick Palka <ppalka@redhat.com>2020-10-12 13:46:21 -0400
committerPatrick Palka <ppalka@redhat.com>2020-10-12 13:46:21 -0400
commite066821b6f6b7332c7a67981f7b33c9ba0ccaee7 (patch)
treec5da81796b6a0a0069e3440a760abea0ed6e690b /libstdc++-v3
parentc840700852c69b2bf7a73df77d8d9f0658330dae (diff)
downloadgcc-e066821b6f6b7332c7a67981f7b33c9ba0ccaee7.zip
gcc-e066821b6f6b7332c7a67981f7b33c9ba0ccaee7.tar.gz
gcc-e066821b6f6b7332c7a67981f7b33c9ba0ccaee7.tar.bz2
libstdc++: Apply proposed resolution for LWG 3449 [PR95322]
Now that the frontend bug PR96805 is fixed, we can cleanly apply the proposed resolution for this issue. This slightly deviates from the proposed resolution by declaring _CI a member of take_view instead of take_view::_Sentinel, since it doesn't depend on anything within _Sentinel anymore. libstdc++-v3/ChangeLog: PR libstdc++/95322 * include/std/ranges (take_view::_CI): Define this alias template as per LWG 3449 and remove ... (take_view::_Sentinel::_CI): ... this type alias. (take_view::_Sentinel::operator==): Adjust use of _CI accordingly. Define a second overload that accepts an iterator of the opposite constness as per LWG 3449. (take_while_view::_Sentinel::operator==): Likewise. * testsuite/std/ranges/adaptors/95322.cc: Add tests for LWG 3449.
Diffstat (limited to 'libstdc++-v3')
-rw-r--r--libstdc++-v3/include/std/ranges23
-rw-r--r--libstdc++-v3/testsuite/std/ranges/adaptors/95322.cc28
2 files changed, 47 insertions, 4 deletions
diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges
index 10f1f7b..19bc01a 100644
--- a/libstdc++-v3/include/std/ranges
+++ b/libstdc++-v3/include/std/ranges
@@ -1663,12 +1663,14 @@ namespace views
{
private:
template<bool _Const>
+ using _CI = counted_iterator<
+ iterator_t<__detail::__maybe_const_t<_Const, _Vp>>>;
+
+ template<bool _Const>
struct _Sentinel
{
private:
using _Base = __detail::__maybe_const_t<_Const, _Vp>;
- using _CI = counted_iterator<iterator_t<_Base>>;
-
sentinel_t<_Base> _M_end = sentinel_t<_Base>();
public:
@@ -1689,7 +1691,15 @@ namespace views
base() const
{ return _M_end; }
- friend constexpr bool operator==(const _CI& __y, const _Sentinel& __x)
+ friend constexpr bool
+ operator==(const _CI<_Const>& __y, const _Sentinel& __x)
+ { return __y.count() == 0 || __y.base() == __x._M_end; }
+
+ template<bool _OtherConst = !_Const,
+ typename _Base2 = __detail::__maybe_const_t<_OtherConst, _Vp>>
+ requires sentinel_for<sentinel_t<_Base>, iterator_t<_Base2>>
+ friend constexpr bool
+ operator==(const _CI<_OtherConst>& __y, const _Sentinel& __x)
{ return __y.count() == 0 || __y.base() == __x._M_end; }
friend _Sentinel<!_Const>;
@@ -1839,6 +1849,13 @@ namespace views
operator==(const iterator_t<_Base>& __x, const _Sentinel& __y)
{ return __y._M_end == __x || !std::__invoke(*__y._M_pred, *__x); }
+ template<bool _OtherConst = !_Const,
+ typename _Base2 = __detail::__maybe_const_t<_OtherConst, _Vp>>
+ requires sentinel_for<sentinel_t<_Base>, iterator_t<_Base2>>
+ friend constexpr bool
+ operator==(const iterator_t<_Base2>& __x, const _Sentinel& __y)
+ { return __y._M_end == __x || !std::__invoke(*__y._M_pred, *__x); }
+
friend _Sentinel<!_Const>;
};
diff --git a/libstdc++-v3/testsuite/std/ranges/adaptors/95322.cc b/libstdc++-v3/testsuite/std/ranges/adaptors/95322.cc
index 67bc7d3..41785a0 100644
--- a/libstdc++-v3/testsuite/std/ranges/adaptors/95322.cc
+++ b/libstdc++-v3/testsuite/std/ranges/adaptors/95322.cc
@@ -26,7 +26,7 @@ using __gnu_test::test_forward_range;
void
test01()
{
- // PR libstdc++/95322 and LWG 3488
+ // PR libstdc++/95322 and LWG 3448
int a[2]{1, 2};
test_forward_range<int> v{a};
auto view1 = v | std::views::take(2);
@@ -51,8 +51,34 @@ test02()
VERIFY( !eq );
}
+void
+test03()
+{
+ // LWG 3449, for take_view
+ int a[2]{1, 2};
+ test_forward_range<int> v{a};
+ auto view1 = v | std::views::transform(std::identity{});
+ auto view2 = view1 | std::views::take(2);
+ const bool eq = std::ranges::cbegin(view2) == std::ranges::end(view2);
+ VERIFY( !eq );
+}
+
+void
+test04()
+{
+ // LWG 3449, for take_while_view
+ int a[2]{1, 2};
+ test_forward_range<int> v{a};
+ auto view1 = v | std::views::transform(std::identity{});
+ auto view2 = view1 | std::views::take_while([] (int i) { return true; });
+ const bool eq = std::ranges::cbegin(view2) == std::ranges::end(view2);
+ VERIFY( !eq );
+}
+
int main()
{
test01();
test02();
+ test03();
+ test04();
}