[libcxx-commits] [libcxx] [libc++] Optimize ranges::{for_each, for_each_n} for segmented iterators (PR #132896)

Peng Liu via libcxx-commits libcxx-commits at lists.llvm.org
Thu Apr 3 09:49:27 PDT 2025


================
@@ -0,0 +1,122 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+
+#include <algorithm>
+#include <cstddef>
+#include <deque>
+#include <list>
+#include <ranges>
+#include <string>
+#include <vector>
+
+#include <benchmark/benchmark.h>
+
+int main(int argc, char** argv) {
+  auto std_for_each   = [](auto first, auto last, auto f) { return std::for_each(first, last, f); };
+  auto std_for_each_n = [](auto first, auto n, auto f) { return std::for_each_n(first, n, f); };
+
+  // {std,ranges}::for_each
----------------
winner245 wrote:

Since I have two tests for `join_view`: `for_each` and `for_each_n`, I think you mean I should move the `for_each` test for `join_view` to `for_each.bench.cpp`, and move the `for_each_n` test for `join_view` to `for_each_n.bench.cpp`. Please let me know if I understand incorrectly. 

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


More information about the libcxx-commits mailing list