]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Simplify std::string_view comparisons (LWG 3950)
authorJonathan Wakely <jwakely@redhat.com>
Fri, 10 Nov 2023 19:18:57 +0000 (19:18 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Sat, 11 Nov 2023 00:41:09 +0000 (00:41 +0000)
LWG 3950 points out that the comparisons of std::basic_string_view can
be simplified to just a single overload of operator== and a single
overload of operator<=>. Those overloads work fine for homogeneous
comparisons of two string view objects.

libstdc++-v3/ChangeLog:

* include/std/string_view (operator==, operator<=>): Remove
redundant overloads (LWG 3950).

libstdc++-v3/include/std/string_view

index 9deae25f71209513dab605a4ca5a512fa11c51b1..cf288ed3a366b29326abf17a347ed09e77c63675 100644 (file)
@@ -602,13 +602,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   // deduction and the other argument gets implicitly converted to the deduced
   // type (see N3766).
 
-  template<typename _CharT, typename _Traits>
-    [[nodiscard]]
-    constexpr bool
-    operator==(basic_string_view<_CharT, _Traits> __x,
-               basic_string_view<_CharT, _Traits> __y) noexcept
-    { return __x.size() == __y.size() && __x.compare(__y) == 0; }
-
   template<typename _CharT, typename _Traits>
     [[nodiscard]]
     constexpr bool
@@ -618,14 +611,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     { return __x.size() == __y.size() && __x.compare(__y) == 0; }
 
 #if __cpp_lib_three_way_comparison
-  template<typename _CharT, typename _Traits>
-    [[nodiscard]]
-    constexpr auto
-    operator<=>(basic_string_view<_CharT, _Traits> __x,
-               basic_string_view<_CharT, _Traits> __y) noexcept
-    -> decltype(__detail::__char_traits_cmp_cat<_Traits>(0))
-    { return __detail::__char_traits_cmp_cat<_Traits>(__x.compare(__y)); }
-
   template<typename _CharT, typename _Traits>
     [[nodiscard]]
     constexpr auto
@@ -635,6 +620,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     -> decltype(__detail::__char_traits_cmp_cat<_Traits>(0))
     { return __detail::__char_traits_cmp_cat<_Traits>(__x.compare(__y)); }
 #else
+  template<typename _CharT, typename _Traits>
+    [[nodiscard]]
+    constexpr bool
+    operator==(basic_string_view<_CharT, _Traits> __x,
+              basic_string_view<_CharT, _Traits> __y) noexcept
+    { return __x.size() == __y.size() && __x.compare(__y) == 0; }
+
   template<typename _CharT, typename _Traits>
     [[nodiscard]]
     constexpr bool