Implement std::ranges::less without std::less
authorJonathan Wakely <jwakely@redhat.com>
Fri, 18 Oct 2019 11:27:26 +0000 (12:27 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Fri, 18 Oct 2019 11:27:26 +0000 (12:27 +0100)
* include/bits/range_cmp.h (ranges::less::operator()): Inline the
logic from std::less::operator() to remove the dependency on it.

From-SVN: r277150

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/range_cmp.h

index 1aeeb880a69eb06b63b8edea0b20dff56c5af974..c37bbd05eb66786bd4e1e2f4f4ac5fa8ead3c338 100644 (file)
@@ -1,3 +1,8 @@
+2019-10-18  Jonathan Wakely  <jwakely@redhat.com>
+
+       * include/bits/range_cmp.h (ranges::less::operator()): Inline the
+       logic from std::less::operator() to remove the dependency on it.
+
 2019-10-17  Jonathan Wakely  <jwakely@redhat.com>
 
        * doc/doxygen/user.cfg.in (INPUT): Add new C++17 and C++20 headers.
index 3e5bb8847ab4b0c0853b7f0edd28d49d9323b37a..a77fd5274b9555d28d3af6becc1ff98e4e009588 100644 (file)
@@ -121,10 +121,19 @@ namespace ranges
       noexcept(noexcept(std::declval<_Tp>() < std::declval<_Up>()))
       {
        if constexpr (__detail::__less_builtin_ptr_cmp<_Tp, _Up>)
-         return std::less<const volatile void*>{}(
-             static_cast<const volatile void*>(std::forward<_Tp>(__t)),
+         {
+#ifdef __cpp_lib_is_constant_evaluated
+           if (std::is_constant_evaluated())
+             return __t < __u;
+#endif
+           auto __x = reinterpret_cast<__UINTPTR_TYPE__>(
+             static_cast<const volatile void*>(std::forward<_Tp>(__t)));
+           auto __y = reinterpret_cast<__UINTPTR_TYPE__>(
              static_cast<const volatile void*>(std::forward<_Up>(__u)));
-       return std::forward<_Tp>(__t) < std::forward<_Up>(__u);
+           return __x < __y;
+         }
+       else
+         return std::forward<_Tp>(__t) < std::forward<_Up>(__u);
       }
 
     using is_transparent = __is_transparent;