[libcxx-commits] [libcxx] [libc++] Implement `std::function_ref` (PR #186692)
via libcxx-commits
libcxx-commits at lists.llvm.org
Sat Jun 20 01:48:10 PDT 2026
================
@@ -0,0 +1,359 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// REQUIRES: std-at-least-c++26
+
+// template<auto f, class T>
+// constexpr function_ref(constant_wrapper<f>, cv T* obj) noexcept;
+
+#include <cassert>
+#include <functional>
+#include <utility>
+#include <type_traits>
+
+#include "test_macros.h"
+
+// Constraints: is-invocable-using<const F&, cv T*> is true.
+
+auto l1 = [](int*) {};
+auto l1_const = [](const int*) {};
+auto l1_noexcept = [](int*) noexcept {};
+auto l1_const_noexcept = [](const int*) noexcept {};
+auto l2 = [](int*, double) {};
+auto l2_const = [](const int*, double) {};
+auto l2_noexcept = [](int*, double) noexcept {};
+auto l2_const_noexcept = [](const int*, double) noexcept {};
+
+struct NonConstInvocable {
+ void operator()(int*) noexcept {}
+};
+
+struct A {
+ int i;
+ void f() {}
+ void f_const() const {}
+ void f_noexcept() noexcept {}
+ void f_const_noexcept() const noexcept {}
+ void g(int&) {}
+ void g_const(int&) const {}
+ void g_noexcept(int&) noexcept {}
+ void g_const_noexcept(int&) const noexcept {}
+};
+
+// non-const noexcept(false)
+static_assert(std::is_constructible_v<std::function_ref<void()>, std::constant_wrapper<l1>, int*>);
+static_assert(!std::is_constructible_v<std::function_ref<void()>, std::constant_wrapper<l1>, const int*>);
----------------
huixie90 wrote:
already has a test case
```
static_assert(!std::is_constructible_v<std::function_ref<void() const>, std::constant_wrapper<l1>, int*>);
```
https://github.com/llvm/llvm-project/pull/186692
More information about the libcxx-commits
mailing list