[libcxx-commits] [libcxx] [libc++][test] Augment ranges::{fill, fill_n, find} with missing tests (PR #121209)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Wed Feb 19 10:05:36 PST 2025


================
@@ -84,49 +101,15 @@ TEST_CONSTEXPR_CXX20 void test_bititer_with_custom_sized_types() {
 TEST_CONSTEXPR_CXX20 bool test() {
   types::for_each(types::forward_iterator_list<char*>(), Test<char>());
   types::for_each(types::forward_iterator_list<int*>(), Test<int>());
-  {   // test vector<bool>::iterator optimization
-    { // simple case
-      std::vector<bool> in(4, false);
-      std::vector<bool> expected(4, true);
-      std::fill(in.begin(), in.end(), true);
-      assert(in == expected);
-    }
-    { // partial byte in the front is not filled
-      std::vector<bool> in(8, false);
-      std::vector<bool> expected(8, true);
-      expected[0] = false;
-      expected[1] = false;
-      std::fill(in.begin() + 2, in.end(), true);
-      assert(in == expected);
-    }
-    { // partial byte in the back is not filled
-      std::vector<bool> in(8, false);
-      std::vector<bool> expected(8, true);
-      expected[6] = false;
-      expected[7] = false;
-      std::fill(in.begin(), in.end() - 2, true);
-      assert(in == expected);
-    }
-    { // partial byte in the front and back is not filled
-      std::vector<bool> in(16, false);
-      std::vector<bool> expected(16, true);
-      expected[0]  = false;
-      expected[1]  = false;
-      expected[14] = false;
-      expected[15] = false;
-      std::fill(in.begin() + 2, in.end() - 2, true);
-      assert(in == expected);
-    }
-    { // only a few bits of a byte are set
-      std::vector<bool> in(8, false);
-      std::vector<bool> expected(8, true);
-      expected[0] = false;
-      expected[1] = false;
-      expected[6] = false;
-      expected[7] = false;
-      std::fill(in.begin() + 2, in.end() - 2, true);
-      assert(in == expected);
-    }
+
+  { // Test vector<bool>::iterator optimization
+    assert(test_vector_bool(8));
+    assert(test_vector_bool(19));
+    assert(test_vector_bool(32));
+    assert(test_vector_bool(49));
+    assert(test_vector_bool(64));
+    assert(test_vector_bool(199));
+    assert(test_vector_bool(256));
   }
 
   test_bititer_with_custom_sized_types();
----------------
ldionne wrote:

I think it would make sense to inline this function here and perhaps to nest that inside the block above. Something like:

```c++
// Test vector<bool>::iterator optimization
{
  assert(test_vector_bool(8));
  ...

  // Make sure std::fill behaves properly with std::vector<bool> iterators with custom size types.
  // See https://github.com/llvm/llvm-project/pull/122410.
  {
    .. test cases in test_bititer_with_custom_sized_types() ..
  }
}

```

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


More information about the libcxx-commits mailing list