diff mbox series

[committed] libstdc++: Rename C++20 Customization Point Objects

Message ID 20230907071141.866877-1-jwakely@redhat.com
State New
Headers show
Series [committed] libstdc++: Rename C++20 Customization Point Objects | expand

Commit Message

Jonathan Wakely Sept. 7, 2023, 7:11 a.m. UTC
Tested x86_64-linux. Pushed to trunk.

-- >8 --

This makes the naming of the CPO types and namespaces simpler and more
consistent. With this change the string "cust" won't appear in
diagnostics related to these CPOs, which avoids confusion about what it
means (customization? customer?). Users don't really need to care that
these are called "customization point objects", so don't show them the
string "cust". Names like "__imove::_IterMove" are preferable to names
like "__cust_imove::_IMove" as the former is more obviously related to
the public API "ranges::iter_move".

Instead of a plethora of inline namespaces for all the different CPO
objects, define them all in an inline namespace called _Cpo (which isn't
shown to users anyway, unlike the types of those objects).

libstdc++-v3/ChangeLog:

	* include/bits/iterator_concepts.h (ranges::__cust_imove):
	Rename to ranges::__imove.
	(_IMove): Rename to _IterMove.
	(ranges::__cust_iswap): Rename to ranges::__iswap.
	(ranges::__cust): Rename to ranges::_Cpo.
	(ranges::__cust_access): Rename to ranges::__access.
	* include/bits/ranges_base.h (ranges::__cust_access): Rename to
	ranges::__access.
	(ranges::__cust): Rename to ranges::_Cpo.
	* include/std/concepts (ranges::__cust_swap):  Rename to
	ranges::__swap.
	(ranges::__cust): Rename to ranges::_Cpo.
	* libsupc++/compare (__cmp_cust): Rename to __compare.
	(__cmp_algo): Rename to _Cpo.
---
 libstdc++-v3/include/bits/iterator_concepts.h |  46 ++++----
 libstdc++-v3/include/bits/ranges_base.h       | 100 +++++++++---------
 libstdc++-v3/include/std/concepts             |  13 +--
 libstdc++-v3/libsupc++/compare                |  31 +++---
 4 files changed, 98 insertions(+), 92 deletions(-)
diff mbox series

Patch

diff --git a/libstdc++-v3/include/bits/iterator_concepts.h b/libstdc++-v3/include/bits/iterator_concepts.h
index e32e94dc9fc..869d52e378b 100644
--- a/libstdc++-v3/include/bits/iterator_concepts.h
+++ b/libstdc++-v3/include/bits/iterator_concepts.h
@@ -97,7 +97,8 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   namespace ranges
   {
-    namespace __cust_imove
+    /// @cond undocumented
+    namespace __imove
     {
       void iter_move();
 
@@ -106,7 +107,7 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	  = (std::__detail::__class_or_enum<remove_reference_t<_Tp>>)
 	  && requires(_Tp&& __t) { iter_move(static_cast<_Tp&&>(__t)); };
 
-      struct _IMove
+      struct _IterMove
       {
       private:
 	template<typename _Tp>
@@ -153,19 +154,17 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	      return *__e;
 	  }
       };
-    } // namespace __cust_imove
+    } // namespace __imove
+    /// @endcond
 
-    inline namespace __cust
-    {
-      inline constexpr __cust_imove::_IMove iter_move{};
-    } // inline namespace __cust
+    inline namespace _Cpo {
+      inline constexpr __imove::_IterMove iter_move{};
+    }
   } // namespace ranges
 
   template<__detail::__dereferenceable _Tp>
-    requires __detail::
-      __can_reference<ranges::__cust_imove::_IMove::__type<_Tp&>>
-    using iter_rvalue_reference_t
-      = ranges::__cust_imove::_IMove::__type<_Tp&>;
+    requires __detail::__can_reference<ranges::__imove::_IterMove::__type<_Tp&>>
+    using iter_rvalue_reference_t = ranges::__imove::_IterMove::__type<_Tp&>;
 
   template<typename> struct incrementable_traits { };
 
