[libcxx-commits] [libcxx] [libc++] Fix {deque, vector}::append_range assuming too much about the types (PR #162438)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Thu Oct 9 06:41:25 PDT 2025


================
@@ -399,6 +399,53 @@ void sequence_container_benchmarks(std::string container) {
           st.ResumeTiming();
         }
       });
+
+#if TEST_STD_VER >= 23
+    for (auto gen : generators)
+      bench("append_range()" + tostr(gen), [gen](auto& state) {
+        auto const size = state.range(0);
+        std::vector<ValueType> in;
+        std::generate_n(std::back_inserter(in), size, gen);
+        DoNotOptimizeData(in);
+
+        Container c;
+        DoNotOptimizeData(c);
+        for (auto _ : state) {
+          c.append_range(in);
+          DoNotOptimizeData(c);
+
+          state.PauseTiming();
+          c.clear();
+          state.ResumeTiming();
+        }
+      });
+#endif
+  }
+
+  /////////////////////////
+  // Prepending elements
+  /////////////////////////
+  static constexpr bool has_prepend_range = requires(Container c, std::vector<ValueType> v) { c.prepend_range(v); };
+
+  if constexpr (has_prepend_range) {
+    for (auto gen : generators)
+      bench("prepend_range()" + tostr(gen), [gen](auto& state) {
----------------
ldionne wrote:

```suggestion
      bench("prepend_range() (empty)" + tostr(gen), [gen](auto& state) {
```

Same comment as above.

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


More information about the libcxx-commits mailing list