草庐IT

unique_future

全部标签

c++ - std::unordered_map<T,std::unique_ptr<U>> 可复制?海湾合作委员会错误?

g++--version产量:g++.exe(x86_64-posix-seh-rev0,BuiltbyMinGW-W64project)4.9.1Copyright(C)2014FreeSoftwareFoundation,Inc.Thisisfreesoftware;seethesourceforcopyingconditions.ThereisNOwarranty;notevenforMERCHANTABILITYorFITNESSFORAPARTICULARPURPOSE.程序:#include#include#includestatic_assert(!std::is_cop

c++ - std::unordered_map<T,std::unique_ptr<U>> 可复制?海湾合作委员会错误?

g++--version产量:g++.exe(x86_64-posix-seh-rev0,BuiltbyMinGW-W64project)4.9.1Copyright(C)2014FreeSoftwareFoundation,Inc.Thisisfreesoftware;seethesourceforcopyingconditions.ThereisNOwarranty;notevenforMERCHANTABILITYorFITNESSFORAPARTICULARPURPOSE.程序:#include#include#includestatic_assert(!std::is_cop

c++ - 与 auto_ptr 声明不同,unique_ptr 声明是否在其模板类型为不完整类型时是明确定义的?

我写了thisarticle并得到了一些让我感到困惑的评论。这基本上归结为我看过T2仅用作模板参数,并错误地得出结论,因此我可以借此机会进行前向声明:structT2;structT1{std::auto_ptrobj;};如果我不继续定义T2,这将调用UB在同一个TU的某个地方,因为std::auto_ptr来电delete在其内部T2*,和callingdeleteonanpointertoanobjectofanincompletetypewhosecompletetypehasanon-trivialdestructorisundefined:[C++11:5.3.5/5]:I

c++ - 与 auto_ptr 声明不同,unique_ptr 声明是否在其模板类型为不完整类型时是明确定义的?

我写了thisarticle并得到了一些让我感到困惑的评论。这基本上归结为我看过T2仅用作模板参数,并错误地得出结论,因此我可以借此机会进行前向声明:structT2;structT1{std::auto_ptrobj;};如果我不继续定义T2,这将调用UB在同一个TU的某个地方,因为std::auto_ptr来电delete在其内部T2*,和callingdeleteonanpointertoanobjectofanincompletetypewhosecompletetypehasanon-trivialdestructorisundefined:[C++11:5.3.5/5]:I

c++ - std::make_shared、std::unique_ptr 和移动构造函数

以下代码使用clang3.0/libc++编译:#includeclassFoo{public:Foo():mem_(newint(10)){}std::unique_ptrmem_;};intmain(){autofoo=std::make_shared();return0;}但是这个没有(std::string参数加了):#include#includeclassFoo{public:Foo(conststd::string&s):mem_(newint(10)){}std::unique_ptrmem_;};intmain(){autofoo=std::make_shared("

c++ - std::make_shared、std::unique_ptr 和移动构造函数

以下代码使用clang3.0/libc++编译:#includeclassFoo{public:Foo():mem_(newint(10)){}std::unique_ptrmem_;};intmain(){autofoo=std::make_shared();return0;}但是这个没有(std::string参数加了):#include#includeclassFoo{public:Foo(conststd::string&s):mem_(newint(10)){}std::unique_ptrmem_;};intmain(){autofoo=std::make_shared("

c++ - std::future 作为函数 C++ 的参数

考虑下面的代码voidprintPromised(std::futuref){std::cout它说“这是一个已删除的功能”。这是为什么?此外,我需要将std::async生成的相同promise结果传递(共享)给多个用户。这意味着当有人调用get()函数时,我需要传递相同的结果(如果它已经生成,我不需要使用std::async重新生成结果)而且我需要std::future::get拥有的阻塞机制。 最佳答案 只有一个future。您不能拥有同一个future的多个拷贝。所以你需要将future的所有权转让给函数:printProm

c++ - std::future 作为函数 C++ 的参数

考虑下面的代码voidprintPromised(std::futuref){std::cout它说“这是一个已删除的功能”。这是为什么?此外,我需要将std::async生成的相同promise结果传递(共享)给多个用户。这意味着当有人调用get()函数时,我需要传递相同的结果(如果它已经生成,我不需要使用std::async重新生成结果)而且我需要std::future::get拥有的阻塞机制。 最佳答案 只有一个future。您不能拥有同一个future的多个拷贝。所以你需要将future的所有权转让给函数:printProm

c++ - unique_lock 可以与 recursive_mutex 一起使用吗?

根据this,unique_lock可通过声明std::unique_lock用于递归锁定,实际上编译得很好。但是,从检查代码(gcc4.8.2和4.9.0)看来,unique_lock不服从_Mutex.lock,而是自己实现lock方法:voidlock(){if(!_M_device)__throw_system_error(int(errc::operation_not_permitted));elseif(_M_owns)__throw_system_error(int(errc::resource_deadlock_would_occur));else{_M_device-

c++ - unique_lock 可以与 recursive_mutex 一起使用吗?

根据this,unique_lock可通过声明std::unique_lock用于递归锁定,实际上编译得很好。但是,从检查代码(gcc4.8.2和4.9.0)看来,unique_lock不服从_Mutex.lock,而是自己实现lock方法:voidlock(){if(!_M_device)__throw_system_error(int(errc::operation_not_permitted));elseif(_M_owns)__throw_system_error(int(errc::resource_deadlock_would_occur));else{_M_device-