[llvm] ADT: Make function_ref constexpr (PR #155830)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 28 06:09:28 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-adt
Author: Matt Arsenault (arsenm)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/155830.diff
1 Files Affected:
- (modified) llvm/include/llvm/ADT/STLFunctionalExtras.h (+8-8)
``````````diff
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;
}
};
``````````
</details>
https://github.com/llvm/llvm-project/pull/155830
More information about the llvm-commits
mailing list