[libcxx-commits] [libcxx] 3e02c8e - [libc++] [test] Add ranges_robust_against_copying_*.pass.cpp
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Mar 17 14:36:28 PDT 2022
Author: Nikolas Klauser
Date: 2022-03-17T22:36:18+01:00
New Revision: 3e02c8e2fc03fa7f2a599ec5a528f1025fcd102e
URL: https://github.com/llvm/llvm-project/commit/3e02c8e2fc03fa7f2a599ec5a528f1025fcd102e
DIFF: https://github.com/llvm/llvm-project/commit/3e02c8e2fc03fa7f2a599ec5a528f1025fcd102e.diff
LOG: [libc++] [test] Add ranges_robust_against_copying_*.pass.cpp
This tests the same QoI issue as the existing STL Classic test,
but for the Ranges algorithms. Also, do the same thing for all
the algorithms that take projections.
I found a few missing algorithms and added them to the existing test, too. `std::find_first_of` currently fails; I should look at why that is (and in particular, what is it doing weird that //makes// it inconsistent with the entire rest of libc++?).
Reviewed By: ldionne, #libc
Spies: libcxx-commits
Differential Revision: https://reviews.llvm.org/D121265
Added:
libcxx/test/libcxx/algorithms/ranges_robust_against_copying_comparators.pass.cpp
libcxx/test/libcxx/algorithms/ranges_robust_against_copying_projections.pass.cpp
Modified:
libcxx/test/libcxx/algorithms/robust_against_copying_comparators.pass.cpp
Removed:
################################################################################
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
new file mode 100644
index 0000000000000..2ce0a7793d0aa
--- /dev/null
+++ b/libcxx/test/libcxx/algorithms/ranges_robust_against_copying_comparators.pass.cpp
@@ -0,0 +1,241 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17
+// UNSUPPORTED: libcpp-has-no-incomplete-ranges
+
+// <algorithm>
+
+// this test checks that the comparators in the ranges algorithms aren't copied/moved
+
+#include <algorithm>
+#include <cassert>
+#include <cstddef>
+
+#include "test_macros.h"
+
+struct Less {
+ int *copies_;
+ constexpr explicit Less(int *copies) : copies_(copies) {}
+ constexpr Less(const Less& rhs) : copies_(rhs.copies_) { *copies_ += 1; }
+ constexpr Less& operator=(const Less&) = default;
+ constexpr bool operator()(void*, void*) const { return false; }
+};
+
+struct Equal {
+ int *copies_;
+ constexpr explicit Equal(int *copies) : copies_(copies) {}
+ constexpr Equal(const Equal& rhs) : copies_(rhs.copies_) { *copies_ += 1; }
+ constexpr Equal& operator=(const Equal&) = default;
+ constexpr bool operator()(void*, void*) const { return true; }
+};
+
+struct UnaryVoid {
+ int *copies_;
+ constexpr explicit UnaryVoid(int *copies) : copies_(copies) {}
+ constexpr UnaryVoid(const UnaryVoid& rhs) : copies_(rhs.copies_) { *copies_ += 1; }
+ constexpr UnaryVoid& operator=(const UnaryVoid&) = default;
+ constexpr void operator()(void*) const {}
+};
+
+struct UnaryTrue {
+ int *copies_;
+ constexpr explicit UnaryTrue(int *copies) : copies_(copies) {}
+ constexpr UnaryTrue(const UnaryTrue& rhs) : copies_(rhs.copies_) { *copies_ += 1; }
+ constexpr UnaryTrue& operator=(const UnaryTrue&) = default;
+ constexpr bool operator()(void*) const { return true; }
+};
+
+struct NullaryValue {
+ int *copies_;
+ constexpr explicit NullaryValue(int *copies) : copies_(copies) {}
+ constexpr NullaryValue(const NullaryValue& rhs) : copies_(rhs.copies_) { *copies_ += 1; }
+ constexpr NullaryValue& operator=(const NullaryValue&) = default;
+ constexpr std::nullptr_t operator()() const { return nullptr; }
+};
+
+struct UnaryTransform {
+ int *copies_;
+ constexpr explicit UnaryTransform(int *copies) : copies_(copies) {}
+ constexpr UnaryTransform(const UnaryTransform& rhs) : copies_(rhs.copies_) { *copies_ += 1; }
+ constexpr UnaryTransform& operator=(const UnaryTransform&) = default;
+ constexpr std::nullptr_t operator()(void*) const { return nullptr; }
+};
+
+struct BinaryTransform {
+ int *copies_;
+ constexpr explicit BinaryTransform(int *copies) : copies_(copies) {}
+ constexpr BinaryTransform(const BinaryTransform& rhs) : copies_(rhs.copies_) { *copies_ += 1; }
+ constexpr BinaryTransform& operator=(const BinaryTransform&) = default;
+ constexpr std::nullptr_t operator()(void*, void*) const { return nullptr; }
+};
+
+constexpr bool all_the_algorithms()
+{
+ void *a[10] = {};
+ void *b[10] = {};
+ //void *half[5] = {};
+ void **first = a;
+ //void **mid = a+5;
+ void **last = a+10;
+ void **first2 = b;
+ //void **mid2 = b+5;
+ void **last2 = b+10;
+ //void *value = nullptr;
+ //int count = 1;
+
+ int copies = 0;
+ //(void)std::ranges::adjacent_find(first, last, Equal(&copies)); assert(copies == 0);
+ //(void)std::ranges::adjacent_find(a, Equal(&copies)); assert(copies == 0);
+ //(void)std::ranges::all_of(first, last, UnaryTrue(&copies)); assert(copies == 0);
+ //(void)std::ranges::all_of(a, UnaryTrue(&copies)); assert(copies == 0);
+ //(void)std::ranges::any_of(first, last, UnaryTrue(&copies)); assert(copies == 0);
+ //(void)std::ranges::any_of(a, UnaryTrue(&copies)); assert(copies == 0);
+ //(void)std::ranges::binary_search(first, last, value, Less(&copies)); assert(copies == 0);
+ //(void)std::ranges::binary_search(a, value, Less(&copies)); assert(copies == 0);
+ //(void)std::ranges::clamp(value, value, value, Less(&copies)); assert(copies == 0);
+ //(void)std::ranges::count_if(first, last, UnaryTrue(&copies)); assert(copies == 0);
+ //(void)std::ranges::count_if(a, UnaryTrue(&copies)); assert(copies == 0);
+ //(void)std::ranges::copy_if(first, last, first2, UnaryTrue(&copies)); assert(copies == 0);
+ //(void)std::ranges::copy_if(a, first2, UnaryTrue(&copies)); assert(copies == 0);
+#if TEST_STD_VER > 20
+ //(void)std::ranges::ends_with(first, last, first2, last2, Equal(&copies)); assert(copies == 0);
+#endif
+ //(void)std::ranges::equal(first, last, first2, last2, Equal(&copies)); assert(copies == 0);
+ //(void)std::ranges::equal(a, b, Equal(&copies)); assert(copies == 0);
+ //(void)std::ranges::equal_range(first, last, value, Less(&copies)); assert(copies == 0);
+ //(void)std::ranges::equal_range(a, value, Less(&copies)); assert(copies == 0);
+ //(void)std::ranges::find_end(first, last, first2, mid2, Equal(&copies)); assert(copies == 0);
+ //(void)std::ranges::find_end(a, b, Equal(&copies)); assert(copies == 0);
+ //(void)std::ranges::find_first_of(first, last, first2, last2, Equal(&copies)); assert(copies == 0);
+ //(void)std::ranges::find_first_of(a, b, Equal(&copies)); assert(copies == 0);
+ (void)std::ranges::find_if(first, last, UnaryTrue(&copies)); assert(copies == 0);
+ (void)std::ranges::find_if(a, UnaryTrue(&copies)); assert(copies == 0);
+ (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);
+ //(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;
+ //(void)std::ranges::for_each_n(first, count, UnaryVoid(&copies)); assert(copies == 0);
+ //(void)std::ranges::generate(first, last, NullaryValue(&copies)); assert(copies == 0);
+ //(void)std::ranges::generate(a, NullaryValue(&copies)); assert(copies == 0);
+ //(void)std::ranges::generate_n(first, count, NullaryValue(&copies)); assert(copies == 0);
+ //(void)std::ranges::includes(first, last, first2, last2, Less(&copies)); assert(copies == 0);
+ //(void)std::ranges::includes(a, b, Less(&copies)); assert(copies == 0);
+ //(void)std::ranges::is_heap(first, last, Less(&copies)); assert(copies == 0);
+ //(void)std::ranges::is_heap(a, Less(&copies)); assert(copies == 0);
+ //(void)std::ranges::is_heap_until(first, last, Less(&copies)); assert(copies == 0);
+ //(void)std::ranges::is_heap_until(a, Less(&copies)); assert(copies == 0);
+ //(void)std::ranges::is_partitioned(first, last, UnaryTrue(&copies)); assert(copies == 0);
+ //(void)std::ranges::is_partitioned(a, UnaryTrue(&copies)); assert(copies == 0);
+ //(void)std::ranges::is_permutation(first, last, first2, last2, Equal(&copies)); assert(copies == 0);
+ //(void)std::ranges::is_permutation(a, b, Equal(&copies)); assert(copies == 0);
+ //(void)std::ranges::is_sorted(first, last, Less(&copies)); assert(copies == 0);
+ //(void)std::ranges::is_sorted(a, Less(&copies)); assert(copies == 0);
+ //(void)std::ranges::is_sorted_until(first, last, Less(&copies)); assert(copies == 0);
+ //(void)std::ranges::is_sorted_until(a, Less(&copies)); assert(copies == 0);
+ //if (!std::is_constant_evaluated()) { (void)std::ranges::inplace_merge(first, mid, last, Less(&copies)); assert(copies == 0); }
+ //if (!std::is_constant_evaluated()) { (void)std::ranges::inplace_merge(a, mid, Less(&copies)); assert(copies == 0); }
+ //(void)std::ranges::lexicographical_compare(first, last, first2, last2, Less(&copies)); assert(copies == 0);
+ //(void)std::ranges::lexicographical_compare(a, b, Less(&copies)); assert(copies == 0);
+ //(void)std::ranges::lower_bound(first, last, value, Less(&copies)); assert(copies == 0);
+ //(void)std::ranges::lower_bound(a, value, Less(&copies)); assert(copies == 0);
+ //(void)std::ranges::make_heap(first, last, Less(&copies)); assert(copies == 0);
+ //(void)std::ranges::make_heap(a, Less(&copies)); assert(copies == 0);
+ //(void)std::ranges::max(value, value, Less(&copies)); assert(copies == 0);
+ //(void)std::ranges::max({ value, value }, Less(&copies)); assert(copies == 0);
+ //(void)std::ranges::max(a, Less(&copies)); assert(copies == 0);
+ (void)std::ranges::max_element(first, last, Less(&copies)); assert(copies == 0);
+ (void)std::ranges::max_element(a, Less(&copies)); assert(copies == 0);
+ //(void)std::ranges::merge(first, mid, mid, last, first2, Less(&copies)); assert(copies == 0);
+ //(void)std::ranges::merge(half, half, b, Less(&copies)); assert(copies == 0);
+ //(void)std::ranges::min(value, value, Less(&copies)); assert(copies == 0);
+ //(void)std::ranges::min({ value, value }, Less(&copies)); assert(copies == 0);
+ //(void)std::ranges::min(a, Less(&copies)); assert(copies == 0);
+ (void)std::ranges::min_element(first, last, Less(&copies)); assert(copies == 0);
+ (void)std::ranges::min_element(a, Less(&copies)); assert(copies == 0);
+ //(void)std::ranges::minmax(value, value, Less(&copies)); assert(copies == 0);
+ //(void)std::ranges::minmax({ value, value }, Less(&copies)); assert(copies == 0);
+ //(void)std::ranges::minmax(a, Less(&copies)); assert(copies == 0);
+ //(void)std::ranges::minmax_element(first, last, Less(&copies)); assert(copies == 0);
+ //(void)std::ranges::minmax_element(a, Less(&copies)); assert(copies == 0);
+ (void)std::ranges::mismatch(first, last, first2, last2, Equal(&copies)); assert(copies == 0);
+ (void)std::ranges::mismatch(a, b, Equal(&copies)); assert(copies == 0);
+ //(void)std::ranges::next_permutation(first, last, Less(&copies)); assert(copies == 0);
+ //(void)std::ranges::next_permutation(a, Less(&copies)); assert(copies == 0);
+ //(void)std::ranges::none_of(first, last, UnaryTrue(&copies)); assert(copies == 0);
+ //(void)std::ranges::none_of(a, UnaryTrue(&copies)); assert(copies == 0);
+ //(void)std::ranges::nth_element(first, mid, last, Less(&copies)); assert(copies == 0);
+ //(void)std::ranges::nth_element(a, mid, Less(&copies)); assert(copies == 0);
+ //(void)std::ranges::partial_sort(first, mid, last, Less(&copies)); assert(copies == 0);
+ //(void)std::ranges::partial_sort(a, mid, Less(&copies)); assert(copies == 0);
+ //(void)std::ranges::partial_sort_copy(first, last, first2, mid2, Less(&copies)); assert(copies == 0);
+ //(void)std::ranges::partial_sort_copy(a, b, Less(&copies)); assert(copies == 0);
+ //(void)std::ranges::partition(first, last, UnaryTrue(&copies)); assert(copies == 0);
+ //(void)std::ranges::partition(a, UnaryTrue(&copies)); assert(copies == 0);
+ //(void)std::ranges::partition_copy(first, last, first2, last2, UnaryTrue(&copies)); assert(copies == 0);
+ //(void)std::ranges::partition_copy(a, first2, last2, UnaryTrue(&copies)); assert(copies == 0);
+ //(void)std::ranges::partition_point(first, last, UnaryTrue(&copies)); assert(copies == 0);
+ //(void)std::ranges::partition_point(a, UnaryTrue(&copies)); assert(copies == 0);
+ //(void)std::ranges::pop_heap(first, last, Less(&copies)); assert(copies == 0);
+ //(void)std::ranges::pop_heap(a, Less(&copies)); assert(copies == 0);
+ //(void)std::ranges::prev_permutation(first, last, Less(&copies)); assert(copies == 0);
+ //(void)std::ranges::prev_permutation(a, Less(&copies)); assert(copies == 0);
+ //(void)std::ranges::push_heap(first, last, Less(&copies)); assert(copies == 0);
+ //(void)std::ranges::push_heap(a, Less(&copies)); assert(copies == 0);
+ //(void)std::ranges::remove_copy_if(first, last, first2, UnaryTrue(&copies)); assert(copies == 0);
+ //(void)std::ranges::remove_copy_if(a, first2, UnaryTrue(&copies)); assert(copies == 0);
+ //(void)std::ranges::remove_if(first, last, UnaryTrue(&copies)); assert(copies == 0);
+ //(void)std::ranges::remove_if(a, UnaryTrue(&copies)); assert(copies == 0);
+ //(void)std::ranges::replace_copy_if(first, last, first2, UnaryTrue(&copies), value); assert(copies == 0);
+ //(void)std::ranges::replace_copy_if(a, first2, UnaryTrue(&copies), value); assert(copies == 0);
+ //(void)std::ranges::replace_if(first, last, UnaryTrue(&copies), value); assert(copies == 0);
+ //(void)std::ranges::replace_if(a, UnaryTrue(&copies), value); assert(copies == 0);
+ //(void)std::ranges::search(first, last, first2, mid2, Equal(&copies)); assert(copies == 0);
+ //(void)std::ranges::search(a, b, Equal(&copies)); assert(copies == 0);
+ //(void)std::ranges::search_n(first, last, count, value, Equal(&copies)); assert(copies == 0);
+ //(void)std::ranges::search_n(a, count, value, Equal(&copies)); assert(copies == 0);
+ //(void)std::ranges::set_
diff erence(first, mid, mid, last, first2, Less(&copies)); assert(copies == 0);
+ //(void)std::ranges::set_
diff erence(a, b, first2, Less(&copies)); assert(copies == 0);
+ //(void)std::ranges::set_intersection(first, mid, mid, last, first2, Less(&copies)); assert(copies == 0);
+ //(void)std::ranges::set_intersection(a, b, first2, Less(&copies)); assert(copies == 0);
+ //(void)std::ranges::set_symmetric_
diff erence(first, mid, mid, last, first2, Less(&copies)); assert(copies == 0);
+ //(void)std::ranges::set_symmetric_
diff erence(a, b, first2, Less(&copies)); assert(copies == 0);
+ //(void)std::ranges::set_union(first, mid, mid, last, first2, Less(&copies)); assert(copies == 0);
+ //(void)std::ranges::set_union(a, b, first2, Less(&copies)); assert(copies == 0);
+ //(void)std::ranges::sort(first, last, Less(&copies)); assert(copies == 0);
+ //(void)std::ranges::sort(a, Less(&copies)); assert(copies == 0);
+ //(void)std::ranges::sort_heap(first, last, Less(&copies)); assert(copies == 0);
+ //(void)std::ranges::sort_heap(a, Less(&copies)); assert(copies == 0);
+ //if (!std::is_constant_evaluated()) { (void)std::ranges::stable_partition(first, last, UnaryTrue(&copies)); assert(copies == 0); }
+ //if (!std::is_constant_evaluated()) { (void)std::ranges::stable_partition(a, UnaryTrue(&copies)); assert(copies == 0); }
+ //if (!std::is_constant_evaluated()) { (void)std::ranges::stable_sort(first, last, Less(&copies)); assert(copies == 0); }
+ //if (!std::is_constant_evaluated()) { (void)std::ranges::stable_sort(a, Less(&copies)); assert(copies == 0); }
+#if TEST_STD_VER > 20
+ //(void)std::ranges::starts_with(first, last, first2, last2, Equal(&copies)); assert(copies == 0);
+#endif
+ //(void)std::ranges::transform(first, last, first2, UnaryTransform(&copies)); assert(copies == 0);
+ //(void)std::ranges::transform(a, first2, UnaryTransform(&copies)); assert(copies == 0);
+ //(void)std::ranges::transform(first, mid, mid, last, first2, BinaryTransform(&copies)); assert(copies == 0);
+ //(void)std::ranges::transform(a, b, first2, BinaryTransform(&copies)); assert(copies == 0);
+ //(void)std::ranges::unique(first, last, Equal(&copies)); assert(copies == 0);
+ //(void)std::ranges::unique(a, Equal(&copies)); assert(copies == 0);
+ //(void)std::ranges::unique_copy(first, last, first2, Equal(&copies)); assert(copies == 0);
+ //(void)std::ranges::unique_copy(a, first2, Equal(&copies)); assert(copies == 0);
+ //(void)std::ranges::upper_bound(first, last, value, Less(&copies)); assert(copies == 0);
+ //(void)std::ranges::upper_bound(a, value, Less(&copies)); assert(copies == 0);
+
+ return true;
+}
+
+int main(int, char**)
+{
+ all_the_algorithms();
+ static_assert(all_the_algorithms());
+
+ return 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
new file mode 100644
index 0000000000000..e0b27644bade4
--- /dev/null
+++ b/libcxx/test/libcxx/algorithms/ranges_robust_against_copying_projections.pass.cpp
@@ -0,0 +1,232 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17
+// UNSUPPORTED: libcpp-has-no-incomplete-ranges
+
+// <algorithm>
+
+// this test checks that the projections in the ranges algorithms aren't copied/moved
+
+#include <algorithm>
+#include <cassert>
+#include <cstddef>
+
+#include "test_macros.h"
+
+struct T {};
+
+struct Proj {
+ int *copies_;
+ constexpr explicit Proj(int *copies) : copies_(copies) {}
+ constexpr Proj(const Proj& rhs) : copies_(rhs.copies_) { *copies_ += 1; }
+ constexpr Proj& operator=(const Proj&) = default;
+ constexpr void *operator()(T) const { return nullptr; }
+};
+
+struct Less {
+ constexpr bool operator()(void*, void*) const { return false; }
+};
+
+struct Equal {
+ constexpr bool operator()(void*, void*) const { return true; }
+};
+
+struct UnaryVoid {
+ constexpr void operator()(void*) const {}
+};
+
+struct UnaryTrue {
+ constexpr bool operator()(void*) const { return true; }
+};
+
+struct NullaryValue {
+ constexpr std::nullptr_t operator()() const { return nullptr; }
+};
+
+struct UnaryTransform {
+ constexpr T operator()(void*) const { return T(); }
+};
+
+struct BinaryTransform {
+ constexpr T operator()(void*, void*) const { return T(); }
+};
+
+constexpr bool all_the_algorithms()
+{
+ T a[10] = {};
+ T b[10] = {};
+ //T half[5] = {};
+ T *first = a;
+ //T *mid = a+5;
+ T *last = a+10;
+ T *first2 = b;
+ //T *mid2 = b+5;
+ T *last2 = b+10;
+ void *value = nullptr;
+ //int count = 1;
+
+ int copies = 0;
+ //(void)std::ranges::adjacent_find(first, last, Equal(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::adjacent_find(a, Equal(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::all_of(first, last, UnaryTrue(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::all_of(a, UnaryTrue(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::any_of(first, last, UnaryTrue(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::any_of(a, UnaryTrue(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::binary_search(first, last, value, Less(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::binary_search(a, value, Less(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::clamp(T(), T(), T(), Less(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::count(first, last, value, Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::count(a, value, Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::count_if(first, last, UnaryTrue(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::count_if(a, UnaryTrue(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::copy_if(first, last, first2, UnaryTrue(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::copy_if(a, first2, UnaryTrue(), Proj(&copies)); assert(copies == 0);
+#if TEST_STD_VER > 20
+ //(void)std::ranges::ends_with(first, last, first2, last2, Equal(), Proj(&copies), Proj(&copies)); assert(copies == 0);
+#endif
+ //(void)std::ranges::equal(first, last, first2, last2, Equal(), Proj(&copies), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::equal(a, b, Equal(), Proj(&copies), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::equal_range(first, last, value, Less(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::equal_range(a, value, Less(), Proj(&copies)); assert(copies == 0);
+ (void)std::ranges::find(first, last, value, Proj(&copies)); assert(copies == 0);
+ (void)std::ranges::find(a, value, Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::find_end(first, last, first2, mid2, Equal(), Proj(&copies), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::find_end(a, b, Equal(), Proj(&copies), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::find_first_of(first, last, first2, last2, Equal(), Proj(&copies), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::find_first_of(a, b, Equal(), Proj(&copies), Proj(&copies)); assert(copies == 0);
+ (void)std::ranges::find_if(first, last, UnaryTrue(), Proj(&copies)); assert(copies == 0);
+ (void)std::ranges::find_if(a, UnaryTrue(), Proj(&copies)); assert(copies == 0);
+ (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);
+ //(void)std::ranges::for_each(first, last, UnaryVoid(), Proj(&copies)); assert(copies == 1); copies = 0;
+ //(void)std::ranges::for_each(a, UnaryVoid(), Proj(&copies)); assert(copies == 1); copies = 0;
+ //(void)std::ranges::for_each_n(first, count, UnaryVoid(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::includes(first, last, first2, last2, Less(), Proj(&copies), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::includes(a, b, Less(), Proj(&copies), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::is_heap(first, last, Less(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::is_heap(a, Less(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::is_heap_until(first, last, Less(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::is_heap_until(a, Less(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::is_partitioned(first, last, UnaryTrue(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::is_partitioned(a, UnaryTrue(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::is_permutation(first, last, first2, last2, Equal(), Proj(&copies), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::is_permutation(a, b, Equal(), Proj(&copies), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::is_sorted(first, last, Less(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::is_sorted(a, Less(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::is_sorted_until(first, last, Less(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::is_sorted_until(a, Less(), Proj(&copies)); assert(copies == 0);
+ //if (!std::is_constant_evaluated()) { (void)std::ranges::inplace_merge(first, mid, last, Less(), Proj(&copies)); assert(copies == 0); }
+ //if (!std::is_constant_evaluated()) { (void)std::ranges::inplace_merge(a, mid, Less(), Proj(&copies)); assert(copies == 0); }
+ //(void)std::ranges::lexicographical_compare(first, last, first2, last2, Less(), Proj(&copies), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::lexicographical_compare(a, b, Less(), Proj(&copies), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::lower_bound(first, last, value, Less(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::lower_bound(a, value, Less(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::make_heap(first, last, Less(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::make_heap(a, Less(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::max(T(), T(), Less(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::max({ T(), T() }, Less(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::max(a, Less(), Proj(&copies)); assert(copies == 0);
+ (void)std::ranges::max_element(first, last, Less(), Proj(&copies)); assert(copies == 0);
+ (void)std::ranges::max_element(a, Less(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::merge(first, mid, mid, last, first2, Less(), Proj(&copies), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::merge(half, half, b, Less(), Proj(&copies), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::min(T(), T(), Less(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::min({ T(), T() }, Less(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::min(a, Less(), Proj(&copies)); assert(copies == 0);
+ (void)std::ranges::min_element(first, last, Less(), Proj(&copies)); assert(copies == 0);
+ (void)std::ranges::min_element(a, Less(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::minmax(T(), T(), Less(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::minmax({ T(), T() }, Less(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::minmax(a, Less(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::minmax_element(first, last, Less(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::minmax_element(a, Less(), Proj(&copies)); assert(copies == 0);
+ (void)std::ranges::mismatch(first, last, first2, last2, Equal(), Proj(&copies), Proj(&copies)); assert(copies == 0);
+ (void)std::ranges::mismatch(a, b, Equal(), Proj(&copies), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::next_permutation(first, last, Less(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::next_permutation(a, Less(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::none_of(first, last, UnaryTrue(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::none_of(a, UnaryTrue(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::nth_element(first, mid, last, Less(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::nth_element(a, mid, Less(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::partial_sort(first, mid, last, Less(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::partial_sort(a, mid, Less(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::partial_sort_copy(first, last, first2, mid2, Less(), Proj(&copies), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::partial_sort_copy(a, b, Less(), Proj(&copies), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::partition(first, last, UnaryTrue(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::partition(a, UnaryTrue(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::partition_copy(first, last, first2, last2, UnaryTrue(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::partition_copy(a, first2, last2, UnaryTrue(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::partition_point(first, last, UnaryTrue(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::partition_point(a, UnaryTrue(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::pop_heap(first, last, Less(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::pop_heap(a, Less(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::prev_permutation(first, last, Less(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::prev_permutation(a, Less(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::push_heap(first, last, Less(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::push_heap(a, Less(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::remove_copy(first, last, first2, value, Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::remove_copy(a, first2, value, Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::remove_copy_if(first, last, first2, UnaryTrue(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::remove_copy_if(a, first2, UnaryTrue(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::remove(first, last, value, Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::remove(a, value, Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::remove_if(first, last, UnaryTrue(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::remove_if(a, UnaryTrue(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::replace_copy(first, last, first2, value, T(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::replace_copy(a, first2, value, T(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::replace_copy_if(first, last, first2, UnaryTrue(), T(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::replace_copy_if(a, first2, UnaryTrue(), T(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::replace(first, last, value, T(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::replace(a, value, T(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::replace_if(first, last, UnaryTrue(), T(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::replace_if(a, UnaryTrue(), T(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::search(first, last, first2, mid2, Equal(), Proj(&copies), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::search(a, b, Equal(), Proj(&copies), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::search_n(first, last, count, value, Equal(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::search_n(a, count, value, Equal(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::set_
diff erence(first, mid, mid, last, first2, Less(), Proj(&copies), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::set_
diff erence(a, b, first2, Less(), Proj(&copies), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::set_intersection(first, mid, mid, last, first2, Less(), Proj(&copies), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::set_intersection(a, b, first2, Less(), Proj(&copies), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::set_symmetric_
diff erence(first, mid, mid, last, first2, Less(), Proj(&copies), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::set_symmetric_
diff erence(a, b, first2, Less(), Proj(&copies), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::set_union(first, mid, mid, last, first2, Less(), Proj(&copies), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::set_union(a, b, first2, Less(), Proj(&copies), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::sort(first, last, Less(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::sort(a, Less(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::sort_heap(first, last, Less(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::sort_heap(a, Less(), Proj(&copies)); assert(copies == 0);
+ //if (!std::is_constant_evaluated()) { (void)std::ranges::stable_partition(first, last, UnaryTrue(), Proj(&copies)); assert(copies == 0); }
+ //if (!std::is_constant_evaluated()) { (void)std::ranges::stable_partition(a, UnaryTrue(), Proj(&copies)); assert(copies == 0); }
+ //if (!std::is_constant_evaluated()) { (void)std::ranges::stable_sort(first, last, Less(), Proj(&copies)); assert(copies == 0); }
+ //if (!std::is_constant_evaluated()) { (void)std::ranges::stable_sort(a, Less(), Proj(&copies)); assert(copies == 0); }
+#if TEST_STD_VER > 20
+ //(void)std::ranges::starts_with(first, last, first2, last2, Equal(), Proj(&copies), Proj(&copies)); assert(copies == 0);
+#endif
+ //(void)std::ranges::transform(first, last, first2, UnaryTransform(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::transform(a, first2, UnaryTransform(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::transform(first, mid, mid, last, first2, BinaryTransform(), Proj(&copies), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::transform(a, b, first2, BinaryTransform(), Proj(&copies), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::unique(first, last, Equal(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::unique(a, Equal(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::unique_copy(first, last, first2, Equal(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::unique_copy(a, first2, Equal(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::upper_bound(first, last, value, Less(), Proj(&copies)); assert(copies == 0);
+ //(void)std::ranges::upper_bound(a, value, Less(), Proj(&copies)); assert(copies == 0);
+
+ return true;
+}
+
+int main(int, char**)
+{
+ all_the_algorithms();
+ static_assert(all_the_algorithms());
+
+ return 0;
+}
diff --git a/libcxx/test/libcxx/algorithms/robust_against_copying_comparators.pass.cpp b/libcxx/test/libcxx/algorithms/robust_against_copying_comparators.pass.cpp
index aa3d34ada4c57..7fbdf1f17536f 100644
--- a/libcxx/test/libcxx/algorithms/robust_against_copying_comparators.pass.cpp
+++ b/libcxx/test/libcxx/algorithms/robust_against_copying_comparators.pass.cpp
@@ -10,6 +10,7 @@
#include <algorithm>
#include <cassert>
+#include <compare>
#include <cstddef>
#include "test_macros.h"
@@ -70,6 +71,16 @@ struct BinaryTransform {
TEST_CONSTEXPR std::nullptr_t operator()(void*, void*) const { return nullptr; }
};
+#if TEST_STD_VER > 17
+struct ThreeWay {
+ int *copies_;
+ constexpr explicit ThreeWay(int *copies) : copies_(copies) {}
+ constexpr ThreeWay(const ThreeWay& rhs) : copies_(rhs.copies_) { *copies_ += 1; }
+ constexpr ThreeWay& operator=(const ThreeWay&) = default;
+ constexpr std::strong_ordering operator()(void*, void*) const { return std::strong_ordering::equal; }
+};
+#endif
+
TEST_CONSTEXPR_CXX20 bool all_the_algorithms()
{
void *a[10] = {};
@@ -94,12 +105,14 @@ TEST_CONSTEXPR_CXX20 bool all_the_algorithms()
(void)std::clamp(value, value, value, Less(&copies)); assert(copies == 0);
#endif
(void)std::count_if(first, last, UnaryTrue(&copies)); assert(copies == 0);
+ (void)std::copy_if(first, last, first2, UnaryTrue(&copies)); assert(copies == 0);
(void)std::equal(first, last, first2, Equal(&copies)); assert(copies == 0);
#if TEST_STD_VER > 11
(void)std::equal(first, last, first2, last2, Equal(&copies)); assert(copies == 0);
#endif
(void)std::equal_range(first, last, value, Less(&copies)); assert(copies == 0);
(void)std::find_end(first, last, first2, mid2, Equal(&copies)); assert(copies == 0);
+ //(void)std::find_first_of(first, last, first2, last2, Equal(&copies)); assert(copies == 0);
(void)std::find_if(first, last, UnaryTrue(&copies)); assert(copies == 0);
(void)std::find_if_not(first, last, UnaryTrue(&copies)); assert(copies == 0);
(void)std::for_each(first, last, UnaryVoid(&copies)); assert(copies == 1); copies = 0;
@@ -120,7 +133,9 @@ TEST_CONSTEXPR_CXX20 bool all_the_algorithms()
(void)std::is_sorted_until(first, last, Less(&copies)); assert(copies == 0);
if (!TEST_IS_CONSTANT_EVALUATED) { (void)std::inplace_merge(first, mid, last, Less(&copies)); assert(copies == 0); }
(void)std::lexicographical_compare(first, last, first2, last2, Less(&copies)); assert(copies == 0);
- // TODO: lexicographical_compare_three_way
+#if TEST_STD_VER > 17
+ //(void)std::lexicographical_compare_three_way(first, last, first2, last2, ThreeWay(&copies)); assert(copies == 0);
+#endif
(void)std::lower_bound(first, last, value, Less(&copies)); assert(copies == 0);
(void)std::make_heap(first, last, Less(&copies)); assert(copies == 0);
(void)std::max(value, value, Less(&copies)); assert(copies == 0);
More information about the libcxx-commits
mailing list