Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use _NODISCARD_FRIEND everywhere #2622

Merged
merged 1 commit into from
Apr 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ 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 @@ -41,52 +41,52 @@ 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 @@ -110,49 +110,49 @@ 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 @@ -177,49 +177,49 @@ 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
12 changes: 6 additions & 6 deletions stl/inc/exception
Original file line number Diff line number Diff line change
Expand Up @@ -260,28 +260,28 @@ public:
__ExceptionPtrSwap(&_Lhs, &_Rhs);
}

_NODISCARD friend bool operator==(const exception_ptr& _Lhs, const exception_ptr& _Rhs) noexcept {
_NODISCARD_FRIEND bool operator==(const exception_ptr& _Lhs, const exception_ptr& _Rhs) noexcept {
return __ExceptionPtrCompare(&_Lhs, &_Rhs);
}

_NODISCARD friend bool operator==(const exception_ptr& _Lhs, nullptr_t) noexcept {
_NODISCARD_FRIEND bool operator==(const exception_ptr& _Lhs, nullptr_t) noexcept {
return !_Lhs;
}

#if !_HAS_CXX20
_NODISCARD friend bool operator==(nullptr_t, const exception_ptr& _Rhs) noexcept {
_NODISCARD_FRIEND bool operator==(nullptr_t, const exception_ptr& _Rhs) noexcept {
return !_Rhs;
}

_NODISCARD friend bool operator!=(const exception_ptr& _Lhs, const exception_ptr& _Rhs) noexcept {
_NODISCARD_FRIEND bool operator!=(const exception_ptr& _Lhs, const exception_ptr& _Rhs) noexcept {
return !(_Lhs == _Rhs);
}

_NODISCARD friend bool operator!=(const exception_ptr& _Lhs, nullptr_t _Rhs) noexcept {
_NODISCARD_FRIEND bool operator!=(const exception_ptr& _Lhs, nullptr_t _Rhs) noexcept {
return !(_Lhs == _Rhs);
}

_NODISCARD friend bool operator!=(nullptr_t _Lhs, const exception_ptr& _Rhs) noexcept {
_NODISCARD_FRIEND bool operator!=(nullptr_t _Lhs, const exception_ptr& _Rhs) noexcept {
return !(_Lhs == _Rhs);
}
#endif // !_HAS_CXX20
Expand Down
24 changes: 12 additions & 12 deletions stl/inc/filesystem
Original file line number Diff line number Diff line change
Expand Up @@ -1395,37 +1395,37 @@ namespace filesystem {
return _Istr;
}

_NODISCARD friend bool operator==(const path& _Left, const path& _Right) noexcept {
_NODISCARD_FRIEND bool operator==(const path& _Left, const path& _Right) noexcept {
return _Left.compare(_Right._Text) == 0;
}

#if _HAS_CXX20
_NODISCARD friend strong_ordering operator<=>(const path& _Left, const path& _Right) noexcept {
_NODISCARD_FRIEND strong_ordering operator<=>(const path& _Left, const path& _Right) noexcept {
return _Left.compare(_Right._Text) <=> 0;
}
#else // ^^^ _HAS_CXX20 / !_HAS_CXX20 vvv
_NODISCARD friend bool operator!=(const path& _Left, const path& _Right) noexcept {
_NODISCARD_FRIEND bool operator!=(const path& _Left, const path& _Right) noexcept {
return _Left.compare(_Right) != 0;
}

_NODISCARD friend bool operator<(const path& _Left, const path& _Right) noexcept {
_NODISCARD_FRIEND bool operator<(const path& _Left, const path& _Right) noexcept {
return _Left.compare(_Right) < 0;
}

_NODISCARD friend bool operator>(const path& _Left, const path& _Right) noexcept {
_NODISCARD_FRIEND bool operator>(const path& _Left, const path& _Right) noexcept {
return _Left.compare(_Right) > 0;
}

_NODISCARD friend bool operator<=(const path& _Left, const path& _Right) noexcept {
_NODISCARD_FRIEND bool operator<=(const path& _Left, const path& _Right) noexcept {
return _Left.compare(_Right) <= 0;
}

_NODISCARD friend bool operator>=(const path& _Left, const path& _Right) noexcept {
_NODISCARD_FRIEND bool operator>=(const path& _Left, const path& _Right) noexcept {
return _Left.compare(_Right) >= 0;
}
#endif // !_HAS_CXX20

_NODISCARD friend path operator/(const path& _Left, const path& _Right) { // append a pair of paths together
_NODISCARD_FRIEND path operator/(const path& _Left, const path& _Right) { // append a pair of paths together
path _Tmp = _Left;
_Tmp /= _Right;
return _Tmp;
Expand Down Expand Up @@ -1596,12 +1596,12 @@ namespace filesystem {
return _Tmp;
}

_NODISCARD friend bool operator==(const _Path_iterator& _Lhs, const _Path_iterator& _Rhs) {
_NODISCARD_FRIEND bool operator==(const _Path_iterator& _Lhs, const _Path_iterator& _Rhs) {
return _Lhs._Position == _Rhs._Position;
}

#if !_HAS_CXX20
_NODISCARD friend bool operator!=(const _Path_iterator& _Lhs, const _Path_iterator& _Rhs) {
_NODISCARD_FRIEND bool operator!=(const _Path_iterator& _Lhs, const _Path_iterator& _Rhs) {
return _Lhs._Position != _Rhs._Position;
}
#endif // !_HAS_CXX20
Expand Down Expand Up @@ -1972,7 +1972,7 @@ namespace filesystem {
}

#if _HAS_CXX20
_NODISCARD friend bool operator==(const file_status& _Lhs, const file_status& _Rhs) noexcept {
_NODISCARD_FRIEND bool operator==(const file_status& _Lhs, const file_status& _Rhs) noexcept {
return _Lhs._Myftype == _Rhs._Myftype && _Lhs._Myperms == _Rhs._Myperms;
}
#endif // _HAS_CXX20
Expand Down Expand Up @@ -3630,7 +3630,7 @@ namespace filesystem {
uintmax_t available;

#if _HAS_CXX20
_NODISCARD friend constexpr bool operator==(const space_info&, const space_info&) noexcept = default;
_NODISCARD_FRIEND constexpr bool operator==(const space_info&, const space_info&) noexcept = default;
#endif // _HAS_CXX20
};

Expand Down
2 changes: 1 addition & 1 deletion stl/inc/functional
Original file line number Diff line number Diff line change
Expand Up @@ -1844,7 +1844,7 @@ public:
_Fn1._Swap(_Fn2);
}

_NODISCARD friend bool operator==(const move_only_function& _This, nullptr_t) noexcept {
_NODISCARD_FRIEND bool operator==(const move_only_function& _This, nullptr_t) noexcept {
return _This._Is_null();
}
};
Expand Down
8 changes: 4 additions & 4 deletions stl/inc/iosfwd
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,12 @@ public:
}

template <class _Int, enable_if_t<is_integral_v<_Int>, int> = 0>
_NODISCARD friend bool operator==(const fpos& _Left, const _Int _Right) {
_NODISCARD_FRIEND bool operator==(const fpos& _Left, const _Int _Right) {
return static_cast<streamoff>(_Left) == _Right;
}

template <class _Int, enable_if_t<is_integral_v<_Int>, int> = 0>
_NODISCARD friend bool operator==(const _Int _Left, const fpos& _Right) {
_NODISCARD_FRIEND bool operator==(const _Int _Left, const fpos& _Right) {
return _Left == static_cast<streamoff>(_Right);
}

Expand All @@ -119,12 +119,12 @@ public:
}

template <class _Int, enable_if_t<is_integral_v<_Int>, int> = 0>
_NODISCARD friend bool operator!=(const fpos& _Left, const _Int _Right) {
_NODISCARD_FRIEND bool operator!=(const fpos& _Left, const _Int _Right) {
return static_cast<streamoff>(_Left) != _Right;
}

template <class _Int, enable_if_t<is_integral_v<_Int>, int> = 0>
_NODISCARD friend bool operator!=(const _Int _Left, const fpos& _Right) {
_NODISCARD_FRIEND bool operator!=(const _Int _Left, const fpos& _Right) {
return _Left != static_cast<streamoff>(_Right);
}

Expand Down
Loading