[llvm] ADT: Make function_ref constexpr (PR #155830)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 28 06:08:59 PDT 2025
https://github.com/arsenm created https://github.com/llvm/llvm-project/pull/155830
None
>From 3705823f7a1b7bad0b3f49d39b0a2d441652e81f Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Thu, 28 Aug 2025 21:57:02 +0900
Subject: [PATCH] ADT: Make function_ref constexpr
---
llvm/include/llvm/ADT/STLFunctionalExtras.h | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/llvm/include/llvm/ADT/STLFunctionalExtras.h b/llvm/include/llvm/ADT/STLFunctionalExtras.h
index a4d50dc3648be..2c8d4e07fa5c0 100644
--- a/llvm/include/llvm/ADT/STLFunctionalExtras.h
+++ b/llvm/include/llvm/ADT/STLFunctionalExtras.h
@@ -41,18 +41,18 @@ class LLVM_GSL_POINTER function_ref<Ret(Params...)> {
Ret (*callback)(intptr_t callable, Params ...params) = nullptr;
intptr_t callable;
- template<typename Callable>
- static Ret callback_fn(intptr_t callable, Params ...params) {
+ template <typename Callable>
+ static constexpr Ret callback_fn(intptr_t callable, Params... params) {
return (*reinterpret_cast<Callable*>(callable))(
std::forward<Params>(params)...);
}
public:
- function_ref() = default;
- function_ref(std::nullptr_t) {}
+ constexpr function_ref() = default;
+ constexpr function_ref(std::nullptr_t) {}
template <typename Callable>
- function_ref(
+ constexpr function_ref(
Callable &&callable LLVM_LIFETIME_BOUND,
// This is not the copy-constructor.
std::enable_if_t<!std::is_same<remove_cvref_t<Callable>,
@@ -65,13 +65,13 @@ class LLVM_GSL_POINTER function_ref<Ret(Params...)> {
: callback(callback_fn<std::remove_reference_t<Callable>>),
callable(reinterpret_cast<intptr_t>(&callable)) {}
- Ret operator()(Params ...params) const {
+ constexpr Ret operator()(Params... params) const {
return callback(callable, std::forward<Params>(params)...);
}
- explicit operator bool() const { return callback; }
+ explicit constexpr operator bool() const { return callback; }
- bool operator==(const function_ref<Ret(Params...)> &Other) const {
+ constexpr bool operator==(const function_ref<Ret(Params...)> &Other) const {
return callable == Other.callable;
}
};
More information about the llvm-commits
mailing list