@@ -87,7 +87,8 @@ concept FunctionPointer =
87
87
};
88
88
89
89
template <class T >
90
- concept IsFunctionPointer = std::is_pointer_v<T> && std::is_function_v<std::remove_pointer_t <T>>;
90
+ concept IsFunctionPointer =
91
+ std::is_pointer_v<T> && std::is_function_v<std::remove_pointer_t <T>>;
91
92
92
93
template <class F >
93
94
concept ConvertsToFunctionPointer = requires (F f) {
@@ -149,18 +150,18 @@ class [[sus_trivial_abi]] Fn<R(CallArgs...)> {
149
150
// / Construction from a non-capturing lambda.
150
151
// /
151
152
// / #[doc.overloads=ctor.lambda]
152
- template <__private::CallableMut <R, CallArgs...> F>
153
+ template <__private::CallableConst <R, CallArgs...> F>
153
154
requires (__private::ConvertsToFunctionPointer<F>)
154
- constexpr Fn (F&& object) noexcept {
155
+ constexpr Fn (F&& object sus_lifetimebound ) noexcept {
155
156
storage_.object = ::sus::mem::addressof (object);
156
157
invoke_ = &__private::Invoker<
157
158
std::remove_reference_t <F>>::template object_call_const<R, CallArgs...>;
158
159
}
159
160
160
161
// / Construction from a capturing lambda or other callable object.
161
162
// /
162
- // / #[doc.overloads=ctor.lambda ]
163
- template <__private::CallableMut <R, CallArgs...> F>
163
+ // / #[doc.overloads=ctor.capturelambda ]
164
+ template <__private::CallableConst <R, CallArgs...> F>
164
165
requires (!__private::ConvertsToFunctionPointer<F>)
165
166
constexpr Fn (F&& object sus_lifetimebound) noexcept {
166
167
storage_.object = ::sus::mem::addressof (object);
@@ -170,12 +171,12 @@ class [[sus_trivial_abi]] Fn<R(CallArgs...)> {
170
171
171
172
~Fn () noexcept = default ;
172
173
173
- constexpr Fn (Fn&& o) noexcept
174
+ constexpr Fn (Fn&& o sus_lifetimebound ) noexcept
174
175
: storage_ (o.storage_ ),
175
176
invoke_ (::sus::mem::replace_ptr (o.invoke_ , nullptr )) {
176
177
::sus::check (invoke_); // Catch use-after-move.
177
178
}
178
- constexpr Fn& operator =(Fn&& o) noexcept {
179
+ constexpr Fn& operator =(Fn&& o sus_lifetimebound ) noexcept {
179
180
storage_ = o.storage_ ;
180
181
invoke_ = ::sus::mem::replace_ptr (o.invoke_ , nullptr );
181
182
::sus::check (invoke_); // Catch use-after-move.
@@ -206,12 +207,16 @@ class [[sus_trivial_abi]] Fn<R(CallArgs...)> {
206
207
}
207
208
208
209
// / `sus::construct::From` trait implementation.
210
+ // /
211
+ // / Fn satisfies `From<T>` for the same types that it is constructible from:
212
+ // / function pointers that exactly match its own signature, and const-callable
213
+ // / objects (lambdas) that are compatible with its signature.
209
214
constexpr static auto from (
210
215
__private::FunctionPointer<R, CallArgs...> auto ptr) noexcept {
211
216
return Fn (ptr);
212
217
}
213
- template <__private::CallableMut <R, CallArgs...> F>
214
- constexpr static auto from (F&& object) noexcept {
218
+ template <__private::CallableConst <R, CallArgs...> F>
219
+ constexpr static auto from (F&& object sus_lifetimebound ) noexcept {
215
220
return Fn (::sus::forward<F>(object));
216
221
}
217
222
@@ -280,11 +285,23 @@ class [[sus_trivial_abi]] FnMut<R(CallArgs...)> {
280
285
invoke_ = &__private::Invoker<F>::template fnptr_call_mut<R, CallArgs...>;
281
286
}
282
287
283
- // / Construction from a capturing lambda or other callable object .
288
+ // / Construction from a non- capturing lambda.
284
289
// /
285
290
// / #[doc.overloads=ctor.lambda]
286
291
template <__private::CallableMut<R, CallArgs...> F>
287
- constexpr FnMut (F&& object) noexcept {
292
+ requires (__private::ConvertsToFunctionPointer<F>)
293
+ constexpr FnMut (F&& object sus_lifetimebound) noexcept {
294
+ storage_.object = ::sus::mem::addressof (object);
295
+ invoke_ = &__private::Invoker<
296
+ std::remove_reference_t <F>>::template object_call_mut<R, CallArgs...>;
297
+ }
298
+
299
+ // / Construction from a capturing lambda or other callable object.
300
+ // /
301
+ // / #[doc.overloads=ctor.capturelambda]
302
+ template <__private::CallableMut<R, CallArgs...> F>
303
+ requires (!__private::ConvertsToFunctionPointer<F>)
304
+ constexpr FnMut (F&& object sus_lifetimebound) noexcept {
288
305
storage_.object = ::sus::mem::addressof (object);
289
306
invoke_ = &__private::Invoker<
290
307
std::remove_reference_t <F>>::template object_call_mut<R, CallArgs...>;
@@ -295,20 +312,20 @@ class [[sus_trivial_abi]] FnMut<R(CallArgs...)> {
295
312
// / Since Fn is callable, FnMut is already constructible from it, but
296
313
// / this constructor avoids extra indirections being inserted when converting,
297
314
// / since otherwise an extra invoker call would be introduced.
298
- constexpr FnMut (Fn<R (CallArgs...)>&& o) noexcept
315
+ constexpr FnMut (Fn<R (CallArgs...)>&& o sus_lifetimebound ) noexcept
299
316
: storage_ (o.storage_ ),
300
317
invoke_ (::sus::mem::replace_ptr (o.invoke_ , nullptr )) {
301
318
::sus::check (invoke_); // Catch use-after-move.
302
319
}
303
320
304
321
~FnMut () noexcept = default ;
305
322
306
- constexpr FnMut (FnMut&& o) noexcept
323
+ constexpr FnMut (FnMut&& o sus_lifetimebound ) noexcept
307
324
: storage_ (o.storage_ ),
308
325
invoke_ (::sus::mem::replace_ptr (o.invoke_ , nullptr )) {
309
326
::sus::check (invoke_); // Catch use-after-move.
310
327
}
311
- constexpr FnMut& operator =(FnMut&& o) noexcept {
328
+ constexpr FnMut& operator =(FnMut&& o sus_lifetimebound ) noexcept {
312
329
storage_ = o.storage_ ;
313
330
invoke_ = ::sus::mem::replace_ptr (o.invoke_ , nullptr );
314
331
::sus::check (invoke_); // Catch use-after-move.
@@ -339,12 +356,16 @@ class [[sus_trivial_abi]] FnMut<R(CallArgs...)> {
339
356
}
340
357
341
358
// / `sus::construct::From` trait implementation.
359
+ // /
360
+ // / FnMut satisfies `From<T>` for the same types that it is constructible
361
+ // / from: function pointers that exactly match its own signature, and callable
362
+ // / objects (lambdas) that are compatible with its signature.
342
363
constexpr static auto from (
343
364
__private::FunctionPointer<R, CallArgs...> auto ptr) noexcept {
344
365
return FnMut (ptr);
345
366
}
346
367
template <__private::CallableMut<R, CallArgs...> F>
347
- constexpr static auto from (F&& object) noexcept {
368
+ constexpr static auto from (F&& object sus_lifetimebound ) noexcept {
348
369
return FnMut (::sus::forward<F>(object));
349
370
}
350
371
@@ -410,11 +431,23 @@ class [[sus_trivial_abi]] FnOnce<R(CallArgs...)> {
410
431
invoke_ = &__private::Invoker<F>::template fnptr_call_mut<R, CallArgs...>;
411
432
}
412
433
413
- // / Construction from a capturing lambda or other callable object .
434
+ // / Construction from a non- capturing lambda.
414
435
// /
415
436
// / #[doc.overloads=ctor.lambda]
416
437
template <__private::CallableMut<R, CallArgs...> F>
417
- constexpr FnOnce (F&& object) noexcept {
438
+ requires (__private::ConvertsToFunctionPointer<F>)
439
+ constexpr FnOnce (F&& object sus_lifetimebound) noexcept {
440
+ storage_.object = ::sus::mem::addressof (object);
441
+ invoke_ = &__private::Invoker<
442
+ std::remove_reference_t <F>>::template object_call_mut<R, CallArgs...>;
443
+ }
444
+
445
+ // / Construction from a capturing lambda or other callable object.
446
+ // /
447
+ // / #[doc.overloads=ctor.capturelambda]
448
+ template <__private::CallableMut<R, CallArgs...> F>
449
+ requires (!__private::ConvertsToFunctionPointer<F>)
450
+ constexpr FnOnce (F&& object sus_lifetimebound) noexcept {
418
451
storage_.object = ::sus::mem::addressof (object);
419
452
invoke_ = &__private::Invoker<
420
453
std::remove_reference_t <F>>::template object_call_mut<R, CallArgs...>;
@@ -425,7 +458,7 @@ class [[sus_trivial_abi]] FnOnce<R(CallArgs...)> {
425
458
// / Since FnMut is callable, FnOnce is already constructible from it, but
426
459
// / this constructor avoids extra indirections being inserted when converting,
427
460
// / since otherwise an extra invoker call would be introduced.
428
- constexpr FnOnce (FnMut<R (CallArgs...)>&& o) noexcept
461
+ constexpr FnOnce (FnMut<R (CallArgs...)>&& o sus_lifetimebound ) noexcept
429
462
: storage_ (o.storage_ ),
430
463
invoke_ (::sus::mem::replace_ptr (o.invoke_ , nullptr )) {
431
464
::sus::check (invoke_); // Catch use-after-move.
@@ -436,20 +469,20 @@ class [[sus_trivial_abi]] FnOnce<R(CallArgs...)> {
436
469
// / Since Fn is callable, FnOnce is already constructible from it, but
437
470
// / this constructor avoids extra indirections being inserted when converting,
438
471
// / since otherwise an extra invoker call would be introduced.
439
- constexpr FnOnce (Fn<R (CallArgs...)>&& o) noexcept
472
+ constexpr FnOnce (Fn<R (CallArgs...)>&& o sus_lifetimebound ) noexcept
440
473
: storage_ (o.storage_ ),
441
474
invoke_ (::sus::mem::replace_ptr (o.invoke_ , nullptr )) {
442
475
::sus::check (invoke_); // Catch use-after-move.
443
476
}
444
477
445
478
~FnOnce () noexcept = default ;
446
479
447
- constexpr FnOnce (FnOnce&& o) noexcept
480
+ constexpr FnOnce (FnOnce&& o sus_lifetimebound ) noexcept
448
481
: storage_ (o.storage_ ),
449
482
invoke_ (::sus::mem::replace_ptr (o.invoke_ , nullptr )) {
450
483
::sus::check (invoke_); // Catch use-after-move.
451
484
}
452
- constexpr FnOnce& operator =(FnOnce&& o) noexcept {
485
+ constexpr FnOnce& operator =(FnOnce&& o sus_lifetimebound ) noexcept {
453
486
storage_ = o.storage_ ;
454
487
invoke_ = ::sus::mem::replace_ptr (o.invoke_ , nullptr );
455
488
::sus::check (invoke_); // Catch use-after-move.
@@ -468,12 +501,16 @@ class [[sus_trivial_abi]] FnOnce<R(CallArgs...)> {
468
501
}
469
502
470
503
// / `sus::construct::From` trait implementation.
504
+ // /
505
+ // / FnOnce satisfies `From<T>` for the same types that it is constructible
506
+ // / from: function pointers that exactly match its own signature, and callable
507
+ // / objects (lambdas) that are compatible with its signature.
471
508
constexpr static auto from (
472
509
__private::FunctionPointer<R, CallArgs...> auto ptr) noexcept {
473
510
return FnOnce (ptr);
474
511
}
475
512
template <__private::CallableMut<R, CallArgs...> F>
476
- constexpr static auto from (F&& object) noexcept {
513
+ constexpr static auto from (F&& object sus_lifetimebound ) noexcept {
477
514
return FnOnce (::sus::forward<F>(object));
478
515
}
479
516
0 commit comments