[libcxx-commits] [libcxx] [libc++] Implement P2538R1 "ADL-proof std::projected" (PR #65411)

A. Jiang via libcxx-commits libcxx-commits at lists.llvm.org
Wed Sep 6 05:24:00 PDT 2023


================
@@ -23,13 +23,29 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 
 #if _LIBCPP_STD_VER >= 20
 
-template<indirectly_readable _It, indirectly_regular_unary_invocable<_It> _Proj>
-struct projected {
-  using value_type = remove_cvref_t<indirect_result_t<_Proj&, _It>>;
-  indirect_result_t<_Proj&, _It> operator*() const; // not defined
+template <class _It, class _Proj>
+struct __projected_impl {
+  struct __type {
+    using value_type = remove_cvref_t<indirect_result_t<_Proj&, _It>>;
+    indirect_result_t<_Proj&, _It> operator*() const; // not defined
+  };
 };
 
-template<weakly_incrementable _It, class _Proj>
+template <weakly_incrementable _It, class _Proj>
+struct __projected_impl<_It, _Proj> {
+  struct __type {
+    using value_type      = remove_cvref_t<indirect_result_t<_Proj&, _It>>;
+    using difference_type = iter_difference_t<_It>;
+    indirect_result_t<_Proj&, _It> operator*() const; // not defined
+  };
+};
+
+// Note: We implement std::projected in a way that satisfies P2538R1 even in standard
+//       modes before C++26 to avoid breaking the ABI between standard modes.
+template <indirectly_readable _It, indirectly_regular_unary_invocable<_It> _Proj>
+using projected = typename __projected_impl<_It, _Proj>::__type;
+
+template <weakly_incrementable _It, class _Proj>
 struct incrementable_traits<projected<_It, _Proj>> {
   using difference_type = iter_difference_t<_It>;
 };
----------------
frederick-vs-ja wrote:

It's strange that this (no longer valid) partial specialization is not removed.

https://github.com/llvm/llvm-project/pull/65411


More information about the libcxx-commits mailing list