[libcxx] [llvm] [libc++] Implement P3379R0 Constrain `std::expected` equality operators (PR #135759)
Nikolas Klauser via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 23 01:47:25 PDT 2025
================
@@ -0,0 +1,31 @@
+#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.
+//
+// This is a conceptual __is_core_convertible.
+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)());
+};
----------------
philnik777 wrote:
```suggestion
concept __core_convertible_to = __is_core_convertible_v<_Tp, _Up>;
```
I'd also just move that to the type traits header. There isn't much value in having this separately.
https://github.com/llvm/llvm-project/pull/135759
More information about the llvm-commits
mailing list