Skip to content

Commit

Permalink
Make implicit conversion to bool ADL-proof (except for views) (#4334)
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 Jan 25, 2024
1 parent ee6bdb9 commit ce257fc
Show file tree
Hide file tree
Showing 8 changed files with 509 additions and 73 deletions.
6 changes: 3 additions & 3 deletions stl/inc/expected
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public:
// [expected.un.eq]
template <class _UErr>
_NODISCARD_FRIEND constexpr bool operator==(const unexpected& _Left, const unexpected<_UErr>& _Right) noexcept(
noexcept(_Fake_copy_init<bool>(_Left._Unexpected == _Right.error()))) /* strengthened */ {
noexcept(_STD _Fake_copy_init<bool>(_Left._Unexpected == _Right.error()))) /* strengthened */ {
return _Left._Unexpected == _Right.error();
}

Expand Down Expand Up @@ -1126,8 +1126,8 @@ public:
template <class _Uty, class _UErr>
requires (!is_void_v<_Uty>)
_NODISCARD_FRIEND constexpr bool operator==(const expected& _Left, const expected<_Uty, _UErr>& _Right) noexcept(
noexcept(_Fake_copy_init<bool>(_Left._Value == *_Right)) && noexcept(
_Fake_copy_init<bool>(_Left._Unexpected == _Right.error()))) /* strengthened */ {
noexcept(_STD _Fake_copy_init<bool>(_Left._Value == *_Right)) && noexcept(
_STD _Fake_copy_init<bool>(_Left._Unexpected == _Right.error()))) /* strengthened */ {
if (_Left._Has_value != _Right.has_value()) {
return false;
} else if (_Left._Has_value) {
Expand Down
36 changes: 18 additions & 18 deletions stl/inc/optional
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ optional(_Ty) -> optional<_Ty>;

_EXPORT_STD template <class _Ty1, class _Ty2>
_NODISCARD constexpr bool operator==(const optional<_Ty1>& _Left, const optional<_Ty2>& _Right) noexcept(
noexcept(_Fake_copy_init<bool>(*_Left == *_Right))) /* strengthened */
noexcept(_STD _Fake_copy_init<bool>(*_Left == *_Right))) /* strengthened */
#ifdef __cpp_lib_concepts
requires requires {
{ *_Left == *_Right } -> _Implicitly_convertible_to<bool>;
Expand All @@ -640,7 +640,7 @@ _NODISCARD constexpr bool operator==(const optional<_Ty1>& _Left, const optional

_EXPORT_STD template <class _Ty1, class _Ty2>
_NODISCARD constexpr bool operator!=(const optional<_Ty1>& _Left, const optional<_Ty2>& _Right) noexcept(
noexcept(_Fake_copy_init<bool>(*_Left != *_Right))) /* strengthened */
noexcept(_STD _Fake_copy_init<bool>(*_Left != *_Right))) /* strengthened */
#ifdef __cpp_lib_concepts
requires requires {
{ *_Left != *_Right } -> _Implicitly_convertible_to<bool>;
Expand All @@ -657,7 +657,7 @@ _NODISCARD constexpr bool operator!=(const optional<_Ty1>& _Left, const optional

_EXPORT_STD template <class _Ty1, class _Ty2>
_NODISCARD constexpr bool operator<(const optional<_Ty1>& _Left, const optional<_Ty2>& _Right) noexcept(
noexcept(_Fake_copy_init<bool>(*_Left < *_Right))) /* strengthened */
noexcept(_STD _Fake_copy_init<bool>(*_Left < *_Right))) /* strengthened */
#ifdef __cpp_lib_concepts
requires requires {
{ *_Left < *_Right } -> _Implicitly_convertible_to<bool>;
Expand All @@ -674,7 +674,7 @@ _NODISCARD constexpr bool operator<(const optional<_Ty1>& _Left, const optional<

_EXPORT_STD template <class _Ty1, class _Ty2>
_NODISCARD constexpr bool operator>(const optional<_Ty1>& _Left, const optional<_Ty2>& _Right) noexcept(
noexcept(_Fake_copy_init<bool>(*_Left > *_Right))) /* strengthened */
noexcept(_STD _Fake_copy_init<bool>(*_Left > *_Right))) /* strengthened */
#ifdef __cpp_lib_concepts
requires requires {
{ *_Left > *_Right } -> _Implicitly_convertible_to<bool>;
Expand All @@ -691,7 +691,7 @@ _NODISCARD constexpr bool operator>(const optional<_Ty1>& _Left, const optional<

_EXPORT_STD template <class _Ty1, class _Ty2>
_NODISCARD constexpr bool operator<=(const optional<_Ty1>& _Left, const optional<_Ty2>& _Right) noexcept(
noexcept(_Fake_copy_init<bool>(*_Left <= *_Right))) /* strengthened */
noexcept(_STD _Fake_copy_init<bool>(*_Left <= *_Right))) /* strengthened */
#ifdef __cpp_lib_concepts
requires requires {
{ *_Left <= *_Right } -> _Implicitly_convertible_to<bool>;
Expand All @@ -708,7 +708,7 @@ _NODISCARD constexpr bool operator<=(const optional<_Ty1>& _Left, const optional

_EXPORT_STD template <class _Ty1, class _Ty2>
_NODISCARD constexpr bool operator>=(const optional<_Ty1>& _Left, const optional<_Ty2>& _Right) noexcept(
noexcept(_Fake_copy_init<bool>(*_Left >= *_Right))) /* strengthened */
noexcept(_STD _Fake_copy_init<bool>(*_Left >= *_Right))) /* strengthened */
#ifdef __cpp_lib_concepts
requires requires {
{ *_Left >= *_Right } -> _Implicitly_convertible_to<bool>;
Expand Down Expand Up @@ -828,7 +828,7 @@ using _Enable_if_comparable_with_greater_equal =

_EXPORT_STD template <class _Ty1, class _Ty2, _Enable_if_comparable_with_equal<_Ty1, _Ty2> = 0>
_NODISCARD constexpr bool operator==(const optional<_Ty1>& _Left, const _Ty2& _Right) noexcept(
noexcept(_Fake_copy_init<bool>(*_Left == _Right))) /* strengthened */ {
noexcept(_STD _Fake_copy_init<bool>(*_Left == _Right))) /* strengthened */ {
if (_Left) {
return *_Left == _Right;
}
Expand All @@ -837,7 +837,7 @@ _NODISCARD constexpr bool operator==(const optional<_Ty1>& _Left, const _Ty2& _R

_EXPORT_STD template <class _Ty1, class _Ty2, _Enable_if_comparable_with_equal<_Ty1, _Ty2> = 0>
_NODISCARD constexpr bool operator==(const _Ty1& _Left, const optional<_Ty2>& _Right) noexcept(
noexcept(_Fake_copy_init<bool>(_Left == *_Right))) /* strengthened */ {
noexcept(_STD _Fake_copy_init<bool>(_Left == *_Right))) /* strengthened */ {
if (_Right) {
return _Left == *_Right;
}
Expand All @@ -846,15 +846,15 @@ _NODISCARD constexpr bool operator==(const _Ty1& _Left, const optional<_Ty2>& _R

_EXPORT_STD template <class _Ty1, class _Ty2, _Enable_if_comparable_with_not_equal<_Ty1, _Ty2> = 0>
_NODISCARD constexpr bool operator!=(const optional<_Ty1>& _Left, const _Ty2& _Right) noexcept(
noexcept(_Fake_copy_init<bool>(*_Left != _Right))) /* strengthened */ {
noexcept(_STD _Fake_copy_init<bool>(*_Left != _Right))) /* strengthened */ {
if (_Left) {
return *_Left != _Right;
}
return true;
}
_EXPORT_STD template <class _Ty1, class _Ty2, _Enable_if_comparable_with_not_equal<_Ty1, _Ty2> = 0>
_NODISCARD constexpr bool operator!=(const _Ty1& _Left, const optional<_Ty2>& _Right) noexcept(
noexcept(_Fake_copy_init<bool>(_Left != *_Right))) /* strengthened */ {
noexcept(_STD _Fake_copy_init<bool>(_Left != *_Right))) /* strengthened */ {
if (_Right) {
return _Left != *_Right;
}
Expand All @@ -863,15 +863,15 @@ _NODISCARD constexpr bool operator!=(const _Ty1& _Left, const optional<_Ty2>& _R

_EXPORT_STD template <class _Ty1, class _Ty2, _Enable_if_comparable_with_less<_Ty1, _Ty2> = 0>
_NODISCARD constexpr bool operator<(const optional<_Ty1>& _Left, const _Ty2& _Right) noexcept(
noexcept(_Fake_copy_init<bool>(*_Left < _Right))) /* strengthened */ {
noexcept(_STD _Fake_copy_init<bool>(*_Left < _Right))) /* strengthened */ {
if (_Left) {
return *_Left < _Right;
}
return true;
}
_EXPORT_STD template <class _Ty1, class _Ty2, _Enable_if_comparable_with_less<_Ty1, _Ty2> = 0>
_NODISCARD constexpr bool operator<(const _Ty1& _Left, const optional<_Ty2>& _Right) noexcept(
noexcept(_Fake_copy_init<bool>(_Left < *_Right))) /* strengthened */ {
noexcept(_STD _Fake_copy_init<bool>(_Left < *_Right))) /* strengthened */ {
if (_Right) {
return _Left < *_Right;
}
Expand All @@ -880,15 +880,15 @@ _NODISCARD constexpr bool operator<(const _Ty1& _Left, const optional<_Ty2>& _Ri

_EXPORT_STD template <class _Ty1, class _Ty2, _Enable_if_comparable_with_greater<_Ty1, _Ty2> = 0>
_NODISCARD constexpr bool operator>(const optional<_Ty1>& _Left, const _Ty2& _Right) noexcept(
noexcept(_Fake_copy_init<bool>(*_Left > _Right))) /* strengthened */ {
noexcept(_STD _Fake_copy_init<bool>(*_Left > _Right))) /* strengthened */ {
if (_Left) {
return *_Left > _Right;
}
return false;
}
_EXPORT_STD template <class _Ty1, class _Ty2, _Enable_if_comparable_with_greater<_Ty1, _Ty2> = 0>
_NODISCARD constexpr bool operator>(const _Ty1& _Left, const optional<_Ty2>& _Right) noexcept(
noexcept(_Fake_copy_init<bool>(_Left > *_Right))) /* strengthened */ {
noexcept(_STD _Fake_copy_init<bool>(_Left > *_Right))) /* strengthened */ {
if (_Right) {
return _Left > *_Right;
}
Expand All @@ -897,15 +897,15 @@ _NODISCARD constexpr bool operator>(const _Ty1& _Left, const optional<_Ty2>& _Ri

_EXPORT_STD template <class _Ty1, class _Ty2, _Enable_if_comparable_with_less_equal<_Ty1, _Ty2> = 0>
_NODISCARD constexpr bool operator<=(const optional<_Ty1>& _Left, const _Ty2& _Right) noexcept(
noexcept(_Fake_copy_init<bool>(*_Left <= _Right))) /* strengthened */ {
noexcept(_STD _Fake_copy_init<bool>(*_Left <= _Right))) /* strengthened */ {
if (_Left) {
return *_Left <= _Right;
}
return true;
}
_EXPORT_STD template <class _Ty1, class _Ty2, _Enable_if_comparable_with_less_equal<_Ty1, _Ty2> = 0>
_NODISCARD constexpr bool operator<=(const _Ty1& _Left, const optional<_Ty2>& _Right) noexcept(
noexcept(_Fake_copy_init<bool>(_Left <= *_Right))) /* strengthened */ {
noexcept(_STD _Fake_copy_init<bool>(_Left <= *_Right))) /* strengthened */ {
if (_Right) {
return _Left <= *_Right;
}
Expand All @@ -914,15 +914,15 @@ _NODISCARD constexpr bool operator<=(const _Ty1& _Left, const optional<_Ty2>& _R

_EXPORT_STD template <class _Ty1, class _Ty2, _Enable_if_comparable_with_greater_equal<_Ty1, _Ty2> = 0>
_NODISCARD constexpr bool operator>=(const optional<_Ty1>& _Left, const _Ty2& _Right) noexcept(
noexcept(_Fake_copy_init<bool>(*_Left >= _Right))) /* strengthened */ {
noexcept(_STD _Fake_copy_init<bool>(*_Left >= _Right))) /* strengthened */ {
if (_Left) {
return *_Left >= _Right;
}
return false;
}
_EXPORT_STD template <class _Ty1, class _Ty2, _Enable_if_comparable_with_greater_equal<_Ty1, _Ty2> = 0>
_NODISCARD constexpr bool operator>=(const _Ty1& _Left, const optional<_Ty2>& _Right) noexcept(
noexcept(_Fake_copy_init<bool>(_Left >= *_Right))) /* strengthened */ {
noexcept(_STD _Fake_copy_init<bool>(_Left >= *_Right))) /* strengthened */ {
if (_Right) {
return _Left >= *_Right;
}
Expand Down
2 changes: 1 addition & 1 deletion stl/inc/type_traits
Original file line number Diff line number Diff line change
Expand Up @@ -2441,7 +2441,7 @@ struct less {
using _RESULT_TYPE_NAME _CXX17_DEPRECATE_ADAPTOR_TYPEDEFS = bool;

_NODISCARD constexpr bool operator()(const _Ty& _Left, const _Ty& _Right) const
noexcept(noexcept(_Fake_copy_init<bool>(_Left < _Right))) /* strengthened */ {
noexcept(noexcept(_STD _Fake_copy_init<bool>(_Left < _Right))) /* strengthened */ {
return _Left < _Right;
}
};
Expand Down
Loading

0 comments on commit ce257fc

Please sign in to comment.