我正在玩,std::variant, lambdas并且std::future当我试图将它们组合在一起时得到超级奇怪的结果.以下是示例:
using variant_t = std::variant<
std::function<std::future<void>(int)>,
std::function<void(int)>
>;
auto f1 = [](int) { return std::async([] { return 1; }); };
auto f2 = [](int) { return std::async([] { }); };
variant_t v1(std::move(f1)); // !!! why DOES this one compile when it SHOULDN'T?
auto idx1 = v1.index(); //equals 1. WHY?
variant_t v2(std::move(f2)); // !!! why DOESN'T this one compile when it SHOULD?
Run Code Online (Sandbox Code Playgroud)
这是编译错误:
错误C2665'std :: variant <std :: function <std :: future <void>(int)>,std :: function <void(int)>> …