[libcxx-commits] [libcxx] [libc++] [string_view] Remove operators made redundant by C++20 (PR #66206)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Sep 13 09:17:44 PDT 2023
================
@@ -776,7 +776,33 @@ template <ranges::contiguous_range _Range>
#endif
// [string.view.comparison]
-// operator ==
+
+#if _LIBCPP_STD_VER >= 20
+
+template<class _CharT, class _Traits>
+_LIBCPP_HIDE_FROM_ABI constexpr
+bool operator==(basic_string_view<_CharT, _Traits> __lhs,
+ type_identity_t<basic_string_view<_CharT, _Traits>> __rhs) noexcept {
+ if (__lhs.size() != __rhs.size()) return false;
+ return __lhs.compare(__rhs) == 0;
+}
+
+template <class _CharT, class _Traits>
+_LIBCPP_HIDE_FROM_ABI constexpr auto operator<=>(
+ basic_string_view<_CharT, _Traits> __lhs, type_identity_t<basic_string_view<_CharT, _Traits>> __rhs) noexcept {
+ if constexpr (requires { typename _Traits::comparison_category; }) {
+ // [string.view]/4
+ static_assert(
+ __comparison_category<typename _Traits::comparison_category>,
+ "return type is not a comparison category type");
+ return static_cast<typename _Traits::comparison_category>(__lhs.compare(__rhs) <=> 0);
+ } else {
+ return static_cast<weak_ordering>(__lhs.compare(__rhs) <=> 0);
+ }
+}
+
+#else
+
----------------
ldionne wrote:
`// operator ==`
https://github.com/llvm/llvm-project/pull/66206
More information about the libcxx-commits
mailing list