草庐IT

boost-coroutine

全部标签

c++ - boost::可选的函数返回

我正在审查一些生产代码,其中一个函数说它将返回一个boost::optional,但它只返回一个double:例如boost::optionalFoo(){doublea=1.0;doubleb=2.0;returna+b;}这种风格是否可以接受/是否存在不安全的情况? 最佳答案 这是我喜欢使用的样式。返回的double将被隐式转换为boost::optional,它已被设置并包含该double的值。我想不出任何不安全的情况。编辑:当optional持有的类型为bool时有一些注意事项-请参阅文档。此转换将使用此boost::opt

c++ - 在 BOOST 图中找到给定 2 个顶点的多条边

我正在为某个项目使用BoostGraph库,我想查找图中一条边重复的次数。例如,typedefboost::adjacency_listGraph_t;//node_infoandEdge_infoareexternalnodeandedgeproperties(structures)假设我有两个节点,node1和node2,并且它们之间有一条边(node1,node2)。每条边的边属性包含时间戳开始、结束……并且图中可以有许多具有不同时间戳的这样的边。例如。edge1=(node1,node2)withstart=100,end=200.edge2=(node1,node2)with

c++ - C++11 中的 BOOST scoped_lock 替换

我面临这样一种情况,我必须用C++11中的等效项替换BOOSTscoped_lock。在visualstudio2013下。由于c++11不支持scoped_lock,我不确定下面的替换代码是什么。我应该选择lock_guard还是try_lock?boost::mutex::scoped_lockobjectLock(ObjectVectorMutex,boost::try_to_lock);if(objectLock){//...}在代码中我有以下“等待”语句if(ObjectsCollection.empty()){//Thisiswherewewaittilsomethingi

c++ - boost::graph 中的 DFS 更改图形内容

最小的例子:#include#include#includestructvertex{intnumber;};structedge{};typedefboost::adjacency_listgraph_t;typedefboost::graph_traits::vertex_descriptorvertex_t;typedefboost::graph_traits::edge_descriptoredge_t;structvertex_visitor:publicboost::default_dfs_visitor{voiddiscover_vertex(vertex_tv,grap

c++ - 如何使用 boost::random_device 生成密码安全的 64 位整数?

我想做这样的事情:boost::random_devicerd;boost::random::mt19937_64gen(rd());boost::random::uniform_int_distributiondis;uint64_tvalue=dis(gen);但我读到梅森扭曲器在密码学上并不安全。但是,我还读到一个random_device可能是,如果它从/dev/urandom中提取数据,这可能在linux平台(我的主要平台)上。因此,如果random_device是非确定性随机的并且它用于播种梅森扭曲器(如上所示),这是否也使梅森扭曲器在密码学上是安全的(即使它本身不是)?我

c++ - boost 侵入式指针

我对boost的侵入式指针有点困惑。定义说:"Everynewintrusive_ptrinstanceincrementsthereferencecountbyusinganunqualifiedcalltothefunctionintrusive_ptr_add_ref,passingitthepointerasanargument.Similarly,whenanintrusive_ptrisdestroyed,itcallsintrusive_ptr_release;thisfunctionisresponsiblefordestroyingtheobjectwhenitsre

c++ - 试图摆脱 C++ boost 警告

每当我在我的项目中加入boost时,我都会收到一百万条这样的警告。有谁知道我怎样才能摆脱警告?../depends\boost/config/abi_prefix.hpp(19):warningC4103:'depends\boost\config\abi_prefix.hpp':alignmentchangedafterincludingheader,maybeduetomissing#pragmapack(pop)我知道我可以执行#pragma来禁用警告,但我想知道这些警告的原因。 最佳答案 原因是boost不会在每个需要打包数

c++ - 在 shared_from_this() 中 boost weak_ptr_cast

我正在使用boost的共享指针,并使用enable_shared_from_this来启用返回指向this的共享指针。代码如下所示:classfoo:publicboost::enable_shared_from_this{boost::shared_ptrget(){returnshared_from_this();}}为什么shared_from_this会抛出weak_ptr_cast异常? 最佳答案 如果您在堆栈上声明了foo,那么就没有其他指向foo的共享指针。例如:voidbar(){foofooby;fooby.get

C++,boost asio,接收空终止字符串

如何使用boost::asio库从套接字中检索以null结尾的字符串? 最佳答案 m_socket=boost::asio::ip::tcp::socket(io_service);boost::asio::streambufreplyBuf;......boost::asio::read_until(m_socket,replyBuf,'\0');如果你想将streambuf转换为字符串:std::stringretVal((std::istreambuf_iterator(&replyBuf)),std::istreambuf_

c++ - 如何为 boost::bind 强制模板函数重载?

我正在尝试通过使用boost::bind和boost::contains为std::find_if创建谓词(来自提升/算法/字符串库)。以下代码段显示了我如何尝试实现此目的的两种方式。#include#include#include#include#includeintmain(intargc,char**argv){std::strings1("hellomom");std::strings2("byemom");boost::functionf=&boost::contains;std::coutcontain_hello=boost::bind(boost::contains,_