17
17
#include < stdint.h>
18
18
19
19
#include " subspace/fn/callable.h"
20
+ #include " subspace/macros/lifetimebound.h"
20
21
#include " subspace/mem/addressof.h"
21
22
#include " subspace/mem/forward.h"
22
23
#include " subspace/mem/never_value.h"
@@ -85,6 +86,14 @@ concept FunctionPointer =
85
86
{ (*f)(args...) } -> std::convertible_to<R>;
86
87
};
87
88
89
+ template <class T >
90
+ concept IsFunctionPointer = std::is_pointer_v<T> && std::is_function_v<std::remove_pointer_t <T>>;
91
+
92
+ template <class F >
93
+ concept ConvertsToFunctionPointer = requires (F f) {
94
+ { +f } -> IsFunctionPointer;
95
+ };
96
+
88
97
template <class F , class R , class ... Args>
89
98
concept CallableMut =
90
99
!FunctionPointer<F, R, Args...> && requires (F & f, Args... args) {
@@ -127,7 +136,7 @@ concept CallableConst =
127
136
template <class R , class ... CallArgs>
128
137
class [[sus_trivial_abi]] Fn<R(CallArgs...)> {
129
138
public:
130
- // / Construction from a function pointer or captureless lambda .
139
+ // / Construction from a function pointer.
131
140
// /
132
141
// / #[doc.overloads=ctor.fnpointer]
133
142
template <__private::FunctionPointer<R, CallArgs...> F>
@@ -137,16 +146,28 @@ class [[sus_trivial_abi]] Fn<R(CallArgs...)> {
137
146
invoke_ = &__private::Invoker<F>::template fnptr_call_const<R, CallArgs...>;
138
147
}
139
148
140
- // / Construction from a capturing lambda or other callable object .
149
+ // / Construction from a non- capturing lambda.
141
150
// /
142
151
// / #[doc.overloads=ctor.lambda]
143
152
template <__private::CallableMut<R, CallArgs...> F>
153
+ requires (__private::ConvertsToFunctionPointer<F>)
144
154
constexpr Fn (F&& object) noexcept {
145
155
storage_.object = ::sus::mem::addressof (object);
146
156
invoke_ = &__private::Invoker<
147
157
std::remove_reference_t <F>>::template object_call_const<R, CallArgs...>;
148
158
}
149
159
160
+ // / Construction from a capturing lambda or other callable object.
161
+ // /
162
+ // / #[doc.overloads=ctor.lambda]
163
+ template <__private::CallableMut<R, CallArgs...> F>
164
+ requires (!__private::ConvertsToFunctionPointer<F>)
165
+ constexpr Fn (F&& object sus_lifetimebound) noexcept {
166
+ storage_.object = ::sus::mem::addressof (object);
167
+ invoke_ = &__private::Invoker<
168
+ std::remove_reference_t <F>>::template object_call_const<R, CallArgs...>;
169
+ }
170
+
150
171
~Fn () noexcept = default ;
151
172
152
173
constexpr Fn (Fn&& o) noexcept
0 commit comments