@@ -832,7 +831,8 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
 namespace ranges
 {
-  namespace __cust_iswap
+  /// @cond undocumented
+  namespace __iswap
   {
     template<typename _It1, typename _It2>
       void iter_swap(_It1, _It2) = delete;
@@ -873,8 +873,8 @@  namespace ranges
 					 *std::declval<_Up>()));
 	  else
 	    return noexcept(*std::declval<_Tp>()
-		= __iter_exchange_move(std::declval<_Up>(),
-				       std::declval<_Tp>()));
+		= __iswap::__iter_exchange_move(std::declval<_Up>(),
+						    std::declval<_Tp>()));
 	}
 
     public:
@@ -896,15 +896,15 @@  namespace ranges
 	      && swappable_with<iter_reference_t<_Tp>, iter_reference_t<_Up>>)
 	    ranges::swap(*__e1, *__e2);
 	  else
-	    *__e1 = __iter_exchange_move(__e2, __e1);
+	    *__e1 = __iswap::__iter_exchange_move(__e2, __e1);
 	}
     };
-  } // namespace __cust_iswap
+  } // namespace __iswap
+  /// @endcond
 
-  inline namespace __cust
-  {
-    inline constexpr __cust_iswap::_IterSwap iter_swap{};
-  } // inline namespace __cust
+  inline namespace _Cpo {
+    inline constexpr __iswap::_IterSwap iter_swap{};
+  }
 
 } // namespace ranges
 
@@ -960,7 +960,7 @@  namespace ranges
   inline constexpr unreachable_sentinel_t unreachable_sentinel{};
 
   // This is the namespace for [range.access] CPOs.
-  namespace ranges::__cust_access
+  namespace ranges::__access
   {
     using std::__detail::__class_or_enum;
 
@@ -1004,14 +1004,14 @@  namespace ranges
 	else
 	  return begin(__t);
       }
-  } // namespace ranges::__cust_access
+  } // namespace ranges::__access
 
   namespace __detail
   {
     // Implementation of std::ranges::iterator_t, without using ranges::begin.
     template<typename _Tp>
       using __range_iter_t
-	= decltype(ranges::__cust_access::__begin(std::declval<_Tp&>()));
+	= decltype(ranges::__access::__begin(std::declval<_Tp&>()));
 
   } // namespace __detail
 
diff --git a/libstdc++-v3/include/bits/ranges_base.h b/libstdc++-v3/include/bits/ranges_base.h
index 698dac7b7c1..35861755c0b 100644
--- a/libstdc++-v3/include/bits/ranges_base.h
+++ b/libstdc++-v3/include/bits/ranges_base.h
@@ -87,7 +87,8 @@  namespace ranges
 
   } // namespace __detail
 
-  namespace __cust_access
+  // Namespace for helpers for the <ranges> customization points.
+  namespace __access
   {
     using std::ranges::__detail::__maybe_borrowed_range;
     using std::__detail::__range_iter_t;
@@ -482,18 +483,18 @@  namespace ranges
 	}
     };
 
-  } // namespace __cust_access
+  } // namespace __access
 
-  inline namespace __cust
+  inline namespace _Cpo
   {
-    inline constexpr __cust_access::_Begin begin{};
-    inline constexpr __cust_access::_End end{};
-    inline constexpr __cust_access::_RBegin rbegin{};
-    inline constexpr __cust_access::_REnd rend{};
-    inline constexpr __cust_access::_Size size{};
-    inline constexpr __cust_access::_SSize ssize{};
-    inline constexpr __cust_access::_Empty empty{};
-    inline constexpr __cust_access::_Data data{};
+    inline constexpr ranges::__access::_Begin begin{};
+    inline constexpr ranges::__access::_End end{};
+    inline constexpr ranges::__access::_RBegin rbegin{};
+    inline constexpr ranges::__access::_REnd rend{};
+    inline constexpr ranges::__access::_Size size{};
+    inline constexpr ranges::__access::_SSize ssize{};
+    inline constexpr ranges::__access::_Empty empty{};
+    inline constexpr ranges::__access::_Data data{};
   }
 
   /// [range.range] The range concept.
@@ -624,7 +625,7 @@  namespace ranges
       = input_range<_Tp> && std::__detail::__constant_iterator<iterator_t<_Tp>>;
 #endif
 
