diff options
author | Patrick Palka <ppalka@redhat.com> | 2020-08-26 21:52:58 -0400 |
---|---|---|
committer | Patrick Palka <ppalka@redhat.com> | 2020-08-26 21:52:58 -0400 |
commit | 4be16d1c1cfa6d151d2853ce509c1a797189c9ad (patch) | |
tree | eddddfb14e9806e18e739b3618ae1132705fa1e1 /libstdc++-v3/include/std | |
parent | 97ab5daa6c1186d3b10872cc1d5b05da247d102c (diff) | |
download | gcc-4be16d1c1cfa6d151d2853ce509c1a797189c9ad.zip gcc-4be16d1c1cfa6d151d2853ce509c1a797189c9ad.tar.gz gcc-4be16d1c1cfa6d151d2853ce509c1a797189c9ad.tar.bz2 |
libstdc++: elements_view's sentinel and iterator not comparable [LWG 3406]
This implements the proposed resolution for LWG 3406, and adds a
testcase for the example from P1994R1.
libstdc++-v3/ChangeLog:
* include/std/ranges (elements_view::begin): Adjust constraints.
(elements_view::end): Likewise.
(elements_view::_Sentinel::operator==): Templatize to take both
_Iterator<true> and _Iterator<false>.
(elements_view::_Sentinel::operator-): Likewise.
* testsuite/std/ranges/adaptors/elements.cc: Add testcase for
the example from P1994R1.
* testsuite/std/ranges/adaptors/lwg3406.cc: New test.
Diffstat (limited to 'libstdc++-v3/include/std')
-rw-r--r-- | libstdc++-v3/include/std/ranges | 39 |
1 files changed, 23 insertions, 16 deletions
diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges index efa8d2c..4202835 100644 --- a/libstdc++-v3/include/std/ranges +++ b/libstdc++-v3/include/std/ranges @@ -3362,15 +3362,15 @@ namespace views { return _Iterator<false>(ranges::begin(_M_base)); } constexpr auto - begin() const requires __detail::__simple_view<_Vp> + begin() const requires range<const _Vp> { return _Iterator<true>(ranges::begin(_M_base)); } constexpr auto - end() + end() requires (!__detail::__simple_view<_Vp> && !common_range<_Vp>) { return _Sentinel<false>{ranges::end(_M_base)}; } constexpr auto - end() requires common_range<_Vp> + end() requires (!__detail::__simple_view<_Vp> && common_range<_Vp>) { return _Iterator<false>{ranges::end(_M_base)}; } constexpr auto @@ -3576,19 +3576,26 @@ namespace views base() const { return _M_end; } - friend constexpr bool - operator==(const _Iterator<_Const>& __x, const _Sentinel& __y) - { return __y._M_equal(__x); } - - friend constexpr range_difference_t<_Base> - operator-(const _Iterator<_Const>& __x, const _Sentinel& __y) - requires sized_sentinel_for<sentinel_t<_Base>, iterator_t<_Base>> - { return __x._M_current - __y._M_end; } - - friend constexpr range_difference_t<_Base> - operator-(const _Sentinel& __x, const _Iterator<_Const>& __y) - requires sized_sentinel_for<sentinel_t<_Base>, iterator_t<_Base>> - { return __x._M_end - __y._M_current; } + template<bool _Const2> + requires sentinel_for<sentinel_t<_Base>, + iterator_t<__detail::__maybe_const_t<_Const2, _Vp>>> + friend constexpr bool + operator==(const _Iterator<_Const2>& __x, const _Sentinel& __y) + { return __y._M_equal(__x); } + + 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 __x._M_current - __y._M_end; } + + 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<_Base> + operator-(const _Sentinel& __x, const _Iterator<_Const2>& __y) + { return __x._M_end - __y._M_current; } friend _Sentinel<!_Const>; }; |