[libcxx-commits] [libcxx] P1223R5: `find_last` (PR #99312)

via libcxx-commits libcxx-commits at lists.llvm.org
Wed Jul 17 05:16:01 PDT 2024


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff 81704f6946894538ee1649a88688f604939de7f0 1140286c1e65418f45558739553ae46fed6aa7d5 --extensions ,cpp,inc,h -- libcxx/include/__algorithm/ranges_find_last.h libcxx/include/__algorithm/ranges_find_last_if.h libcxx/include/__algorithm/ranges_find_last_if_not.h libcxx/test/std/algorithms/alg.nonmodifying/alg.find.last/ranges.find_last.pass.cpp libcxx/test/std/algorithms/alg.nonmodifying/alg.find.last/ranges.find_last_if.pass.cpp libcxx/test/std/algorithms/alg.nonmodifying/alg.find.last/ranges.find_last_if_not.pass.cpp libcxx/include/__algorithm/ranges_find_if.h libcxx/include/algorithm libcxx/include/version libcxx/modules/std/algorithm.inc libcxx/test/libcxx/algorithms/ranges_robust_against_copying_comparators.pass.cpp libcxx/test/libcxx/algorithms/ranges_robust_against_copying_projections.pass.cpp libcxx/test/libcxx/diagnostics/algorithm.nodiscard.verify.cpp libcxx/test/std/algorithms/ranges_robust_against_dangling.pass.cpp libcxx/test/std/algorithms/ranges_robust_against_nonbool.compile.pass.cpp libcxx/test/std/algorithms/ranges_robust_against_proxy_iterators.pass.cpp libcxx/test/std/language.support/support.limits/support.limits.general/algorithm.version.compile.pass.cpp libcxx/test/std/language.support/support.limits/support.limits.general/version.version.compile.pass.cpp libcxx/test/std/library/description/conventions/customization.point.object/niebloid.compile.pass.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/libcxx/include/__algorithm/ranges_find_last.h b/libcxx/include/__algorithm/ranges_find_last.h
index 3aba821066..1ce056d719 100644
--- a/libcxx/include/__algorithm/ranges_find_last.h
+++ b/libcxx/include/__algorithm/ranges_find_last.h
@@ -14,10 +14,10 @@
 #include <__functional/invoke.h>
 #include <__functional/ranges_operations.h>
 #include <__iterator/concepts.h>
+#include <__iterator/indirectly_comparable.h>
 #include <__iterator/next.h>
 #include <__iterator/prev.h>
 #include <__iterator/projected.h>
-#include <__iterator/indirectly_comparable.h>
 #include <__ranges/access.h>
 #include <__ranges/concepts.h>
 #include <__ranges/subrange.h>
diff --git a/libcxx/include/algorithm b/libcxx/include/algorithm
index f36e396246..08da7e1ce5 100644
--- a/libcxx/include/algorithm
+++ b/libcxx/include/algorithm
@@ -101,26 +101,26 @@ namespace ranges {
            indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
     constexpr borrowed_iterator_t<R>
       find_if_not(R&& r, Pred pred, Proj proj = {});                                                      // since C++20
-																																																					//
+                                                                                                                                                                                                                                                                                                                                                                                                                                        //
   template<forward_iterator I, sentinel_for<I> S, class T, class Proj = identity>
     requires indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T*>
     constexpr subrange<I> find_last(I first, S last, const T& value, Proj proj = {});
-	template<forward_range R, class T, class Proj = identity>
-		requires
-			indirect_binary_predicate<ranges::equal_to, projected<iterator_t<R>, Proj>, const T*>
-		constexpr borrowed_subrange_t<R> find_last(R&& r, const T& value, Proj proj = {});
-	template<forward_iterator I, sentinel_for<I> S, class Proj = identity,
+        template<forward_range R, class T, class Proj = identity>
+                requires
+                        indirect_binary_predicate<ranges::equal_to, projected<iterator_t<R>, Proj>, const T*>
+                constexpr borrowed_subrange_t<R> find_last(R&& r, const T& value, Proj proj = {});
+        template<forward_iterator I, sentinel_for<I> S, class Proj = identity,
            indirect_unary_predicate<projected<I, Proj>> Pred>
-		constexpr subrange<I> find_last_if(I first, S last, Pred pred, Proj proj = {});
-	template<forward_range R, class Proj = identity,
+                constexpr subrange<I> find_last_if(I first, S last, Pred pred, Proj proj = {});
+        template<forward_range R, class Proj = identity,
            indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
-		constexpr borrowed_subrange_t<R> find_last_if(R&& r, Pred pred, Proj proj = {});
-	template<forward_iterator I, sentinel_for<I> S, class Proj = identity,
+                constexpr borrowed_subrange_t<R> find_last_if(R&& r, Pred pred, Proj proj = {});
+        template<forward_iterator I, sentinel_for<I> S, class Proj = identity,
            indirect_unary_predicate<projected<I, Proj>> Pred>
-		constexpr subrange<I> find_last_if_not(I first, S last, Pred pred, Proj proj = {});
-	template<forward_range R, class Proj = identity,
+                constexpr subrange<I> find_last_if_not(I first, S last, Pred pred, Proj proj = {});
+        template<forward_range R, class Proj = identity,
            indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
-		constexpr borrowed_subrange_t<R> find_last_if_not(R&& r, Pred pred, Proj proj = {});
+                constexpr borrowed_subrange_t<R> find_last_if_not(R&& r, Pred pred, Proj proj = {});
 
   template<class T, class Proj = identity,
            indirect_strict_weak_order<projected<const T*, Proj>> Comp = ranges::less>
diff --git a/libcxx/test/libcxx/algorithms/ranges_robust_against_copying_comparators.pass.cpp b/libcxx/test/libcxx/algorithms/ranges_robust_against_copying_comparators.pass.cpp
index 3c1cd606c6..6bac7deadf 100644
--- a/libcxx/test/libcxx/algorithms/ranges_robust_against_copying_comparators.pass.cpp
+++ b/libcxx/test/libcxx/algorithms/ranges_robust_against_copying_comparators.pass.cpp
@@ -120,10 +120,14 @@ constexpr bool all_the_algorithms()
     (void)std::ranges::find_if_not(first, last, UnaryTrue(&copies)); assert(copies == 0);
     (void)std::ranges::find_if_not(a, UnaryTrue(&copies)); assert(copies == 0);
 #if TEST_STD_VER >= 23
-    (void)std::ranges::find_last_if(first, last, UnaryTrue(&copies)); assert(copies == 0);
-    (void)std::ranges::find_last_if(a, UnaryTrue(&copies)); assert(copies == 0);
-    (void)std::ranges::find_last_if_not(first, last, UnaryTrue(&copies)); assert(copies == 0);
-    (void)std::ranges::find_last_if_not(a, UnaryTrue(&copies)); assert(copies == 0);
+    (void)std::ranges::find_last_if(first, last, UnaryTrue(&copies));
+    assert(copies == 0);
+    (void)std::ranges::find_last_if(a, UnaryTrue(&copies));
+    assert(copies == 0);
+    (void)std::ranges::find_last_if_not(first, last, UnaryTrue(&copies));
+    assert(copies == 0);
+    (void)std::ranges::find_last_if_not(a, UnaryTrue(&copies));
+    assert(copies == 0);
 #endif
     (void)std::ranges::for_each(first, last, UnaryVoid(&copies)); assert(copies == 1); copies = 0;
     (void)std::ranges::for_each(a, UnaryVoid(&copies)); assert(copies == 1); copies = 0;
diff --git a/libcxx/test/libcxx/algorithms/ranges_robust_against_copying_projections.pass.cpp b/libcxx/test/libcxx/algorithms/ranges_robust_against_copying_projections.pass.cpp
index 95f0893b14..bc71150c9e 100644
--- a/libcxx/test/libcxx/algorithms/ranges_robust_against_copying_projections.pass.cpp
+++ b/libcxx/test/libcxx/algorithms/ranges_robust_against_copying_projections.pass.cpp
@@ -116,12 +116,18 @@ constexpr bool all_the_algorithms()
     (void)std::ranges::find_if_not(first, last, UnaryTrue(), Proj(&copies)); assert(copies == 0);
     (void)std::ranges::find_if_not(a, UnaryTrue(), Proj(&copies)); assert(copies == 0);
 #if TEST_STD_VER >= 23
-    (void)std::ranges::find_last(first, last, value, Proj(&copies)); assert(copies == 0);
-    (void)std::ranges::find_last(a, value, Proj(&copies)); assert(copies == 0);
-    (void)std::ranges::find_last_if(first, last, UnaryTrue(), Proj(&copies)); assert(copies == 0);
-    (void)std::ranges::find_last_if(a, UnaryTrue(), Proj(&copies)); assert(copies == 0);
-    (void)std::ranges::find_last_if_not(first, last, UnaryTrue(), Proj(&copies)); assert(copies == 0);
-    (void)std::ranges::find_last_if_not(a, UnaryTrue(), Proj(&copies)); assert(copies == 0);
+    (void)std::ranges::find_last(first, last, value, Proj(&copies));
+    assert(copies == 0);
+    (void)std::ranges::find_last(a, value, Proj(&copies));
+    assert(copies == 0);
+    (void)std::ranges::find_last_if(first, last, UnaryTrue(), Proj(&copies));
+    assert(copies == 0);
+    (void)std::ranges::find_last_if(a, UnaryTrue(), Proj(&copies));
+    assert(copies == 0);
+    (void)std::ranges::find_last_if_not(first, last, UnaryTrue(), Proj(&copies));
+    assert(copies == 0);
+    (void)std::ranges::find_last_if_not(a, UnaryTrue(), Proj(&copies));
+    assert(copies == 0);
 #endif
     (void)std::ranges::for_each(first, last, UnaryVoid(), Proj(&copies)); assert(copies == 0);
     (void)std::ranges::for_each(a, UnaryVoid(), Proj(&copies)); assert(copies == 0);
diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.last/ranges.find_last.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.last/ranges.find_last.pass.cpp
index 967e7d6495..1ce4126b43 100644
--- a/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.last/ranges.find_last.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.last/ranges.find_last.pass.cpp
@@ -65,14 +65,14 @@ constexpr void test_iterators() {
   using ValueT = std::iter_value_t<It>;
   { // simple test
     {
-      ValueT a[] = {1, 2, 3, 4};
+      ValueT a[]                                       = {1, 2, 3, 4};
       std::same_as<std::ranges::subrange<It>> auto ret = std::ranges::find_last(It(a), Sent(It(a + 4)), 2);
       assert(base(ret.begin()) == a + 1);
       assert(*ret.begin() == 2);
     }
     {
-      ValueT a[] = {1, 2, 3, 4};
-      auto range = std::ranges::subrange(It(a), Sent(It(a + 4)));
+      ValueT a[]                                       = {1, 2, 3, 4};
+      auto range                                       = std::ranges::subrange(It(a), Sent(It(a + 4)));
       std::same_as<std::ranges::subrange<It>> auto ret = std::ranges::find_last(range, 2);
       assert(base(ret.begin()) == a + 1);
       assert(*ret.begin() == 2);
@@ -82,13 +82,13 @@ constexpr void test_iterators() {
   { // check that an empty range works
     {
       std::array<ValueT, 0> a = {};
-      auto ret = std::ranges::find_last(It(a.data()), Sent(It(a.data())), 1).begin();
+      auto ret                = std::ranges::find_last(It(a.data()), Sent(It(a.data())), 1).begin();
       assert(base(ret) == a.data());
     }
     {
       std::array<ValueT, 0> a = {};
-      auto range = std::ranges::subrange(It(a.data()), Sent(It(a.data())));
-      auto ret = std::ranges::find_last(range, 1).begin();
+      auto range              = std::ranges::subrange(It(a.data()), Sent(It(a.data())));
+      auto ret                = std::ranges::find_last(range, 1).begin();
       assert(base(ret) == a.data());
     }
   }
@@ -96,12 +96,12 @@ constexpr void test_iterators() {
   { // check that last is returned with no match
     {
       ValueT a[] = {1, 1, 1};
-      auto ret = std::ranges::find_last(a, a + 3, 0).begin();
+      auto ret   = std::ranges::find_last(a, a + 3, 0).begin();
       assert(ret == a + 3);
     }
     {
       ValueT a[] = {1, 1, 1};
-      auto ret = std::ranges::find_last(a, 0).begin();
+      auto ret   = std::ranges::find_last(a, 0).begin();
       assert(ret == a + 3);
     }
   }
@@ -143,7 +143,7 @@ constexpr bool test() {
         int comp;
         int other;
       };
-      S a[] = { {0, 0}, {0, 2}, {0, 1} };
+      S a[]    = {{0, 0}, {0, 2}, {0, 1}};
       auto ret = std::ranges::find_last(a, 0, &S::comp).begin();
       assert(ret == a + 2);
       assert(ret->comp == 0);
@@ -154,7 +154,7 @@ constexpr bool test() {
         int comp;
         int other;
       };
-      S a[] = { {0, 0}, {0, 2}, {0, 1} };
+      S a[]    = {{0, 0}, {0, 2}, {0, 1}};
       auto ret = std::ranges::find_last(a, a + 3, 0, &S::comp).begin();
       assert(ret == a + 2);
       assert(ret->comp == 0);
@@ -164,7 +164,7 @@ constexpr bool test() {
 
   {
     // check that an iterator is returned with a borrowing range
-    int a[] = {1, 2, 3, 4};
+    int a[]                                            = {1, 2, 3, 4};
     std::same_as<std::ranges::subrange<int*>> auto ret = std::ranges::find_last(std::views::all(a), 1);
     assert(ret.begin() == a);
     assert(*ret.begin() == 1);
@@ -173,17 +173,23 @@ constexpr bool test() {
   {
     // count invocations of the projection
     {
-      int a[] = {1, 2, 3, 4};
+      int a[]              = {1, 2, 3, 4};
       int projection_count = 0;
-      auto ret = std::ranges::find_last(a, a + 4, 2, [&](int i) { ++projection_count; return i; }).begin();
+      auto ret             = std::ranges::find_last(a, a + 4, 2, [&](int i) {
+                   ++projection_count;
+                   return i;
+                 }).begin();
       assert(ret == a + 1);
       assert(*ret == 2);
       assert(projection_count == 3);
     }
     {
-      int a[] = {1, 2, 3, 4};
+      int a[]              = {1, 2, 3, 4};
       int projection_count = 0;
-      auto ret = std::ranges::find_last(a, 2, [&](int i) { ++projection_count; return i; }).begin();
+      auto ret             = std::ranges::find_last(a, 2, [&](int i) {
+                   ++projection_count;
+                   return i;
+                 }).begin();
       assert(ret == a + 1);
       assert(*ret == 2);
       assert(projection_count == 3);
@@ -205,9 +211,7 @@ public:
           return size;
         }()) {}
 
-  bool operator==(const Comparable& other) const {
-    return comparable_data[other.index_] == comparable_data[index_];
-  }
+  bool operator==(const Comparable& other) const { return comparable_data[other.index_] == comparable_data[index_]; }
 
   friend bool operator==(const Comparable& lhs, long long rhs) { return comparable_data[lhs.index_] == rhs; }
 };
diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.last/ranges.find_last_if.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.last/ranges.find_last_if.pass.cpp
index e2fc64fd81..116ac5533d 100644
--- a/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.last/ranges.find_last_if.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.last/ranges.find_last_if.pass.cpp
@@ -43,7 +43,7 @@ static_assert(!HasFindLastIfIt<int*, int>);
 static_assert(!HasFindLastIfIt<int, int*>);
 
 template <class Pred>
-concept HasFindLastIfPred = requires(int* it, Pred pred) {std::ranges::find_last_if(it, it, pred); };
+concept HasFindLastIfPred = requires(int* it, Pred pred) { std::ranges::find_last_if(it, it, pred); };
 
 static_assert(!HasFindLastIfPred<IndirectUnaryPredicateNotCopyConstructible>);
 static_assert(!HasFindLastIfPred<IndirectUnaryPredicateNotPredicate>);
@@ -61,13 +61,14 @@ template <class It, class Sent = It>
 constexpr void test_iterators() {
   {
     int a[] = {1, 2, 3, 4};
-    std::same_as<std::ranges::subrange<It>> auto ret = std::ranges::find_last_if(It(a), Sent(It(a + 4)), [](int x) { return x == 4; });
+    std::same_as<std::ranges::subrange<It>> auto ret =
+        std::ranges::find_last_if(It(a), Sent(It(a + 4)), [](int x) { return x == 4; });
     assert(base(ret.begin()) == a + 3);
     assert(*ret.begin() == 4);
   }
   {
-    int a[] = {1, 2, 3, 4};
-    auto range = std::ranges::subrange(It(a), Sent(It(a + 4)));
+    int a[]                                          = {1, 2, 3, 4};
+    auto range                                       = std::ranges::subrange(It(a), Sent(It(a + 4)));
     std::same_as<std::ranges::subrange<It>> auto ret = std::ranges::find_last_if(range, [](int x) { return x == 4; });
     assert(base(ret.begin()) == a + 3);
     assert(*ret.begin() == 4);
@@ -94,11 +95,12 @@ constexpr bool test() {
     // check that projections are used properly and that they are called with the iterator directly
     {
       int a[] = {1, 2, 3, 4};
-      auto ret = std::ranges::find_last_if(a, a + 4, [&](int* i) { return i == a + 3; }, [](int& i) { return &i; }).begin();
+      auto ret =
+          std::ranges::find_last_if(a, a + 4, [&](int* i) { return i == a + 3; }, [](int& i) { return &i; }).begin();
       assert(ret == a + 3);
     }
     {
-      int a[] = {1, 2, 3, 4};
+      int a[]  = {1, 2, 3, 4};
       auto ret = std::ranges::find_last_if(a, [&](int* i) { return i == a + 3; }, [](int& i) { return &i; }).begin();
       assert(ret == a + 3);
     }
@@ -111,8 +113,8 @@ constexpr bool test() {
         int comp;
         int other;
       };
-      S a[] = { {0, 0}, {0, 2}, {0, 1} };
-      auto ret = std::ranges::find_last_if(a, [](int i){ return i == 0; }, &S::comp).begin();
+      S a[]    = {{0, 0}, {0, 2}, {0, 1}};
+      auto ret = std::ranges::find_last_if(a, [](int i) { return i == 0; }, &S::comp).begin();
       assert(ret == a + 2);
       assert(ret->comp == 0);
       assert(ret->other == 1);
@@ -122,7 +124,7 @@ constexpr bool test() {
         int comp;
         int other;
       };
-      S a[] = { {0, 0}, {0, 2}, {0, 1} };
+      S a[]    = {{0, 0}, {0, 2}, {0, 1}};
       auto ret = std::ranges::find_last_if(a, a + 3, [](int i) { return i == 0; }, &S::comp).begin();
       assert(ret == a + 2);
       assert(ret->comp == 0);
@@ -133,13 +135,13 @@ constexpr bool test() {
   {
     // check that end iterator is returned with no match
     {
-      int a[] = {1, 1, 1};
+      int a[]  = {1, 1, 1};
       auto ret = std::ranges::find_last_if(a, a + 3, [](int) { return false; }).begin();
       assert(ret == a + 3);
     }
     {
-      int a[] = {1, 1, 1};
-      auto ret = std::ranges::find_last_if(a, [](int){ return false; }).begin();
+      int a[]  = {1, 1, 1};
+      auto ret = std::ranges::find_last_if(a, [](int) { return false; }).begin();
       assert(ret == a + 3);
     }
   }
@@ -147,21 +149,24 @@ constexpr bool test() {
   {
     // check that ranges::dangling is returned
     [[maybe_unused]] std::same_as<std::ranges::dangling> auto ret =
-      std::ranges::find_last_if(std::array{1, 2}, [](int){ return false; });
+        std::ranges::find_last_if(std::array{1, 2}, [](int) { return false; });
   }
 
   {
     // check that an iterator is returned with a borrowing range
     int a[] = {1, 2, 3, 4};
-    std::same_as<std::ranges::subrange<int*>> auto ret = std::ranges::find_last_if(std::views::all(a), [](int){ return true; });
+    std::same_as<std::ranges::subrange<int*>> auto ret =
+        std::ranges::find_last_if(std::views::all(a), [](int) { return true; });
     assert(ret.begin() == a + 3);
     assert(*ret.begin() == 4);
   }
 
   {
     // check that std::invoke is used
-    struct S { int i; };
-    S a[] = { S{1}, S{3}, S{2} };
+    struct S {
+      int i;
+    };
+    S a[]                     = {S{1}, S{3}, S{2}};
     std::same_as<S*> auto ret = std::ranges::find_last_if(a, [](int) { return false; }, &S::i).begin();
     assert(ret == a + 3);
   }
@@ -169,24 +174,43 @@ constexpr bool test() {
   {
     // count projection and predicate invocation count
     {
-      int a[] = {1, 2, 3, 4};
-      int predicate_count = 0;
+      int a[]              = {1, 2, 3, 4};
+      int predicate_count  = 0;
       int projection_count = 0;
-      auto ret = std::ranges::find_last_if(a, a + 4,
-                                      [&](int i) { ++predicate_count; return i == 2; },
-                                      [&](int i) { ++projection_count; return i; }).begin();
+      auto ret =
+          std::ranges::find_last_if(
+              a,
+              a + 4,
+              [&](int i) {
+                ++predicate_count;
+                return i == 2;
+              },
+              [&](int i) {
+                ++projection_count;
+                return i;
+              })
+              .begin();
       assert(ret == a + 1);
       assert(*ret == 2);
       assert(predicate_count == 3);
       assert(projection_count == 3);
     }
     {
-      int a[] = {1, 2, 3, 4};
-      int predicate_count = 0;
+      int a[]              = {1, 2, 3, 4};
+      int predicate_count  = 0;
       int projection_count = 0;
-      auto ret = std::ranges::find_last_if(a,
-                                      [&](int i) { ++predicate_count; return i == 2; },
-                                      [&](int i) { ++projection_count; return i; }).begin();
+      auto ret =
+          std::ranges::find_last_if(
+              a,
+              [&](int i) {
+                ++predicate_count;
+                return i == 2;
+              },
+              [&](int i) {
+                ++projection_count;
+                return i;
+              })
+              .begin();
       assert(ret == a + 1);
       assert(*ret == 2);
       assert(predicate_count == 3);
@@ -197,13 +221,13 @@ constexpr bool test() {
   {
     // check that the return type of `iter::operator*` doesn't change
     {
-      NonConstComparable a[] = { NonConstComparable{} };
+      NonConstComparable a[] = {NonConstComparable{}};
       auto ret = std::ranges::find_last_if(a, a + 1, [](auto&& e) { return e == NonConstComparable{}; }).begin();
       assert(ret == a);
     }
     {
-      NonConstComparable a[] = { NonConstComparable{} };
-      auto ret = std::ranges::find_last_if(a, [](auto&& e) { return e == NonConstComparable{}; }).begin();
+      NonConstComparable a[] = {NonConstComparable{}};
+      auto ret               = std::ranges::find_last_if(a, [](auto&& e) { return e == NonConstComparable{}; }).begin();
       assert(ret == a);
     }
   }
@@ -211,13 +235,13 @@ constexpr bool test() {
   {
     // check that an empty range works
     {
-      std::array<int ,0> a = {};
-      auto ret = std::ranges::find_last_if(a.begin(), a.end(), [](int) { return true; }).begin();
+      std::array<int, 0> a = {};
+      auto ret             = std::ranges::find_last_if(a.begin(), a.end(), [](int) { return true; }).begin();
       assert(ret == a.begin());
     }
     {
       std::array<int, 0> a = {};
-      auto ret = std::ranges::find_last_if(a, [](int) { return true; }).begin();
+      auto ret             = std::ranges::find_last_if(a, [](int) { return true; }).begin();
       assert(ret == a.begin());
     }
   }
diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.last/ranges.find_last_if_not.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.last/ranges.find_last_if_not.pass.cpp
index 0a1e0d29f6..48337acc8e 100644
--- a/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.last/ranges.find_last_if_not.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.last/ranges.find_last_if_not.pass.cpp
@@ -45,7 +45,7 @@ static_assert(!HasFindLastIfNotIt<int*, int>);
 static_assert(!HasFindLastIfNotIt<int, int*>);
 
 template <class Pred>
-concept HasFindLastIfNotPred = requires(int* it, Pred pred) {std::ranges::find_last_if_not(it, it, pred); };
+concept HasFindLastIfNotPred = requires(int* it, Pred pred) { std::ranges::find_last_if_not(it, it, pred); };
 
 static_assert(!HasFindLastIfNotPred<IndirectUnaryPredicateNotCopyConstructible>);
 static_assert(!HasFindLastIfNotPred<IndirectUnaryPredicateNotPredicate>);
@@ -63,14 +63,16 @@ template <class It, class Sent = It>
 constexpr void test_iterators() {
   {
     int a[] = {1, 2, 3, 4};
-    std::same_as<std::ranges::subrange<It>> auto ret = std::ranges::find_last_if_not(It(a), Sent(It(a + 4)), [](int x) { return x != 4; });
+    std::same_as<std::ranges::subrange<It>> auto ret =
+        std::ranges::find_last_if_not(It(a), Sent(It(a + 4)), [](int x) { return x != 4; });
     assert(base(ret.begin()) == a + 3);
     assert(*ret.begin() == 4);
   }
   {
-    int a[] = {1, 2, 3, 4};
+    int a[]    = {1, 2, 3, 4};
     auto range = std::ranges::subrange(It(a), Sent(It(a + 4)));
-    std::same_as<std::ranges::subrange<It>> auto ret = std::ranges::find_last_if_not(range, [](int x) { return x != 4; });
+    std::same_as<std::ranges::subrange<It>> auto ret =
+        std::ranges::find_last_if_not(range, [](int x) { return x != 4; });
     assert(base(ret.begin()) == a + 3);
     assert(*ret.begin() == 4);
   }
@@ -95,13 +97,16 @@ constexpr bool test() {
   {
     // check that projections are used properly and that they are called with the iterator directly
     {
-      int a[] = {1, 2, 3, 4};
-      auto ret = std::ranges::find_last_if_not(a, a + 4, [&](int* i) { return i != a + 3; }, [](int& i) { return &i; }).begin();
+      int a[]  = {1, 2, 3, 4};
+      auto ret = std::ranges::find_last_if_not(
+                     a, a + 4, [&](int* i) { return i != a + 3; }, [](int& i) { return &i; })
+                     .begin();
       assert(ret == a + 3);
     }
     {
       int a[] = {1, 2, 3, 4};
-      auto ret = std::ranges::find_last_if_not(a, [&](int* i) { return i != a + 3; }, [](int& i) { return &i; }).begin();
+      auto ret =
+          std::ranges::find_last_if_not(a, [&](int* i) { return i != a + 3; }, [](int& i) { return &i; }).begin();
       assert(ret == a + 3);
     }
   }
@@ -113,8 +118,8 @@ constexpr bool test() {
         int comp;
         int other;
       };
-      S a[] = { {0, 0}, {0, 2}, {0, 1} };
-      auto ret = std::ranges::find_last_if_not(a, [](int i){ return i != 0; }, &S::comp).begin();
+      S a[]    = {{0, 0}, {0, 2}, {0, 1}};
+      auto ret = std::ranges::find_last_if_not(a, [](int i) { return i != 0; }, &S::comp).begin();
       assert(ret == a + 2);
       assert(ret->comp == 0);
       assert(ret->other == 1);
@@ -124,7 +129,7 @@ constexpr bool test() {
         int comp;
         int other;
       };
-      S a[] = { {0, 0}, {0, 2}, {0, 1} };
+      S a[]    = {{0, 0}, {0, 2}, {0, 1}};
       auto ret = std::ranges::find_last_if_not(a, a + 3, [](int i) { return i != 0; }, &S::comp).begin();
       assert(ret == a + 2);
       assert(ret->comp == 0);
@@ -135,13 +140,13 @@ constexpr bool test() {
   {
     // check that end iterator is returned with no match
     {
-      int a[] = {1, 1, 1};
+      int a[]  = {1, 1, 1};
       auto ret = std::ranges::find_last_if_not(a, a + 3, [](int) { return true; }).begin();
       assert(ret == a + 3);
     }
     {
-      int a[] = {1, 1, 1};
-      auto ret = std::ranges::find_last_if_not(a, [](int){ return true; }).begin();
+      int a[]  = {1, 1, 1};
+      auto ret = std::ranges::find_last_if_not(a, [](int) { return true; }).begin();
       assert(ret == a + 3);
     }
   }
@@ -149,21 +154,24 @@ constexpr bool test() {
   {
     // check that ranges::dangling is returned
     [[maybe_unused]] std::same_as<std::ranges::dangling> auto ret =
-      std::ranges::find_last_if_not(std::array{1, 2}, [](int){ return true; });
+        std::ranges::find_last_if_not(std::array{1, 2}, [](int) { return true; });
   }
 
   {
     // check that an iterator is returned with a borrowing range
     int a[] = {1, 2, 3, 4};
-    std::same_as<std::ranges::subrange<int*>> auto ret = std::ranges::find_last_if_not(std::views::all(a), [](int){ return false; });
+    std::same_as<std::ranges::subrange<int*>> auto ret =
+        std::ranges::find_last_if_not(std::views::all(a), [](int) { return false; });
     assert(ret.begin() == a + 3);
     assert(*ret.begin() == 4);
   }
 
   {
     // check that std::invoke is used
-    struct S { int i; };
-    S a[] = { S{1}, S{3}, S{2} };
+    struct S {
+      int i;
+    };
+    S a[]                     = {S{1}, S{3}, S{2}};
     std::same_as<S*> auto ret = std::ranges::find_last_if_not(a, [](int) { return true; }, &S::i).begin();
     assert(ret == a + 3);
   }
@@ -171,24 +179,43 @@ constexpr bool test() {
   {
     // count projection and predicate invocation count
     {
-      int a[] = {1, 2, 3, 4};
-      int predicate_count = 0;
+      int a[]              = {1, 2, 3, 4};
+      int predicate_count  = 0;
       int projection_count = 0;
-      auto ret = std::ranges::find_last_if_not(a, a + 4,
-                                      [&](int i) { ++predicate_count; return i != 2; },
-                                      [&](int i) { ++projection_count; return i; }).begin();
+      auto ret =
+          std::ranges::find_last_if_not(
+              a,
+              a + 4,
+              [&](int i) {
+                ++predicate_count;
+                return i != 2;
+              },
+              [&](int i) {
+                ++projection_count;
+                return i;
+              })
+              .begin();
       assert(ret == a + 1);
       assert(*ret == 2);
       assert(predicate_count == 3);
       assert(projection_count == 3);
     }
     {
-      int a[] = {1, 2, 3, 4};
-      int predicate_count = 0;
+      int a[]              = {1, 2, 3, 4};
+      int predicate_count  = 0;
       int projection_count = 0;
-      auto ret = std::ranges::find_last_if_not(a,
-                                      [&](int i) { ++predicate_count; return i != 2; },
-                                      [&](int i) { ++projection_count; return i; }).begin();
+      auto ret =
+          std::ranges::find_last_if_not(
+              a,
+              [&](int i) {
+                ++predicate_count;
+                return i != 2;
+              },
+              [&](int i) {
+                ++projection_count;
+                return i;
+              })
+              .begin();
       assert(ret == a + 1);
       assert(*ret == 2);
       assert(predicate_count == 3);
@@ -199,12 +226,13 @@ constexpr bool test() {
   {
     // check that the return type of `iter::operator*` doesn't change
     {
-      NonConstComparableLValue a[] = { NonConstComparableLValue{} };
-      auto ret = std::ranges::find_last_if_not(a, a + 1, [](auto&& e) { return e != NonConstComparableLValue{}; }).begin();
+      NonConstComparableLValue a[] = {NonConstComparableLValue{}};
+      auto ret =
+          std::ranges::find_last_if_not(a, a + 1, [](auto&& e) { return e != NonConstComparableLValue{}; }).begin();
       assert(ret == a);
     }
     {
-      NonConstComparableLValue a[] = { NonConstComparableLValue{} };
+      NonConstComparableLValue a[] = {NonConstComparableLValue{}};
       auto ret = std::ranges::find_last_if_not(a, [](auto&& e) { return e != NonConstComparableLValue{}; }).begin();
       assert(ret == a);
     }
@@ -213,13 +241,13 @@ constexpr bool test() {
   {
     // check that an empty range works
     {
-      std::array<int ,0> a = {};
-      auto ret = std::ranges::find_last_if_not(a.begin(), a.end(), [](int) { return true; }).begin();
+      std::array<int, 0> a = {};
+      auto ret             = std::ranges::find_last_if_not(a.begin(), a.end(), [](int) { return true; }).begin();
       assert(ret == a.begin());
     }
     {
       std::array<int, 0> a = {};
-      auto ret = std::ranges::find_last_if_not(a, [](int) { return true; }).begin();
+      auto ret             = std::ranges::find_last_if_not(a, [](int) { return true; }).begin();
       assert(ret == a.begin());
     }
   }

``````````

</details>


https://github.com/llvm/llvm-project/pull/99312


More information about the libcxx-commits mailing list