[libcxx-commits] [libcxx] [libc++] Implement std::move_only_function (P0288R9) (PR #94670)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Fri Nov 21 08:21:02 PST 2025


================
@@ -0,0 +1,42 @@
+//===----------------------------------------------------------------------===//
+//
+// 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, c++20
+
+#include <benchmark/benchmark.h>
+#include <functional>
+
+template <bool Opaque>
+static void BM_invoke(benchmark::State& state) {
+  std::move_only_function<void()> func = [] {};
+
+  for (auto _ : state) {
+    if constexpr (Opaque)
+      benchmark::DoNotOptimize(func);
+    func();
+  }
+}
+BENCHMARK(BM_invoke<false>)->Name("move_only_function call (transparent)");
+BENCHMARK(BM_invoke<true>)->Name("move_only_function call (opaque)");
+
+static void BM_move_assign(benchmark::State& state) {
+  std::move_only_function<void()> func1 = [] {};
----------------
ldionne wrote:

Should we also benchmark something that fits in the small buffer vs something that doesn't?

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


More information about the libcxx-commits mailing list