-  namespace __cust_access
+  namespace __access
   {
 #if __cplusplus > 202020L
     template<typename _Range>
@@ -659,11 +660,11 @@  namespace ranges
 	constexpr auto
 	operator()(_Tp&& __t) const
 	noexcept(noexcept(std::make_const_iterator
-			  (ranges::begin(__cust_access::__possibly_const_range(__t)))))
+			  (ranges::begin(__access::__possibly_const_range(__t)))))
 	requires requires { std::make_const_iterator
-			    (ranges::begin(__cust_access::__possibly_const_range(__t))); }
+			    (ranges::begin(__access::__possibly_const_range(__t))); }
 	{
-	  auto& __r = __cust_access::__possibly_const_range(__t);
+	  auto& __r = __access::__possibly_const_range(__t);
 	  return const_iterator_t<decltype(__r)>(ranges::begin(__r));
 	}
 #else
@@ -671,10 +672,10 @@  namespace ranges
 	[[nodiscard]]
 	constexpr auto
 	operator()(_Tp&& __e) const
-	noexcept(noexcept(_Begin{}(__cust_access::__as_const<_Tp>(__e))))
-	requires requires { _Begin{}(__cust_access::__as_const<_Tp>(__e)); }
+	noexcept(noexcept(_Begin{}(__access::__as_const<_Tp>(__e))))
+	requires requires { _Begin{}(__access::__as_const<_Tp>(__e)); }
 	{
-	  return _Begin{}(__cust_access::__as_const<_Tp>(__e));
+	  return _Begin{}(__access::__as_const<_Tp>(__e));
 	}
 #endif
     };
@@ -687,11 +688,11 @@  namespace ranges
 	constexpr auto
 	operator()(_Tp&& __t) const
 	noexcept(noexcept(std::make_const_sentinel
-			  (ranges::end(__cust_access::__possibly_const_range(__t)))))
+			  (ranges::end(__access::__possibly_const_range(__t)))))
 	requires requires { std::make_const_sentinel
-			    (ranges::end(__cust_access::__possibly_const_range(__t))); }
+			    (ranges::end(__access::__possibly_const_range(__t))); }
 	{
-	  auto& __r = __cust_access::__possibly_const_range(__t);
+	  auto& __r = __access::__possibly_const_range(__t);
 	  return const_sentinel_t<decltype(__r)>(ranges::end(__r));
 	}
 #else
@@ -699,10 +700,10 @@  namespace ranges
 	[[nodiscard]]
 	constexpr auto
 	operator()(_Tp&& __e) const
-	noexcept(noexcept(_End{}(__cust_access::__as_const<_Tp>(__e))))
-	requires requires { _End{}(__cust_access::__as_const<_Tp>(__e)); }
+	noexcept(noexcept(_End{}(__access::__as_const<_Tp>(__e))))
+	requires requires { _End{}(__access::__as_const<_Tp>(__e)); }
 	{
-	  return _End{}(__cust_access::__as_const<_Tp>(__e));
+	  return _End{}(__access::__as_const<_Tp>(__e));
 	}
 #endif
     };
@@ -715,11 +716,11 @@  namespace ranges
 	constexpr auto
 	operator()(_Tp&& __t) const
 	noexcept(noexcept(std::make_const_iterator
-			  (ranges::rbegin(__cust_access::__possibly_const_range(__t)))))
+			  (ranges::rbegin(__access::__possibly_const_range(__t)))))
 	requires requires { std::make_const_iterator
-			    (ranges::rbegin(__cust_access::__possibly_const_range(__t))); }
+			    (ranges::rbegin(__access::__possibly_const_range(__t))); }
 	{
-	  auto& __r = __cust_access::__possibly_const_range(__t);
+	  auto& __r = __access::__possibly_const_range(__t);
 	  return const_iterator<decltype(ranges::rbegin(__r))>(ranges::rbegin(__r));
 	}
 #else
@@ -727,10 +728,10 @@  namespace ranges
 	[[nodiscard]]
 	constexpr auto
 	operator()(_Tp&& __e) const
