Skip to content

Commit

Permalink
<ranges>: Make views ADL-proof (#4389)
Browse files Browse the repository at this point in the history
Co-authored-by: Stephan T. Lavavej <stl@nuwen.net>
  • Loading branch information
frederick-vs-ja and StephanTLavavej authored Feb 16, 2024
1 parent 2f6e7f8 commit c74507c
Show file tree
Hide file tree
Showing 4 changed files with 573 additions and 43 deletions.
87 changes: 44 additions & 43 deletions stl/inc/ranges
Original file line number Diff line number Diff line change
Expand Up @@ -2215,9 +2215,9 @@ namespace ranges {
is_nothrow_move_constructible_v<iterator_t<_Vw>>) // strengthened
: _Current(_STD move(_Current_)), _Parent{_STD addressof(_Parent_)} {
#if _ITERATOR_DEBUG_LEVEL != 0
_Adl_verify_range(_Current, _RANGES end(_Parent_._Range));
_STD _Adl_verify_range(_Current, _RANGES end(_Parent_._Range));
if constexpr (forward_range<_Vw>) {
_Adl_verify_range(_RANGES begin(_Parent_._Range), _Current);
_STD _Adl_verify_range(_RANGES begin(_Parent_._Range), _Current);
}
#endif // _ITERATOR_DEBUG_LEVEL != 0
}
Expand Down Expand Up @@ -2322,7 +2322,7 @@ namespace ranges {
}

_NODISCARD constexpr bool _Equal(const sentinel_t<_Vw>& _Last) const
noexcept(noexcept(_Fake_copy_init<bool>(_Current == _Last))) {
noexcept(noexcept(_STD _Fake_copy_init<bool>(_Current == _Last))) {
return _Current == _Last;
}
};
Expand Down Expand Up @@ -2492,9 +2492,9 @@ namespace ranges {
is_nothrow_move_constructible_v<iterator_t<_Base>>) // strengthened
: _Current{_STD move(_Current_)}, _Parent{_STD addressof(_Parent_)} {
#if _ITERATOR_DEBUG_LEVEL != 0
_Adl_verify_range(_Current, _RANGES end(_Parent_._Range));
_STD _Adl_verify_range(_Current, _RANGES end(_Parent_._Range));
if constexpr (forward_range<_Base>) {
_Adl_verify_range(_RANGES begin(_Parent_._Range), _Current);
_STD _Adl_verify_range(_RANGES begin(_Parent_._Range), _Current);
}
#endif // _ITERATOR_DEBUG_LEVEL != 0
}
Expand Down Expand Up @@ -3750,8 +3750,8 @@ namespace ranges {
requires forward_range<_Base>
: _Mybase{_STD move(_Outer_)}, _Parent{_STD addressof(_Parent_)} {
#if _ITERATOR_DEBUG_LEVEL != 0
_Adl_verify_range(this->_Outer, _RANGES end(_Parent_._Range));
_Adl_verify_range(_RANGES begin(_Parent_._Range), this->_Outer);
_STD _Adl_verify_range(this->_Outer, _RANGES end(_Parent_._Range));
_STD _Adl_verify_range(_RANGES begin(_Parent_._Range), this->_Outer);
#endif // _ITERATOR_DEBUG_LEVEL != 0
_Satisfy();
}
Expand Down Expand Up @@ -3807,7 +3807,7 @@ namespace ranges {
_STL_VERIFY(_Get_outer() != _RANGES end(_Parent->_Range), "cannot dereference join_view end iterator");
sentinel_t<_InnerRng<_Const>> _Last;
if constexpr (_Deref_is_glvalue) {
_Last = _RANGES end(_As_lvalue(*_Get_outer()));
_Last = _RANGES end(_RANGES _As_lvalue(*_Get_outer()));
} else {
_Last = _RANGES end((*_Parent->_Inner)._Val);
}
Expand Down Expand Up @@ -3856,7 +3856,7 @@ namespace ranges {
constexpr _Iterator& operator++() {
auto& _Outer = _Get_outer();
if constexpr (_Deref_is_glvalue) {
if (++*_Inner == _RANGES end(_As_lvalue(*_Outer))) {
if (++*_Inner == _RANGES end(_RANGES _As_lvalue(*_Outer))) {
++_Outer;
_Satisfy();
}
Expand Down Expand Up @@ -3886,11 +3886,11 @@ namespace ranges {
auto& _Outer = _Get_outer();
if (_Outer == _RANGES end(_Parent->_Range)) {
--_Outer;
_Inner = _RANGES end(_As_lvalue(*_Outer));
_Inner = _RANGES end(_RANGES _As_lvalue(*_Outer));
}
while (*_Inner == _RANGES begin(_As_lvalue(*_Outer))) {
while (*_Inner == _RANGES begin(_RANGES _As_lvalue(*_Outer))) {
--_Outer;
*_Inner = _RANGES end(_As_lvalue(*_Outer));
*_Inner = _RANGES end(_RANGES _As_lvalue(*_Outer));
}
--*_Inner;
return *this;
Expand Down Expand Up @@ -3952,7 +3952,7 @@ namespace ranges {
template <bool _OtherConst>
requires sentinel_for<sentinel_t<_Base>, _Maybe_const_iter<_OtherConst>>
_NODISCARD constexpr bool _Equal(const _Iterator<_OtherConst>& _It) const
noexcept(noexcept(_Fake_copy_init<bool>(_It._Get_outer() == _Last))) {
noexcept(noexcept(_STD _Fake_copy_init<bool>(_It._Get_outer() == _Last))) {
return _It._Get_outer() == _Last;
}

Expand Down Expand Up @@ -4219,15 +4219,15 @@ namespace ranges {

_NODISCARD constexpr auto& _Update_inner() {
if constexpr (_Deref_is_glvalue) {
return _As_lvalue(*_Get_outer());
return _RANGES _As_lvalue(*_Get_outer());
} else {
return _Parent->_Inner._Emplace(_Construct_tag{}, _Get_outer())._Val;
}
}

_NODISCARD constexpr auto& _Get_inner() noexcept {
if constexpr (_Deref_is_glvalue) {
return _As_lvalue(*_Get_outer());
return _RANGES _As_lvalue(*_Get_outer());
} else {
return (*_Parent->_Inner)._Val;
}
Expand Down Expand Up @@ -4465,7 +4465,7 @@ namespace ranges {

template <bool _OtherConst>
_NODISCARD constexpr bool _Equal(const _Iterator<_OtherConst>& _It) const
noexcept(noexcept(_Fake_copy_init<bool>(_It._Get_outer() == _Last))) {
noexcept(noexcept(_STD _Fake_copy_init<bool>(_It._Get_outer() == _Last))) {
_STL_INTERNAL_STATIC_ASSERT(
sentinel_for<sentinel_t<_Base>, iterator_t<_Maybe_const<_OtherConst, _Vw>>>);
return _It._Get_outer() == _Last;
Expand Down Expand Up @@ -4691,7 +4691,7 @@ namespace ranges {
}

_NODISCARD constexpr bool _At_end() const
noexcept(noexcept(_Fake_copy_init<bool>(_Get_current() == _RANGES end(_Parent->_Range)))) {
noexcept(noexcept(_STD _Fake_copy_init<bool>(_Get_current() == _RANGES end(_Parent->_Range)))) {
return _Get_current() == _RANGES end(_Parent->_Range);
}

Expand Down Expand Up @@ -5111,7 +5111,7 @@ namespace ranges {
/* [[no_unique_address]] */ sentinel_t<_Vw> _Last{};

_NODISCARD constexpr bool _Equal(const _Iterator& _It) const
noexcept(noexcept(_Fake_copy_init<bool>(_It._Current == _Last))) {
noexcept(noexcept(_STD _Fake_copy_init<bool>(_It._Current == _Last))) {
return !_It._Trailing_empty && _It._Current == _Last;
}

Expand Down Expand Up @@ -6304,7 +6304,7 @@ namespace ranges {
template <bool _OtherConst>
requires sentinel_for<_Base_sentinel, iterator_t<_Maybe_const<_OtherConst, _Vw>>>
_NODISCARD constexpr bool _Equal(const _Iterator<_OtherConst>& _It) const
noexcept(noexcept(_Fake_copy_init<bool>(_It._Current == _End))) {
noexcept(noexcept(_STD _Fake_copy_init<bool>(_It._Current == _End))) {
return _It._Current == _End;
}

Expand Down Expand Up @@ -6848,38 +6848,38 @@ namespace ranges {
}

_NODISCARD_FRIEND constexpr bool operator==(const _Iterator& _Left, const _Iterator& _Right) noexcept(
noexcept(_Fake_copy_init<bool>(_Left._Current == _Right._Current))) /* strengthened */ {
noexcept(_STD _Fake_copy_init<bool>(_Left._Current == _Right._Current))) /* strengthened */ {
return _Left._Current == _Right._Current;
}

_NODISCARD_FRIEND constexpr bool operator==(const _Iterator& _Left, default_sentinel_t) noexcept(
noexcept(_Fake_copy_init<bool>(_Left._Current == _Left._End))) /* strengthened */ {
noexcept(_STD _Fake_copy_init<bool>(_Left._Current == _Left._End))) /* strengthened */ {
return _Left._Current == _Left._End;
}

_NODISCARD_FRIEND constexpr bool operator<(const _Iterator& _Left, const _Iterator& _Right) noexcept(
noexcept(_Fake_copy_init<bool>(_Left._Current < _Right._Current))) /* strengthened */
noexcept(_STD _Fake_copy_init<bool>(_Left._Current < _Right._Current))) /* strengthened */
requires random_access_range<_Base>
{
return _Left._Current < _Right._Current;
}

_NODISCARD_FRIEND constexpr bool operator>(const _Iterator& _Left, const _Iterator& _Right) noexcept(
noexcept(_Fake_copy_init<bool>(_Right._Current < _Left._Current))) /* strengthened */
noexcept(_STD _Fake_copy_init<bool>(_Right._Current < _Left._Current))) /* strengthened */
requires random_access_range<_Base>
{
return _Right._Current < _Left._Current;
}

_NODISCARD_FRIEND constexpr bool operator<=(const _Iterator& _Left, const _Iterator& _Right) noexcept(
noexcept(_Fake_copy_init<bool>(!(_Right._Current < _Left._Current)))) /* strengthened */
noexcept(_STD _Fake_copy_init<bool>(!(_Right._Current < _Left._Current)))) /* strengthened */
requires random_access_range<_Base>
{
return !(_Right._Current < _Left._Current);
}

_NODISCARD_FRIEND constexpr bool operator>=(const _Iterator& _Left, const _Iterator& _Right) noexcept(
noexcept(_Fake_copy_init<bool>(!(_Left._Current < _Right._Current)))) /* strengthened */
noexcept(_STD _Fake_copy_init<bool>(!(_Left._Current < _Right._Current)))) /* strengthened */
requires random_access_range<_Base>
{
return !(_Left._Current < _Right._Current);
Expand Down Expand Up @@ -7207,7 +7207,7 @@ namespace ranges {
}

_NODISCARD_FRIEND constexpr bool operator==(const _Iterator& _Left, const _Iterator& _Right) noexcept(
noexcept(_Fake_copy_init<bool>(_Left._Current == _Right._Current))) /* strengthened */ {
noexcept(_STD _Fake_copy_init<bool>(_Left._Current == _Right._Current))) /* strengthened */ {
if constexpr (_Slide_caches_first<_Base>) {
return _Left._Last_element == _Right._Last_element;
} else {
Expand All @@ -7216,28 +7216,28 @@ namespace ranges {
}

_NODISCARD_FRIEND constexpr bool operator<(const _Iterator& _Left, const _Iterator& _Right) noexcept(
noexcept(_Fake_copy_init<bool>(_Left._Current < _Right._Current))) /* strengthened */
noexcept(_STD _Fake_copy_init<bool>(_Left._Current < _Right._Current))) /* strengthened */
requires random_access_range<_Base>
{
return _Left._Current < _Right._Current;
}

_NODISCARD_FRIEND constexpr bool operator>(const _Iterator& _Left, const _Iterator& _Right) noexcept(
noexcept(_Fake_copy_init<bool>(_Right._Current < _Left._Current))) /* strengthened */
noexcept(_STD _Fake_copy_init<bool>(_Right._Current < _Left._Current))) /* strengthened */
requires random_access_range<_Base>
{
return _Right._Current < _Left._Current;
}

_NODISCARD_FRIEND constexpr bool operator<=(const _Iterator& _Left, const _Iterator& _Right) noexcept(
noexcept(_Fake_copy_init<bool>(!(_Right._Current < _Left._Current)))) /* strengthened */
noexcept(_STD _Fake_copy_init<bool>(!(_Right._Current < _Left._Current)))) /* strengthened */
requires random_access_range<_Base>
{
return !(_Right._Current < _Left._Current);
}

_NODISCARD_FRIEND constexpr bool operator>=(const _Iterator& _Left, const _Iterator& _Right) noexcept(
noexcept(_Fake_copy_init<bool>(!(_Left._Current < _Right._Current)))) /* strengthened */
noexcept(_STD _Fake_copy_init<bool>(!(_Left._Current < _Right._Current)))) /* strengthened */
requires random_access_range<_Base>
{
return !(_Left._Current < _Right._Current);
Expand Down Expand Up @@ -7302,8 +7302,8 @@ namespace ranges {
_Sentinel() = default;

_NODISCARD_FRIEND constexpr bool
operator==(const _Iterator<false>& _Left, const _Sentinel& _Right) noexcept(
noexcept(_Fake_copy_init<bool>(_Left._Get_last_element() == _Right._Last))) /* strengthened */ {
operator==(const _Iterator<false>& _Left, const _Sentinel& _Right) noexcept(noexcept(
_STD _Fake_copy_init<bool>(_Left._Get_last_element() == _Right._Last))) /* strengthened */ {
return _Left._Get_last_element() == _Right._Last;
}

Expand Down Expand Up @@ -7555,12 +7555,12 @@ namespace ranges {
}

_NODISCARD_FRIEND constexpr bool operator==(const _Iterator& _Left, const _Iterator& _Right) noexcept(
noexcept(_Fake_copy_init<bool>(_Left._Current == _Right._Current))) /* strengthened */ {
noexcept(_STD _Fake_copy_init<bool>(_Left._Current == _Right._Current))) /* strengthened */ {
return _Left._Current == _Right._Current;
}

_NODISCARD_FRIEND constexpr bool operator==(const _Iterator& _Left, default_sentinel_t) noexcept(
noexcept(_Fake_copy_init<bool>(_Left._Current == _Left._Next))) /* strengthened */ {
noexcept(_STD _Fake_copy_init<bool>(_Left._Current == _Left._Next))) /* strengthened */ {
return _Left._Current == _Left._Next;
}
};
Expand Down Expand Up @@ -7822,40 +7822,40 @@ namespace ranges {
}

_NODISCARD_FRIEND constexpr bool operator==(const _Iterator& _It, default_sentinel_t) noexcept(
noexcept(_Fake_copy_init<bool>(_It._Current == _It._End))) /* strengthened */ {
noexcept(_STD _Fake_copy_init<bool>(_It._Current == _It._End))) /* strengthened */ {
return _It._Current == _It._End;
}

_NODISCARD_FRIEND constexpr bool operator==(const _Iterator& _Left, const _Iterator& _Right) noexcept(
noexcept(_Fake_copy_init<bool>(_Left._Current == _Right._Current))) // strengthened
noexcept(_STD _Fake_copy_init<bool>(_Left._Current == _Right._Current))) // strengthened
requires equality_comparable<_Base_iterator>
{
return _Left._Current == _Right._Current;
}

_NODISCARD_FRIEND constexpr bool operator<(const _Iterator& _Left, const _Iterator& _Right) noexcept(
noexcept(_Fake_copy_init<bool>(_Left._Current < _Right._Current))) // strengthened
noexcept(_STD _Fake_copy_init<bool>(_Left._Current < _Right._Current))) // strengthened
requires random_access_range<_Base>
{
return _Left._Current < _Right._Current;
}

_NODISCARD_FRIEND constexpr bool operator>(const _Iterator& _Left, const _Iterator& _Right) noexcept(
noexcept(_Fake_copy_init<bool>(_Right._Current < _Left._Current))) // strengthened
noexcept(_STD _Fake_copy_init<bool>(_Right._Current < _Left._Current))) // strengthened
requires random_access_range<_Base>
{
return _Right._Current < _Left._Current;
}

_NODISCARD_FRIEND constexpr bool operator<=(const _Iterator& _Left, const _Iterator& _Right) noexcept(
noexcept(_Fake_copy_init<bool>(!(_Right._Current < _Left._Current)))) // strengthened
noexcept(_STD _Fake_copy_init<bool>(!(_Right._Current < _Left._Current)))) // strengthened
requires random_access_range<_Base>
{
return !(_Right._Current < _Left._Current);
}

_NODISCARD_FRIEND constexpr bool operator>=(const _Iterator& _Left, const _Iterator& _Right) noexcept(
noexcept(_Fake_copy_init<bool>(!(_Left._Current < _Right._Current)))) // strengthened
noexcept(_STD _Fake_copy_init<bool>(!(_Left._Current < _Right._Current)))) // strengthened
requires random_access_range<_Base>
{
return !(_Left._Current < _Right._Current);
Expand Down Expand Up @@ -9124,12 +9124,13 @@ namespace ranges {
}

_NODISCARD_FRIEND constexpr bool operator==(const _Iterator& _Left, const _Iterator& _Right) noexcept(
noexcept(_Fake_copy_init<bool>(_Left._Current.back() == _Right._Current.back()))) /* strengthened */ {
noexcept(_STD _Fake_copy_init<bool>(_Left._Current.back() == _Right._Current.back()))) // strengthened
{
return _Left._Current.back() == _Right._Current.back();
}

_NODISCARD_FRIEND constexpr bool operator<(const _Iterator& _Left, const _Iterator& _Right) noexcept(
noexcept(_Fake_copy_init<bool>(_Left._Current.back() < _Right._Current.back()))) // strengthened
noexcept(_STD _Fake_copy_init<bool>(_Left._Current.back() < _Right._Current.back()))) // strengthened
requires random_access_range<_Base>
{
return _Left._Current.back() < _Right._Current.back();
Expand Down Expand Up @@ -9234,7 +9235,7 @@ namespace ranges {
template <bool _OtherConst>
requires sentinel_for<_Base_sentinel, iterator_t<_Maybe_const<_OtherConst, _Vw>>>
_NODISCARD constexpr bool _Equal(const _Iterator<_OtherConst>& _It) const
noexcept(noexcept(_Fake_copy_init<bool>(_It._Current.back() == _End))) {
noexcept(noexcept(_STD _Fake_copy_init<bool>(_It._Current.back() == _End))) {
return _It._Current.back() == _End;
}

Expand Down
1 change: 1 addition & 0 deletions tests/std/test.lst
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ tests\Dev11_1150223_shared_mutex
tests\Dev11_1158803_regex_thread_safety
tests\Dev11_1180290_filesystem_error_code
tests\GH_000140_adl_proof_comparison
tests\GH_000140_adl_proof_views
tests\GH_000177_forbidden_aliasing
tests\GH_000178_uniform_int
tests\GH_000342_filebuf_close
Expand Down
4 changes: 4 additions & 0 deletions tests/std/tests/GH_000140_adl_proof_views/env.lst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

RUNALL_INCLUDE ..\strict_concepts_20_matrix.lst
Loading

0 comments on commit c74507c

Please sign in to comment.