<future>
: Make packaged_task
accept move-only functors by frederick-vs-ja · Pull Request #4946 · microsoft/STL (original) (raw)
Fixes #321.
The issue was considered ABI-breaking, but I think it can be resolved in an ABI-preserving way like #2568. This PR adds internal constructors to function
to accept non-copy-constructible functors and add static_assert
to keep the copyability checking for standard constructors. Valid user codes won't be able to call these internal constructors.
Also implements the previously missing Mandates in [futures.task.members]/3, and switches to use move construction in reset
per [futures.task.members]/26.
Notes:
- The internal constructors are made constrained templates to avoid affecting overload resolution unexpectedly, see LLVM-103409.
- The involved allocator-extended constructors were removed in C++17 by WG21-P0302R1 and LWG-2921, so this PR cites WG21-N4140 in the C++17-removed constructors.
- The fix should work for most move-only types. Although there can be classes whose copy constructor are only invalid in instantation. In vNext we should completely get rid of
function
. - If the
function<R(Args...)>
is a program-defined specialization, this approach doesn't work. I don't think any user should specializestd::function
, but this is allowed by the standard. - Three
_Packaged_state
specializations are merged into one. I believe this can ease maintenance.