-	noexcept(noexcept(_RBegin{}(__cust_access::__as_const<_Tp>(__e))))
-	requires requires { _RBegin{}(__cust_access::__as_const<_Tp>(__e)); }
+	noexcept(noexcept(_RBegin{}(__access::__as_const<_Tp>(__e))))
+	requires requires { _RBegin{}(__access::__as_const<_Tp>(__e)); }
 	{
-	  return _RBegin{}(__cust_access::__as_const<_Tp>(__e));
+	  return _RBegin{}(__access::__as_const<_Tp>(__e));
 	}
 #endif
     };
@@ -743,11 +744,11 @@  namespace ranges
 	constexpr auto
 	operator()(_Tp&& __t) const
 	noexcept(noexcept(std::make_const_sentinel
-			  (ranges::rend(__cust_access::__possibly_const_range(__t)))))
+			  (ranges::rend(__access::__possibly_const_range(__t)))))
 	requires requires { std::make_const_sentinel
-			    (ranges::rend(__cust_access::__possibly_const_range(__t))); }
+			    (ranges::rend(__access::__possibly_const_range(__t))); }
 	{
-	  auto& __r = __cust_access::__possibly_const_range(__t);
+	  auto& __r = __access::__possibly_const_range(__t);
 	  return const_sentinel<decltype(ranges::rend(__r))>(ranges::rend(__r));
 	}
 #else
@@ -755,10 +756,10 @@  namespace ranges
 	[[nodiscard]]
 	constexpr auto
 	operator()(_Tp&& __e) const
-	noexcept(noexcept(_REnd{}(__cust_access::__as_const<_Tp>(__e))))
-	requires requires { _REnd{}(__cust_access::__as_const<_Tp>(__e)); }
+	noexcept(noexcept(_REnd{}(__access::__as_const<_Tp>(__e))))
+	requires requires { _REnd{}(__access::__as_const<_Tp>(__e)); }
 	{
-	  return _REnd{}(__cust_access::__as_const<_Tp>(__e));
+	  return _REnd{}(__access::__as_const<_Tp>(__e));
 	}
 #endif
     };
@@ -770,31 +771,30 @@  namespace ranges
 	[[nodiscard]]
 	constexpr const auto*
 	operator()(_Tp&& __t) const
-	noexcept(noexcept(ranges::data(__cust_access::__possibly_const_range(__t))))
-	requires requires { ranges::data(__cust_access::__possibly_const_range(__t)); }
-	{ return ranges::data(__cust_access::__possibly_const_range(__t)); }
+	noexcept(noexcept(ranges::data(__access::__possibly_const_range(__t))))
+	requires requires { ranges::data(__access::__possibly_const_range(__t)); }
+	{ return ranges::data(__access::__possibly_const_range(__t)); }
 #else
       template<typename _Tp>
 	[[nodiscard]]
 	constexpr auto
 	operator()(_Tp&& __e) const
-	noexcept(noexcept(_Data{}(__cust_access::__as_const<_Tp>(__e))))
-	requires requires { _Data{}(__cust_access::__as_const<_Tp>(__e)); }
+	noexcept(noexcept(_Data{}(__access::__as_const<_Tp>(__e))))
+	requires requires { _Data{}(__access::__as_const<_Tp>(__e)); }
 	{
-	  return _Data{}(__cust_access::__as_const<_Tp>(__e));
+	  return _Data{}(__access::__as_const<_Tp>(__e));
 	}
 #endif
     };
+  } // namespace __access
 
-  } // namespace __cust_access
-
-  inline namespace __cust
+  inline namespace _Cpo
   {
-    inline constexpr __cust_access::_CBegin cbegin{};
-    inline constexpr __cust_access::_CEnd cend{};
-    inline constexpr __cust_access::_CRBegin crbegin{};
-    inline constexpr __cust_access::_CREnd crend{};
-    inline constexpr __cust_access::_CData cdata{};
+    inline constexpr ranges::__access::_CBegin cbegin{};
+    inline constexpr ranges::__access::_CEnd cend{};
+    inline constexpr ranges::__access::_CRBegin crbegin{};
+    inline constexpr ranges::__access::_CREnd crend{};
+    inline constexpr ranges::__access::_CData cdata{};
   }
 
   namespace __detail
