Skip to content

Commit

Permalink
Remove _NODISCARD_FRIEND workaround (#4782)
Browse files Browse the repository at this point in the history
Co-authored-by: Stephan T. Lavavej <stl@nuwen.net>
  • Loading branch information
fsb4000 and StephanTLavavej authored Jul 5, 2024
1 parent 4406e0e commit 184ce39
Show file tree
Hide file tree
Showing 29 changed files with 468 additions and 474 deletions.
86 changes: 43 additions & 43 deletions stl/inc/__msvc_int128.hpp

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions stl/inc/__msvc_ranges_to.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@ namespace ranges {
return _STD invoke(*_Parent->_Fun, _Current[_Idx]);
}

_NODISCARD_FRIEND constexpr bool operator==(const _Iterator& _Left, const _Iterator& _Right) noexcept(
_NODISCARD friend constexpr bool operator==(const _Iterator& _Left, const _Iterator& _Right) noexcept(
noexcept(_Left._Current == _Right._Current)) /* strengthened */
requires equality_comparable<iterator_t<_Base>>
{
Expand All @@ -837,7 +837,7 @@ namespace ranges {
return _Left._Current == _Right._Current;
}

_NODISCARD_FRIEND constexpr bool operator<(const _Iterator& _Left, const _Iterator& _Right) noexcept(
_NODISCARD friend constexpr bool operator<(const _Iterator& _Left, const _Iterator& _Right) noexcept(
noexcept(_Left._Current < _Right._Current)) /* strengthened */
requires random_access_range<_Base>
{
Expand All @@ -846,25 +846,25 @@ namespace ranges {
#endif // _ITERATOR_DEBUG_LEVEL != 0
return _Left._Current < _Right._Current;
}
_NODISCARD_FRIEND constexpr bool operator>(const _Iterator& _Left, const _Iterator& _Right) noexcept(
_NODISCARD friend constexpr bool operator>(const _Iterator& _Left, const _Iterator& _Right) noexcept(
noexcept(_Left._Current < _Right._Current)) /* strengthened */
requires random_access_range<_Base>
{
return _Right < _Left;
}
_NODISCARD_FRIEND constexpr bool operator<=(const _Iterator& _Left, const _Iterator& _Right) noexcept(
_NODISCARD friend constexpr bool operator<=(const _Iterator& _Left, const _Iterator& _Right) noexcept(
noexcept(_Left._Current < _Right._Current)) /* strengthened */
requires random_access_range<_Base>
{
return !(_Right < _Left);
}
_NODISCARD_FRIEND constexpr bool operator>=(const _Iterator& _Left, const _Iterator& _Right) noexcept(
_NODISCARD friend constexpr bool operator>=(const _Iterator& _Left, const _Iterator& _Right) noexcept(
noexcept(_Left._Current < _Right._Current)) /* strengthened */
requires random_access_range<_Base>
{
return !(_Left < _Right);
}
_NODISCARD_FRIEND constexpr auto operator<=>(const _Iterator& _Left, const _Iterator& _Right) noexcept(
_NODISCARD friend constexpr auto operator<=>(const _Iterator& _Left, const _Iterator& _Right) noexcept(
noexcept(_Left._Current <=> _Right._Current)) /* strengthened */
requires random_access_range<_Base> && three_way_comparable<iterator_t<_Base>>
{
Expand All @@ -874,7 +874,7 @@ namespace ranges {
return _Left._Current <=> _Right._Current;
}

_NODISCARD_FRIEND constexpr _Iterator operator+(_Iterator _It, const difference_type _Off) noexcept(
_NODISCARD friend constexpr _Iterator operator+(_Iterator _It, const difference_type _Off) noexcept(
noexcept(_It._Current += _Off)) /* strengthened */
requires random_access_range<_Base>
{
Expand All @@ -884,7 +884,7 @@ namespace ranges {
_It._Current += _Off;
return _It;
}
_NODISCARD_FRIEND constexpr _Iterator operator+(const difference_type _Off, _Iterator _It) noexcept(
_NODISCARD friend constexpr _Iterator operator+(const difference_type _Off, _Iterator _It) noexcept(
noexcept(_It._Current += _Off)) /* strengthened */
requires random_access_range<_Base>
{
Expand All @@ -895,7 +895,7 @@ namespace ranges {
return _It;
}

_NODISCARD_FRIEND constexpr _Iterator operator-(_Iterator _It, const difference_type _Off) noexcept(
_NODISCARD friend constexpr _Iterator operator-(_Iterator _It, const difference_type _Off) noexcept(
noexcept(_It._Current -= _Off)) /* strengthened */
requires random_access_range<_Base>
{
Expand All @@ -907,7 +907,7 @@ namespace ranges {
return _It;
}

_NODISCARD_FRIEND constexpr difference_type operator-(const _Iterator& _Left,
_NODISCARD friend constexpr difference_type operator-(const _Iterator& _Left,
const _Iterator& _Right) noexcept(noexcept(_Left._Current - _Right._Current)) /* strengthened */
requires sized_sentinel_for<iterator_t<_Base>, iterator_t<_Base>>
{
Expand Down Expand Up @@ -958,22 +958,22 @@ namespace ranges {

template <bool _OtherConst>
requires sentinel_for<sentinel_t<_Base>, _Maybe_const_iter<_OtherConst>>
_NODISCARD_FRIEND constexpr bool operator==(const _Iterator<_OtherConst>& _Left,
_NODISCARD friend constexpr bool operator==(const _Iterator<_OtherConst>& _Left,
const _Sentinel& _Right) noexcept(noexcept(_Get_current(_Left) == _Right._Last)) /* strengthened */ {
return _Get_current(_Left) == _Right._Last;
}

template <bool _OtherConst>
requires sized_sentinel_for<sentinel_t<_Base>, _Maybe_const_iter<_OtherConst>>
_NODISCARD_FRIEND constexpr range_difference_t<_Maybe_const<_OtherConst, _Vw>> operator-(
_NODISCARD friend constexpr range_difference_t<_Maybe_const<_OtherConst, _Vw>> operator-(
const _Iterator<_OtherConst>& _Left,
const _Sentinel& _Right) noexcept(noexcept(_Get_current(_Left) - _Right._Last)) /* strengthened */ {
return _Get_current(_Left) - _Right._Last;
}

template <bool _OtherConst>
requires sized_sentinel_for<sentinel_t<_Base>, _Maybe_const_iter<_OtherConst>>
_NODISCARD_FRIEND constexpr range_difference_t<_Maybe_const<_OtherConst, _Vw>>
_NODISCARD friend constexpr range_difference_t<_Maybe_const<_OtherConst, _Vw>>
operator-(const _Sentinel& _Left, const _Iterator<_OtherConst>& _Right) noexcept(
noexcept(_Left._Last - _Get_current(_Right))) /* strengthened */ {
return _Left._Last - _Get_current(_Right);
Expand Down
2 changes: 1 addition & 1 deletion stl/inc/__msvc_string_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,7 @@ class _String_view_iterator {
return _Tmp;
}

_NODISCARD_FRIEND constexpr _String_view_iterator operator+(
_NODISCARD friend constexpr _String_view_iterator operator+(
const difference_type _Off, _String_view_iterator _Right) noexcept {
_Right += _Off;
return _Right;
Expand Down
4 changes: 2 additions & 2 deletions stl/inc/array
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public:
return _Tmp;
}

_NODISCARD_FRIEND _CONSTEXPR17 _Array_const_iterator operator+(
_NODISCARD friend _CONSTEXPR17 _Array_const_iterator operator+(
const ptrdiff_t _Off, _Array_const_iterator _Next) noexcept {
_Next += _Off;
return _Next;
Expand Down Expand Up @@ -360,7 +360,7 @@ public:
return _Tmp;
}

_NODISCARD_FRIEND _CONSTEXPR17 _Array_iterator operator+(const ptrdiff_t _Off, _Array_iterator _Next) noexcept {
_NODISCARD friend _CONSTEXPR17 _Array_iterator operator+(const ptrdiff_t _Off, _Array_iterator _Next) noexcept {
_Next += _Off;
return _Next;
}
Expand Down
2 changes: 1 addition & 1 deletion stl/inc/charconv
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ _EXPORT_STD struct from_chars_result {
const char* ptr;
errc ec;
#if _HAS_CXX20
_NODISCARD_FRIEND bool operator==(const from_chars_result&, const from_chars_result&) = default;
_NODISCARD friend bool operator==(const from_chars_result&, const from_chars_result&) = default;
#endif // _HAS_CXX20
};

Expand Down
72 changes: 36 additions & 36 deletions stl/inc/compare
Original file line number Diff line number Diff line change
Expand Up @@ -47,52 +47,52 @@ _EXPORT_STD struct partial_ordering {
static const partial_ordering greater;
static const partial_ordering unordered;

_NODISCARD_FRIEND constexpr bool operator==(const partial_ordering _Val, _Literal_zero) noexcept {
_NODISCARD friend constexpr bool operator==(const partial_ordering _Val, _Literal_zero) noexcept {
return _Val._Value == 0;
}

_NODISCARD_FRIEND constexpr bool operator==(partial_ordering, partial_ordering) noexcept = default;
_NODISCARD friend constexpr bool operator==(partial_ordering, partial_ordering) noexcept = default;

_NODISCARD_FRIEND constexpr bool operator<(const partial_ordering _Val, _Literal_zero) noexcept {
_NODISCARD friend constexpr bool operator<(const partial_ordering _Val, _Literal_zero) noexcept {
return _Val._Value == static_cast<_Compare_t>(_Compare_ord::less);
}

_NODISCARD_FRIEND constexpr bool operator>(const partial_ordering _Val, _Literal_zero) noexcept {
_NODISCARD friend constexpr bool operator>(const partial_ordering _Val, _Literal_zero) noexcept {
return _Val._Value > 0;
}

_NODISCARD_FRIEND constexpr bool operator<=(const partial_ordering _Val, _Literal_zero) noexcept {
_NODISCARD friend constexpr bool operator<=(const partial_ordering _Val, _Literal_zero) noexcept {
// The stored value is either less (0xff), equivalent (0x00), greater (0x01), or unordered (0x80).
// Subtracting from 0 produces either 0x01, 0x00, 0xff, or 0x80. The result is greater than or equal to 0
// if and only if the initial value was less or equivalent, for which we want to return true.
return static_cast<signed char>(0 - static_cast<unsigned int>(_Val._Value)) >= 0;
}

_NODISCARD_FRIEND constexpr bool operator>=(const partial_ordering _Val, _Literal_zero) noexcept {
_NODISCARD friend constexpr bool operator>=(const partial_ordering _Val, _Literal_zero) noexcept {
return _Val._Value >= 0;
}

_NODISCARD_FRIEND constexpr bool operator<(_Literal_zero, const partial_ordering _Val) noexcept {
_NODISCARD friend constexpr bool operator<(_Literal_zero, const partial_ordering _Val) noexcept {
return _Val > 0;
}

_NODISCARD_FRIEND constexpr bool operator>(_Literal_zero, const partial_ordering _Val) noexcept {
_NODISCARD friend constexpr bool operator>(_Literal_zero, const partial_ordering _Val) noexcept {
return _Val < 0;
}

_NODISCARD_FRIEND constexpr bool operator<=(_Literal_zero, const partial_ordering _Val) noexcept {
_NODISCARD friend constexpr bool operator<=(_Literal_zero, const partial_ordering _Val) noexcept {
return _Val >= 0;
}

_NODISCARD_FRIEND constexpr bool operator>=(_Literal_zero, const partial_ordering _Val) noexcept {
_NODISCARD friend constexpr bool operator>=(_Literal_zero, const partial_ordering _Val) noexcept {
return _Val <= 0;
}

_NODISCARD_FRIEND constexpr partial_ordering operator<=>(const partial_ordering _Val, _Literal_zero) noexcept {
_NODISCARD friend constexpr partial_ordering operator<=>(const partial_ordering _Val, _Literal_zero) noexcept {
return _Val;
}

_NODISCARD_FRIEND constexpr partial_ordering operator<=>(_Literal_zero, const partial_ordering _Val) noexcept {
_NODISCARD friend constexpr partial_ordering operator<=>(_Literal_zero, const partial_ordering _Val) noexcept {
// The stored value is either less (0xff), equivalent (0x00), greater (0x01), or unordered (0x80).
// Subtracting from 0 produces either 0x01, 0x00, 0xff, or 0x80. Note that the effect is to
// exchange less for greater (and vice versa), while leaving equivalent and unordered unchanged.
Expand All @@ -116,49 +116,49 @@ _EXPORT_STD struct weak_ordering {
return {static_cast<_Compare_t>(_Value)};
}

_NODISCARD_FRIEND constexpr bool operator==(const weak_ordering _Val, _Literal_zero) noexcept {
_NODISCARD friend constexpr bool operator==(const weak_ordering _Val, _Literal_zero) noexcept {
return _Val._Value == 0;
}

_NODISCARD_FRIEND constexpr bool operator==(weak_ordering, weak_ordering) noexcept = default;
_NODISCARD friend constexpr bool operator==(weak_ordering, weak_ordering) noexcept = default;

_NODISCARD_FRIEND constexpr bool operator<(const weak_ordering _Val, _Literal_zero) noexcept {
_NODISCARD friend constexpr bool operator<(const weak_ordering _Val, _Literal_zero) noexcept {
return _Val._Value < 0;
}

_NODISCARD_FRIEND constexpr bool operator>(const weak_ordering _Val, _Literal_zero) noexcept {
_NODISCARD friend constexpr bool operator>(const weak_ordering _Val, _Literal_zero) noexcept {
return _Val._Value > 0;
}

_NODISCARD_FRIEND constexpr bool operator<=(const weak_ordering _Val, _Literal_zero) noexcept {
_NODISCARD friend constexpr bool operator<=(const weak_ordering _Val, _Literal_zero) noexcept {
return _Val._Value <= 0;
}

_NODISCARD_FRIEND constexpr bool operator>=(const weak_ordering _Val, _Literal_zero) noexcept {
_NODISCARD friend constexpr bool operator>=(const weak_ordering _Val, _Literal_zero) noexcept {
return _Val._Value >= 0;
}

_NODISCARD_FRIEND constexpr bool operator<(_Literal_zero, const weak_ordering _Val) noexcept {
_NODISCARD friend constexpr bool operator<(_Literal_zero, const weak_ordering _Val) noexcept {
return _Val > 0;
}

_NODISCARD_FRIEND constexpr bool operator>(_Literal_zero, const weak_ordering _Val) noexcept {
_NODISCARD friend constexpr bool operator>(_Literal_zero, const weak_ordering _Val) noexcept {
return _Val < 0;
}

_NODISCARD_FRIEND constexpr bool operator<=(_Literal_zero, const weak_ordering _Val) noexcept {
_NODISCARD friend constexpr bool operator<=(_Literal_zero, const weak_ordering _Val) noexcept {
return _Val >= 0;
}

_NODISCARD_FRIEND constexpr bool operator>=(_Literal_zero, const weak_ordering _Val) noexcept {
_NODISCARD friend constexpr bool operator>=(_Literal_zero, const weak_ordering _Val) noexcept {
return _Val <= 0;
}

_NODISCARD_FRIEND constexpr weak_ordering operator<=>(const weak_ordering _Val, _Literal_zero) noexcept {
_NODISCARD friend constexpr weak_ordering operator<=>(const weak_ordering _Val, _Literal_zero) noexcept {
return _Val;
}

_NODISCARD_FRIEND constexpr weak_ordering operator<=>(_Literal_zero, const weak_ordering _Val) noexcept {
_NODISCARD friend constexpr weak_ordering operator<=>(_Literal_zero, const weak_ordering _Val) noexcept {
return {static_cast<_Compare_t>(-_Val._Value)};
}

Expand All @@ -183,49 +183,49 @@ _EXPORT_STD struct strong_ordering {
return {static_cast<_Compare_t>(_Value)};
}

_NODISCARD_FRIEND constexpr bool operator==(const strong_ordering _Val, _Literal_zero) noexcept {
_NODISCARD friend constexpr bool operator==(const strong_ordering _Val, _Literal_zero) noexcept {
return _Val._Value == 0;
}

_NODISCARD_FRIEND constexpr bool operator==(strong_ordering, strong_ordering) noexcept = default;
_NODISCARD friend constexpr bool operator==(strong_ordering, strong_ordering) noexcept = default;

_NODISCARD_FRIEND constexpr bool operator<(const strong_ordering _Val, _Literal_zero) noexcept {
_NODISCARD friend constexpr bool operator<(const strong_ordering _Val, _Literal_zero) noexcept {
return _Val._Value < 0;
}

_NODISCARD_FRIEND constexpr bool operator>(const strong_ordering _Val, _Literal_zero) noexcept {
_NODISCARD friend constexpr bool operator>(const strong_ordering _Val, _Literal_zero) noexcept {
return _Val._Value > 0;
}

_NODISCARD_FRIEND constexpr bool operator<=(const strong_ordering _Val, _Literal_zero) noexcept {
_NODISCARD friend constexpr bool operator<=(const strong_ordering _Val, _Literal_zero) noexcept {
return _Val._Value <= 0;
}

_NODISCARD_FRIEND constexpr bool operator>=(const strong_ordering _Val, _Literal_zero) noexcept {
_NODISCARD friend constexpr bool operator>=(const strong_ordering _Val, _Literal_zero) noexcept {
return _Val._Value >= 0;
}

_NODISCARD_FRIEND constexpr bool operator<(_Literal_zero, const strong_ordering _Val) noexcept {
_NODISCARD friend constexpr bool operator<(_Literal_zero, const strong_ordering _Val) noexcept {
return _Val > 0;
}

_NODISCARD_FRIEND constexpr bool operator>(_Literal_zero, const strong_ordering _Val) noexcept {
_NODISCARD friend constexpr bool operator>(_Literal_zero, const strong_ordering _Val) noexcept {
return _Val < 0;
}

_NODISCARD_FRIEND constexpr bool operator<=(_Literal_zero, const strong_ordering _Val) noexcept {
_NODISCARD friend constexpr bool operator<=(_Literal_zero, const strong_ordering _Val) noexcept {
return _Val >= 0;
}

_NODISCARD_FRIEND constexpr bool operator>=(_Literal_zero, const strong_ordering _Val) noexcept {
_NODISCARD friend constexpr bool operator>=(_Literal_zero, const strong_ordering _Val) noexcept {
return _Val <= 0;
}

_NODISCARD_FRIEND constexpr strong_ordering operator<=>(const strong_ordering _Val, _Literal_zero) noexcept {
_NODISCARD friend constexpr strong_ordering operator<=>(const strong_ordering _Val, _Literal_zero) noexcept {
return _Val;
}

_NODISCARD_FRIEND constexpr strong_ordering operator<=>(_Literal_zero, const strong_ordering _Val) noexcept {
_NODISCARD friend constexpr strong_ordering operator<=>(_Literal_zero, const strong_ordering _Val) noexcept {
return {static_cast<_Compare_t>(-_Val._Value)};
}

Expand Down
8 changes: 4 additions & 4 deletions stl/inc/deque
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public:
return _Tmp;
}

_NODISCARD_FRIEND _Deque_unchecked_const_iterator operator+(
_NODISCARD friend _Deque_unchecked_const_iterator operator+(
const difference_type _Off, _Deque_unchecked_const_iterator _Next) noexcept {
_Next += _Off;
return _Next;
Expand Down Expand Up @@ -202,7 +202,7 @@ public:
return _Tmp;
}

_NODISCARD_FRIEND _Deque_unchecked_iterator operator+(
_NODISCARD friend _Deque_unchecked_iterator operator+(
const difference_type _Off, _Deque_unchecked_iterator _Next) noexcept {
_Next += _Off;
return _Next;
Expand Down Expand Up @@ -323,7 +323,7 @@ public:
return _Tmp;
}

_NODISCARD_FRIEND _Deque_const_iterator operator+(
_NODISCARD friend _Deque_const_iterator operator+(
const difference_type _Off, _Deque_const_iterator _Next) noexcept {
_Next += _Off;
return _Next;
Expand Down Expand Up @@ -484,7 +484,7 @@ public:
return _Tmp;
}

_NODISCARD_FRIEND _Deque_iterator operator+(const difference_type _Off, _Deque_iterator _Next) noexcept {
_NODISCARD friend _Deque_iterator operator+(const difference_type _Off, _Deque_iterator _Next) noexcept {
_Next += _Off;
return _Next;
}
Expand Down
Loading

0 comments on commit 184ce39

Please sign in to comment.