【发布时间】:2015-04-24 12:21:52
【问题描述】:
我基本上是在尝试这样做:
using Type = SomeTypeThatIWantToMove;
std::promise<Type> promised_result;
std::future<Type> promised_future = promised_result.get_future();
using Callback = std::function<void()>;
Callback function_which_should_be_movable =
[this, future_result(std::move(promised_future))]() mutable
{
this->some_function(future_result.get()); // signature: void some_function(const Type&)
};
using ResultBuilder = std::function<Type(Callback&&)>;
// result_builder is of type ResultBuilder
Type thingy = result_builder(std::move(function_which_should_be_movable));
MinGW 告诉我,function_which_should_be_movable 的 Move-Constructor 被删除了,因为 std::future 的 Copy-constructor 被删除了。但是,我不明白为什么编译器会尝试复制未来而不是移动它。
【问题讨论】:
-
不幸的现实是
std::function被严重破坏了。
标签: c++ lambda mutable move-constructor