C++23 introduced std::function
's cousin std::move_only_function
, just like its name, it is a move-only wrapper for move-only callable objects (demo):
#include <functional>
#include <memory>
int main() {
auto l = [p = std::make_unique<int>(0)] { };
std::function<void(void)> f1{std::move(l)}; // ill-formed
std::move_only_function<void(void)> f2{std::move(l)}; // well-formed
}
But unlike std::function
, the standard does not define deduction guides for it (demo):
#include <functional>
int func(double) { return 0; }
int main() {
std::function f1{func}; // guide deduces function<int(double)>
std::move_only_function f2{func}; // deduction failed
}
Is there a reason for banning CTAD?