From 019dfa0b3337ba4c14f232c308a741e409a68985 Mon Sep 17 00:00:00 2001 From: Casey Carter Date: Thu, 16 Dec 2021 21:18:17 -0800 Subject: [PATCH 1/2] Update counted_iterator's "same sequence" definition Per LWG-3543. (This is _almost_ a pure non-functional change, but I added a word to the error message we emit on failure.) Fixes #2184 --- stl/inc/iterator | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/stl/inc/iterator b/stl/inc/iterator index 0ce96d9bfdd..bedd9065a40 100644 --- a/stl/inc/iterator +++ b/stl/inc/iterator @@ -1305,9 +1305,9 @@ public: template _Other> friend constexpr void _Same_sequence( const counted_iterator& _Left, const counted_iterator<_Other>& _Right) noexcept { - // Per N4861 [counted.iterator]/2, two counted_iterators x and y refer to elements of the same sequence iff - // next(x.base(), x.count()) and next(y.base(), y.count()) "refer to the same element." Iterator equality is a - // fair proxy for this condition. + // Per N4901 [counted.iterator]/3, two counted_iterators x and y refer to elements of the same sequence iff + // for some integer n, next(x.base(), x.count() + n) and next(y.base(), y.count() + n) "refer to the same + // element." Iterator equality is a fair proxy for the vaguely-defined "refer to the same element". if constexpr (forward_iterator<_Iter> && forward_iterator<_Other>) { using _CIter = common_type_t<_Iter, _Other>; using _CDiff = common_type_t, iter_difference_t<_Other>>; @@ -1316,11 +1316,11 @@ public: if (_Diff < 0) { _STL_VERIFY( static_cast<_CIter>(_Left._Current) == _RANGES next(static_cast<_CIter>(_Right.base()), -_Diff), - "counted_iterators from different ranges"); + "counted_iterators are from different ranges"); } else { _STL_VERIFY( _RANGES next(static_cast<_CIter>(_Left._Current), _Diff) == static_cast<_CIter>(_Right.base()), - "counted_iterators from different ranges"); + "counted_iterators are from different ranges"); } } } From 92f8f52bccd0281cd55d0e1598cec5b075ef1707 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Fri, 17 Dec 2021 19:17:13 -0800 Subject: [PATCH 2/2] Exactly quote the Standard. --- stl/inc/iterator | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/stl/inc/iterator b/stl/inc/iterator index bedd9065a40..c7c1c6baecf 100644 --- a/stl/inc/iterator +++ b/stl/inc/iterator @@ -1306,8 +1306,9 @@ public: friend constexpr void _Same_sequence( const counted_iterator& _Left, const counted_iterator<_Other>& _Right) noexcept { // Per N4901 [counted.iterator]/3, two counted_iterators x and y refer to elements of the same sequence iff - // for some integer n, next(x.base(), x.count() + n) and next(y.base(), y.count() + n) "refer to the same - // element." Iterator equality is a fair proxy for the vaguely-defined "refer to the same element". + // for some integer n, next(x.base(), x.count() + n) and next(y.base(), y.count() + n) + // "refer to the same (possibly past-the-end) element". + // Iterator equality is a fair proxy for the vaguely-defined "refer to the same element". if constexpr (forward_iterator<_Iter> && forward_iterator<_Other>) { using _CIter = common_type_t<_Iter, _Other>; using _CDiff = common_type_t, iter_difference_t<_Other>>;