[libcxx-commits] [libcxx] [libc++] P3379R1: Constrain `std::expected` equality operators (PR #117664)
A. Jiang via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Nov 27 21:52:01 PST 2024
================
@@ -1139,7 +1140,11 @@ class expected : private __expected_base<_Tp, _Err> {
// [expected.object.eq], equality operators
template <class _T2, class _E2>
- requires(!is_void_v<_T2>)
+ requires(!is_void_v<_T2> &&
+ requires(const _Tp& __tp, const _T2& __t2, const _Err& __err, const _E2& __e2) {
+ { __tp == __t2 } -> convertible_to<bool>;
----------------
frederick-vs-ja wrote:
I guess we can have the following.
<details><summary>Internal concept <code>__core_convertible_to</code> in the <code><__concepts/core_convertible_to.h></code> internal header</summary>
<p>
```C++
#ifndef _LIBCPP___CONCEPTS_CORE_CONVERTIBLE_TO_H
#define _LIBCPP___CONCEPTS_CORE_CONVERTIBLE_TO_H
#include <__config>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
#if _LIBCPP_STD_VER >= 20
// [conv.general]/3 says "E is convertible to T" whenever "T t=E;" is well-formed.
// We can't test for that, but we can test implicit convertibility by passing it
// to a function. Unlike std::convertible_to, __core_convertible_to doesn't test
// static_cast or handle cv void, while accepting move-only types.
template <class _Tp, class _Up>
concept __core_convertible_to = requires {
// rejects function and array types which are adjusted to pointer types in parameter lists
static_cast<_Up (*)()>(nullptr)();
static_cast<void (*)(_Up)>(nullptr)(static_cast<_Tp (*)()>(nullptr)());
};
#endif
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP___CONCEPTS_CORE_CONVERTIBLE_TO_H
```
</p>
</details>
https://github.com/llvm/llvm-project/pull/117664
More information about the libcxx-commits
mailing list