草庐IT

exception_ptr

全部标签

C++ 异常和来自 std::exception 的继承

鉴于此示例代码:#include#includeclassmy_exception_t:std::exception{public:explicitmy_exception_t(){}virtualconstchar*what()constthrow(){return"Hello,world!";}};intmain(){try{throwmy_exception_t();}catch(conststd::exception&error){std::cerr我得到以下输出:Exception:unknown然而,简单地从std::exceptionpublic继承my_exceptio

C++ 异常和来自 std::exception 的继承

鉴于此示例代码:#include#includeclassmy_exception_t:std::exception{public:explicitmy_exception_t(){}virtualconstchar*what()constthrow(){return"Hello,world!";}};intmain(){try{throwmy_exception_t();}catch(conststd::exception&error){std::cerr我得到以下输出:Exception:unknown然而,简单地从std::exceptionpublic继承my_exceptio

c++ - 将 unique_ptr 的 vector 插入另一个 vector

我有一个unique_ptr的vector,我想将它们附加到另一个unique_ptrvector。我通常会做一个简单的插入:std::vector>bar;bar.push_back(std::unique_ptr(newfoo(1)));std::vector>baz;baz.push_back(std::unique_ptr(newfoo(2)));bar.insert(bar.end(),baz.begin(),baz.end());但是这给了我类似这样的编译错误:/usr/include/c++/4.8/bits/stl_algobase.h:335:error:useofd

c++ - 将 unique_ptr 的 vector 插入另一个 vector

我有一个unique_ptr的vector,我想将它们附加到另一个unique_ptrvector。我通常会做一个简单的插入:std::vector>bar;bar.push_back(std::unique_ptr(newfoo(1)));std::vector>baz;baz.push_back(std::unique_ptr(newfoo(2)));bar.insert(bar.end(),baz.begin(),baz.end());但是这给了我类似这样的编译错误:/usr/include/c++/4.8/bits/stl_algobase.h:335:error:useofd

c++ - 如何使用带有 boost::ptr_map 的 BOOST_FOREACH?

如何通过boost::ptr_map有效地使用BOOST_FOREACH(字符数/可读性)?Kristo在他的answer中展示了可以将BOOST_FOREACH与ptr_map一起使用,但与使用迭代器迭代ptr_map相比,它并不能真正为我节省任何打字(或使我的代码更易读):typedefboost::ptr_container_detail::ref_pairIntPair;BOOST_FOREACH(IntPairp,mymap){inti=p.first;}//vs.boost::ptr_map::iteratorit;for(it=mymap.begin();it!=myma

c++ - 如何使用带有 boost::ptr_map 的 BOOST_FOREACH?

如何通过boost::ptr_map有效地使用BOOST_FOREACH(字符数/可读性)?Kristo在他的answer中展示了可以将BOOST_FOREACH与ptr_map一起使用,但与使用迭代器迭代ptr_map相比,它并不能真正为我节省任何打字(或使我的代码更易读):typedefboost::ptr_container_detail::ref_pairIntPair;BOOST_FOREACH(IntPairp,mymap){inti=p.first;}//vs.boost::ptr_map::iteratorit;for(it=mymap.begin();it!=myma

c++ - `unique_ptr< T const [] >` 是否应该接受 `T*` 构造函数参数?

代码:#includeusingnamespacestd;structT{};T*foo(){returnnewT;}Tconst*bar(){returnfoo();}intmain(){unique_ptrp1(bar());//OKunique_ptra1(bar());//OKunique_ptrp2(foo());//OKunique_ptra2(foo());//?thisisline#15}VisualC++10.0和MinGWg++4.4.1的示例错误:[d:\dev\test]>clfoo.cppfoo.cppfoo.cpp(15):errorC2248:'std::

c++ - `unique_ptr< T const [] >` 是否应该接受 `T*` 构造函数参数?

代码:#includeusingnamespacestd;structT{};T*foo(){returnnewT;}Tconst*bar(){returnfoo();}intmain(){unique_ptrp1(bar());//OKunique_ptra1(bar());//OKunique_ptrp2(foo());//OKunique_ptra2(foo());//?thisisline#15}VisualC++10.0和MinGWg++4.4.1的示例错误:[d:\dev\test]>clfoo.cppfoo.cppfoo.cpp(15):errorC2248:'std::

c++ - 在 vector <unique_ptr> 上使用 is_copy_constructible 误报

类型trait是否应该能够处理std::vector>之类的情况?并检测到它不是可复制的?这是https://ideone.com/gbcRUa的示例(运行g++4.8.1)#include#include#include#includeintmain(){//Thisprints1,implyingthatit'scopyconstructible,whenit'sclearlynotstd::cout>>::value如果这是is_copy_constructible的正确行为,有没有办法检测到复制结构是不正确的?好吧,不仅仅是让它无法编译。 最佳答案

c++ - 在 vector <unique_ptr> 上使用 is_copy_constructible 误报

类型trait是否应该能够处理std::vector>之类的情况?并检测到它不是可复制的?这是https://ideone.com/gbcRUa的示例(运行g++4.8.1)#include#include#include#includeintmain(){//Thisprints1,implyingthatit'scopyconstructible,whenit'sclearlynotstd::cout>>::value如果这是is_copy_constructible的正确行为,有没有办法检测到复制结构是不正确的?好吧,不仅仅是让它无法编译。 最佳答案