On 17/10/19 16:40 +0100, Jonathan Wakely wrote:
Define std::identity, std::ranges::equal_to, std::ranges::not_equal_to,
std::ranges::greater, std::ranges::less, std::ranges::greater_equal and
std::ranges::less_equal.

        * include/Makefile.am: Add new header.
        * include/Makefile.in: Regenerate.
        * include/bits/range_cmp.h: New header for C++20 function objects.
        * include/std/functional: Include new header.
        * testsuite/20_util/function_objects/identity/1.cc: New test.
        * testsuite/20_util/function_objects/range.cmp/equal_to.cc: New test.
        * testsuite/20_util/function_objects/range.cmp/greater.cc: New test.
        * testsuite/20_util/function_objects/range.cmp/greater_equal.cc: New
        test.
        * testsuite/20_util/function_objects/range.cmp/less.cc: New test.
        * testsuite/20_util/function_objects/range.cmp/less_equal.cc: New test.
        * testsuite/20_util/function_objects/range.cmp/not_equal_to.cc: New
        test.

This removes the dependency on std::less, so that ranges::less doesn't
need to instantiate another template, and <bits/range_cmp.h> doesn't
need to include <bits/stl_function.h>. Various components in <iterator>
and <ranges> require ranges::less but don't necessarily need to depend
on everything in <bits/stl_function.h>, so this removes unnecessary
coupling between the new ranges world and the old STL world.

Tested powerpc64le-linux, committed to trunk.

commit cc43d4d492ecc64cc3aac8b47aae759942d9e57f
Author: Jonathan Wakely <jwak...@redhat.com>
Date:   Thu Oct 17 18:56:46 2019 +0100

    Implement std::ranges::less without std::less
    
            * include/bits/range_cmp.h (ranges::less::operator()): Inline the
            logic from std::less::operator() to remove the dependency on it.

diff --git a/libstdc++-v3/include/bits/range_cmp.h b/libstdc++-v3/include/bits/range_cmp.h
index 3e5bb8847ab..a77fd5274b9 100644
--- a/libstdc++-v3/include/bits/range_cmp.h
+++ b/libstdc++-v3/include/bits/range_cmp.h
@@ -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;

Reply via email to