C++ promise的向量引发异常,但boost::promise不会

C++ promise的向量引发异常,但boost::promise不会,c++,c++11,boost,future,C++,C++11,Boost,Future,问题:存储承诺集合的正确方式是什么 我使用的是带有“-std=c++11”的g++(Ubuntu 4.8.4-2ubuntu1~14.04)4.8.4。(更新:现在升级到g++5.3,请参见备注) 以下代码在调用promise.set_value()时引发异常。消息是“在抛出'std::system_error'实例后终止调用what():未知错误-1中止(内核转储)” 由于您成功地编译了main,但没有返回类型,因此可能会添加一些选项,以增加编译器的标准一致性和警告数量。无法在Windows中

问题:存储承诺集合的正确方式是什么

我使用的是带有“-std=c++11”的g++(Ubuntu 4.8.4-2ubuntu1~14.04)4.8.4。(更新:现在升级到g++5.3,请参见备注)

以下代码在调用promise.set_value()时引发异常。消息是“在抛出'std::system_error'实例后终止调用what():未知错误-1中止(内核转储)”


由于您成功地编译了
main
,但没有返回类型,因此可能会添加一些选项,以增加编译器的标准一致性和警告数量。无法在Windows中使用MinGW g++5.1进行复制。也不能用Visual C++ 2015进行复制。也不能用CLAN 7进行复制。听起来你只需要升级你的编译器。GCC4.8.4已经有一年的历史了,我们已经升级到GCC5.2。升级到g++5.3,仍然看到相同的错误“g++(Ubuntu 5.3.0-3ubuntu1~14.04)5.3.0 20151204”我的编译选项:“g++-Werror-Wall-Wextra-std=c++11”
#include <vector>
#include <future>

int main()
{
    {   
        std::vector<std::promise<int>> q;
        std::promise<int> p;
        auto f = p.get_future();
        q.push_back(std::move(p));
        auto t1 = std::move(q.front());
        t1.set_value(10);
    }   
}
#include <vector>
#include <boost/thread/future.hpp>

int main()
{
    {   
        std::vector<boost::promise<int>> q;
        boost::promise<int> p;
        auto f = p.get_future();
        q.push_back(std::move(p));
        auto t1 = std::move(q.front());
        t1.set_value(10);
    }   
}
#include <vector>
#include <future>
#include <boost/thread/future.hpp>

int main()
{
    {   // this hides the exception thrown by promise::set_value()
        boost::promise<int> p;
    }   

    {   
        std::vector<std::promise<int>> q;
        std::promise<int> p;
        auto f = p.get_future();
        q.push_back(std::move(p));
        auto t1 = std::move(q.front());
        t1.set_value(10);
    }   
}
linux-vdso.so.1 =>  (0x00007fffe51fe000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fa542df1000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fa542bda000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fa542813000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fa54250d000)
/lib64/ld-linux-x86-64.so.2 (0x00007fa54311f000)