I'm basically trying do do this:
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 tell me, that the Move-Constructor of function_which_should_be_movable is deleted, because the Copy-constructor of std::future is deleted. However, I don't see why the compiler would attempt to copy the future instead of moving it.
function_which_should_be_movable
is of type std::function
. According to cppreference:
template< class F > function( F f );
F
must meet the requirements ofCallable
andCopyConstructible
.
The lambda expression you try to use to construct an std::function
object is not copyable, and hence the problem.
As to why std::function
has this requirement, please see this question: Why the initializer of std::function has to be CopyConstructible? (which is asked exactly by myself). Simply put, the type erasure technique used by std::function
will instantiate the copy-constructor of F
. This happens regardless of whether you, the user of the std::function
object, actually used this copy-constructor or not.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments