C++23 で導入されstd::functionた の cousinstd::move_only_functionは、その名前のように、移動のみの呼び出し可能オブジェクト ( 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
}
ただし、 とは異なりstd::function、標準では推論ガイドが定義されていません ( 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
}
CTAD を禁止する理由はありますか?