如果我使用:
int a = 3;
std::function<void()> task1 = std::bind([](int a){}, std::move(a));
Run Code Online (Sandbox Code Playgroud)
这是确定的,但如果我代替int用std::promise<int>:
std::promise<int> p;
std::function<void()> task2 = std::bind([](std::promise<int> p){}, std::move(p));
Run Code Online (Sandbox Code Playgroud)
G ++抛出一个错误:
error: conversion from ‘std::_Bind_helper<false, main()::__lambda7, std::promise<int> >::type {aka std::_Bind<main()::__lambda7(std::promise<int>)>}’ to non-scalar type ‘std::function<void()>’ requested
std::function<void()> task2 = std::bind([](std::promise<int> p){}, std::move(p));
Run Code Online (Sandbox Code Playgroud)
为什么?绑定一个std::promise参数有什么问题?