[libcxx-commits] [libcxx] c75c654 - [libc++] Slightly improve constexpr test coverage for std::includes.

Arthur O'Dwyer via libcxx-commits libcxx-commits at lists.llvm.org
Fri Dec 4 14:54:51 PST 2020


Author: Arthur O'Dwyer
Date: 2020-12-04T17:53:53-05:00
New Revision: c75c6549ba7cadbbd51cae88d4ed286a6290a66b

URL: https://github.com/llvm/llvm-project/commit/c75c6549ba7cadbbd51cae88d4ed286a6290a66b
DIFF: https://github.com/llvm/llvm-project/commit/c75c6549ba7cadbbd51cae88d4ed286a6290a66b.diff

LOG: [libc++] Slightly improve constexpr test coverage for std::includes.

Differential Revision: https://reviews.llvm.org/D92255

Added: 
    

Modified: 
    libcxx/test/std/algorithms/alg.sorting/alg.set.operations/includes/includes.pass.cpp
    libcxx/test/std/algorithms/alg.sorting/alg.set.operations/includes/includes_comp.pass.cpp

Removed: 
    


################################################################################
diff  --git a/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/includes/includes.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/includes/includes.pass.cpp
index f8e8884085de..790b93c5ada5 100644
--- a/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/includes/includes.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/includes/includes.pass.cpp
@@ -20,21 +20,9 @@
 #include "test_macros.h"
 #include "test_iterators.h"
 
-#if TEST_STD_VER > 17
-TEST_CONSTEXPR bool test_constexpr() {
-    int ia[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4};
-    int ib[] = {2, 4};
-    int ic[] = {3, 3, 3, 3};
-
-    return  std::includes(std::begin(ia), std::end(ia), std::begin(ib), std::end(ib))
-        && !std::includes(std::begin(ia), std::end(ia), std::begin(ic), std::end(ic))
-           ;
-    }
-#endif
-
 template <class Iter1, class Iter2>
-void
-test()
+TEST_CONSTEXPR_CXX20
+void test()
 {
     int ia[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4};
     const unsigned sa = sizeof(ia)/sizeof(ia[0]);
@@ -62,7 +50,8 @@ test()
     assert(!std::includes(Iter1(ia), Iter1(ia+sa), Iter2(id), Iter2(id+4)));
 }
 
-int main(int, char**)
+TEST_CONSTEXPR_CXX20
+bool do_tests()
 {
     test<input_iterator<const int*>, input_iterator<const int*> >();
     test<input_iterator<const int*>, forward_iterator<const int*> >();
@@ -94,9 +83,14 @@ int main(int, char**)
     test<const int*, random_access_iterator<const int*> >();
     test<const int*, const int*>();
 
+    return true;
+}
+
+int main(int, char**)
+{
+    do_tests();
 #if TEST_STD_VER > 17
-   static_assert(test_constexpr());
+    static_assert(do_tests());
 #endif
-
-  return 0;
+    return 0;
 }

diff  --git a/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/includes/includes_comp.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/includes/includes_comp.pass.cpp
index 48bafcb3a84c..8c54f0df0f1c 100644
--- a/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/includes/includes_comp.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/includes/includes_comp.pass.cpp
@@ -21,51 +21,38 @@
 #include "test_macros.h"
 #include "test_iterators.h"
 
-#if TEST_STD_VER > 17
-TEST_CONSTEXPR bool test_constexpr() {
-    int ia[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4};
-    int ib[] = {2, 4};
-    int ic[] = {3, 3, 3, 3};
-
-    auto comp = [](int a, int b) {return a < b; };
-    return  std::includes(std::begin(ia), std::end(ia), std::begin(ib), std::end(ib), comp)
-        && !std::includes(std::begin(ia), std::end(ia), std::begin(ic), std::end(ic), comp)
-           ;
-    }
-#endif
-
-
 template <class Iter1, class Iter2>
-void
-test()
+TEST_CONSTEXPR_CXX20
+void test()
 {
-    int ia[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4};
+    int ia[] = {4, 4, 4, 4, 3, 3, 3, 2, 2, 1};
     const unsigned sa = sizeof(ia)/sizeof(ia[0]);
-    int ib[] = {2, 4};
+    int ib[] = {4, 2};
     const unsigned sb = sizeof(ib)/sizeof(ib[0]);
-    int ic[] = {1, 2};
+    int ic[] = {2, 1};
     const unsigned sc = sizeof(ic)/sizeof(ic[0]); ((void)sc);
     int id[] = {3, 3, 3, 3};
     const unsigned sd = sizeof(id)/sizeof(id[0]); ((void)sd);
 
-    assert(std::includes(Iter1(ia), Iter1(ia), Iter2(ib), Iter2(ib), std::less<int>()));
-    assert(!std::includes(Iter1(ia), Iter1(ia), Iter2(ib), Iter2(ib+1), std::less<int>()));
-    assert(std::includes(Iter1(ia), Iter1(ia+1), Iter2(ib), Iter2(ib), std::less<int>()));
-    assert(std::includes(Iter1(ia), Iter1(ia+sa), Iter2(ia), Iter2(ia+sa), std::less<int>()));
+    assert(std::includes(Iter1(ia), Iter1(ia), Iter2(ib), Iter2(ib), std::greater<int>()));
+    assert(!std::includes(Iter1(ia), Iter1(ia), Iter2(ib), Iter2(ib+1), std::greater<int>()));
+    assert(std::includes(Iter1(ia), Iter1(ia+1), Iter2(ib), Iter2(ib), std::greater<int>()));
+    assert(std::includes(Iter1(ia), Iter1(ia+sa), Iter2(ia), Iter2(ia+sa), std::greater<int>()));
 
-    assert(std::includes(Iter1(ia), Iter1(ia+sa), Iter2(ib), Iter2(ib+sb), std::less<int>()));
-    assert(!std::includes(Iter1(ib), Iter1(ib+sb), Iter2(ia), Iter2(ia+sa), std::less<int>()));
+    assert(std::includes(Iter1(ia), Iter1(ia+sa), Iter2(ib), Iter2(ib+sb), std::greater<int>()));
+    assert(!std::includes(Iter1(ib), Iter1(ib+sb), Iter2(ia), Iter2(ia+sa), std::greater<int>()));
 
-    assert(std::includes(Iter1(ia), Iter1(ia+2), Iter2(ic), Iter2(ic+2), std::less<int>()));
-    assert(!std::includes(Iter1(ia), Iter1(ia+2), Iter2(ib), Iter2(ib+2), std::less<int>()));
+    assert(std::includes(Iter1(ia+8), Iter1(ia+sa), Iter2(ic), Iter2(ic+sc), std::greater<int>()));
+    assert(!std::includes(Iter1(ia+8), Iter1(ia+sa), Iter2(ib), Iter2(ib+sb), std::greater<int>()));
 
-    assert(std::includes(Iter1(ia), Iter1(ia+sa), Iter2(id), Iter2(id+1), std::less<int>()));
-    assert(std::includes(Iter1(ia), Iter1(ia+sa), Iter2(id), Iter2(id+2), std::less<int>()));
-    assert(std::includes(Iter1(ia), Iter1(ia+sa), Iter2(id), Iter2(id+3), std::less<int>()));
-    assert(!std::includes(Iter1(ia), Iter1(ia+sa), Iter2(id), Iter2(id+4), std::less<int>()));
+    assert(std::includes(Iter1(ia), Iter1(ia+sa), Iter2(id), Iter2(id+1), std::greater<int>()));
+    assert(std::includes(Iter1(ia), Iter1(ia+sa), Iter2(id), Iter2(id+2), std::greater<int>()));
+    assert(std::includes(Iter1(ia), Iter1(ia+sa), Iter2(id), Iter2(id+3), std::greater<int>()));
+    assert(!std::includes(Iter1(ia), Iter1(ia+sa), Iter2(id), Iter2(id+4), std::greater<int>()));
 }
 
-int main(int, char**)
+TEST_CONSTEXPR_CXX20
+bool do_tests()
 {
     test<input_iterator<const int*>, input_iterator<const int*> >();
     test<input_iterator<const int*>, forward_iterator<const int*> >();
@@ -97,9 +84,14 @@ int main(int, char**)
     test<const int*, random_access_iterator<const int*> >();
     test<const int*, const int*>();
 
+    return true;
+}
+
+int main(int, char**)
+{
+    do_tests();
 #if TEST_STD_VER > 17
-   static_assert(test_constexpr());
+    static_assert(do_tests());
 #endif
-
-  return 0;
+    return 0;
 }


        


More information about the libcxx-commits mailing list