diff --git a/libstdc++-v3/include/std/concepts b/libstdc++-v3/include/std/concepts
index d8a05ffab33..d958ab74701 100644
--- a/libstdc++-v3/include/std/concepts
+++ b/libstdc++-v3/include/std/concepts
@@ -178,7 +178,8 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   namespace ranges
   {
-    namespace __cust_swap
+    /// @cond undocumented
+    namespace __swap
     {
       template<typename _Tp> void swap(_Tp&, _Tp&) = delete;
 
@@ -236,12 +237,12 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	      (*this)(__e1[__n], __e2[__n]);
 	  }
       };
-    } // namespace __cust_swap
+    } // namespace __swap
+    /// @endcond
 
-    inline namespace __cust
-    {
-      inline constexpr __cust_swap::_Swap swap{};
-    } // inline namespace __cust
+    inline namespace _Cpo {
+      inline constexpr __swap::_Swap swap{};
+    }
   } // namespace ranges
 
   template<typename _Tp>
diff --git a/libstdc++-v3/libsupc++/compare b/libstdc++-v3/libsupc++/compare
index 9215f51e94b..84ef31a1ee7 100644
--- a/libstdc++-v3/libsupc++/compare
+++ b/libstdc++-v3/libsupc++/compare
@@ -566,7 +566,9 @@  namespace std _GLIBCXX_VISIBILITY(default)
     using is_transparent = void;
   };
 
-  namespace __cmp_cust
+  /// @cond undocumented
+  // Namespace for helpers for the <compare> customization points.
+  namespace __compare
   {
     template<floating_point _Tp>
       constexpr weak_ordering
@@ -1000,7 +1002,7 @@  namespace std _GLIBCXX_VISIBILITY(default)
 	noexcept(_S_noexcept<_Tp, _Up>())
 	{
 	  if constexpr (floating_point<decay_t<_Tp>>)
-	    return __cmp_cust::__fp_weak_ordering(__e, __f);
+	    return __compare::__fp_weak_ordering(__e, __f);
 	  else if constexpr (__adl_weak<_Tp, _Up>)
 	    return weak_ordering(weak_order(static_cast<_Tp&&>(__e),
 					    static_cast<_Up&&>(__f)));
@@ -1172,27 +1174,29 @@  namespace std _GLIBCXX_VISIBILITY(default)
 	      : partial_ordering::unordered;
 	}
     };
-  } // namespace __cmp_cust
+  } // namespace @endcond
 
   // [cmp.alg], comparison algorithms
-  inline namespace __cmp_alg
+
+  inline namespace _Cpo
   {
-    inline constexpr __cmp_cust::_Strong_order strong_order{};
+    inline constexpr __compare::_Strong_order strong_order{};
 
-    inline constexpr __cmp_cust::_Weak_order weak_order{};
+    inline constexpr __compare::_Weak_order weak_order{};
 
-    inline constexpr __cmp_cust::_Partial_order partial_order{};
+    inline constexpr __compare::_Partial_order partial_order{};
 
-    inline constexpr __cmp_cust::_Strong_fallback
-    compare_strong_order_fallback{};
+    inline constexpr __compare::_Strong_fallback
+      compare_strong_order_fallback{};
 
-    inline constexpr __cmp_cust::_Weak_fallback
-    compare_weak_order_fallback{};
+    inline constexpr __compare::_Weak_fallback
+      compare_weak_order_fallback{};
 
-    inline constexpr __cmp_cust::_Partial_fallback
-    compare_partial_order_fallback{};
+    inline constexpr __compare::_Partial_fallback
+      compare_partial_order_fallback{};
   }
 
+  /// @cond undocumented
   namespace __detail
   {
     // [expos.only.func] synth-three-way
@@ -1239,6 +1243,7 @@  namespace std _GLIBCXX_VISIBILITY(default)
 	= decltype(__detail::__synth3way(std::declval<_Tp&>(),
 					 std::declval<_Up&>()));
   } // namespace __detail
+  /// @endcond
 #endif // __cpp_lib_three_way_comparison >= 201907L
 } // namespace std