[libcxx-commits] [libcxx] [libc++] Implement `std::function_ref` (PR #186692)
via libcxx-commits
libcxx-commits at lists.llvm.org
Wed May 13 03:08:59 PDT 2026
================
@@ -0,0 +1,184 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// This header is unguarded on purpose. This header is an implementation detail of function_ref.h
+// and generates multiple versions of std::function_ref
+
+#include <__assert>
+#include <__config>
+#include <__functional/function_ref_common.h>
+#include <__functional/invoke.h>
+#include <__memory/addressof.h>
+#include <__type_traits/conditional.h>
+#include <__type_traits/invoke.h>
+#include <__type_traits/is_const.h>
+#include <__type_traits/is_convertible.h>
+#include <__type_traits/is_function.h>
+#include <__type_traits/is_member_pointer.h>
+#include <__type_traits/is_object.h>
+#include <__type_traits/is_pointer.h>
+#include <__type_traits/is_reference.h>
+#include <__type_traits/is_same.h>
+#include <__type_traits/is_void.h>
+#include <__type_traits/remove_cvref.h>
+#include <__type_traits/remove_pointer.h>
+#include <__type_traits/remove_reference.h>
+#include <__utility/constant_wrapper.h>
+#include <__utility/forward.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+# pragma GCC system_header
+#endif
+
+#ifndef _LIBCPP___FUNCTIONAL_FUNCTION_REF_H
+# error This header should only be included from function_ref.h
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 26
+
+template <class...>
+class function_ref;
+
+template <bool _NoExcept2, bool _NoExcept1, class _Rp, class... _ArgTypes>
+struct __is_convertible_from_specialization<
+ function_ref<_Rp(_ArgTypes...) _LIBCPP_FUNCTION_REF_CV noexcept(_NoExcept2)>,
+ _NoExcept1,
+ _Rp,
+ _ArgTypes...>
+ : is_convertible<_Rp (&)(_ArgTypes...) noexcept(_NoExcept2), _Rp (&)(_ArgTypes...) noexcept(_NoExcept1)> {};
----------------
Kim-J-Smith wrote:
https://eel.is/c++draft/func.wrap#ref.ctor-2
> template<class F>
static constexpr bool is-convertible-from-specialization = see below;
> If F denotes a specialization function_ref<R(Args...) cv2 noexcept(noex2)> for some placeholders cv2 and noex2, is-convertible-from-specialization<F> is equal to:
is_convertible_v<R(&)(Args...) noexcept(noex2), R(&)(Args...) noexcept(noex)> **&&
is_convertible_v<int cv&, int cv2&>**.
Otherwise, is-convertible-from-specialization<F> is false[.](https://eel.is/c++draft/func.wrap#ref.ctor-2.sentence-2)
It seems that the second judgment condition is missing here?
https://github.com/llvm/llvm-project/pull/186692
More information about the libcxx-commits
mailing list