草庐IT

Boost-asio

全部标签

c++ - 从不同线程写入 boost::asio 套接字

在我们的应用程序中,我们使用Boost库(以及用于网络通信的ASIO)。最近,我们发现如果我们通过同一个套接字从不同线程发送数据,我们的客户端应用程序将接收到垃圾数据。突出问题的小测试:#include#include#includevoidsend_routine(boost::shared_ptrs,charc){std::vectordata(15000,c);data.push_back('\n');for(inti=0;i(newtcp::socket(io_service));socket->connect(*iterator);boost::threadt1(send_r

c++ - 使用迭代器从 boost 多索引中删除项目时的一致性

我知道下面的代码对于std::vectors和更普遍的所有STL容器来说是不正确的:std::vector::iteratorit=array.begin();for(;it!=array.end();it++){...array.erase(it);...}因为删除元素后需要更新迭代器。我想知道boost多索引是否相同,例如,下面的内容是否正确:my_index::iteratorit=index.get().begin();for(;it!=index.get().end();it++){...index.erase(it);...}我想确保理解文档的以下段落:http://www

c++ - boost::container 是否支持 C++11 初始化列表?

在Boost.Container网站上我们可以看到:Boost.Containerdoesnotsupportinitializerlistswhenconstructingorassigningcontainersbutitwillsupportitforcompilerswithinitialized-listsupport.(...)对不起,如果我只是愚蠢,但我真的不知道如何阅读它。这是否意味着它会在不可预测的future这样做,或者它现在应该与符合标准的编译器一起工作?我已经在GCC4.7和ICC13.0上测试过它,两者都不起作用,但我相信我可能错过了一些非常重要的东西,比如正

c++ - 它如何清除所有已经排队的已发布任务?

它如何清除所有已在io_service::strand中排队的已发布任务?我在boost文档中没有看到类似的方法。 最佳答案 我还没有找到对它的需求,因为它可以通过正确设计异步调用链来正确解决。通常,Boost.AsioAPI经过精心设计,可以防止复杂的应用程序在异步流程中变得复杂。如果您检查了调用链,并且绝对确定重新设计它们的努力在当前和future的风险大于引入清除链的复杂性,那么有一种方法可以实现它。但是,它确实具有删除strand中所有未调用的处理程序的主要副作用。,及其相关的io_service.当strand被摧毁,它的

c++ -/boost/lockfree/queue.hpp: 错误: 静态断言失败: (boost::has_trivial_destructor<T>::value)

我正在尝试替换boost::lockfree::queue对于std::queue在这个文件中https://github.com/zaphoyd/websocketpp/blob/experimental/examples/broadcast_server/broadcast_server.cpp我添加了#include;改线130,std::queuem_actions;,至boost::lockfree::queuem_actions;;删除所有与锁定有关的行;并更改了行103,m_actions.pop();,至m_actions.pop(a);.我在sconsbroadcas

c++ - 为什么 boost filter_iterator 有奇怪的 make_filter_iterator 函数?

在经历了一些痛苦之后,我设法拼凑了这个boostfilter_iterator的最小示例usingnamespacestd;std::functionstlfunc=[](uint32_tn){returnn%3==0;};intmain(){vectornumbers{11,22,33,44,55,66,77,3,6,9};autostart=boost::make_filter_iterator(stlfunc,numbers.begin(),numbers.end());autoend=boost::make_filter_iterator(stlfunc,numbers.end

c++ - 为什么 boost 的随机数生成(正态分布)总是给出相同的值?

我正在生成一些随机数并出现可疑行为。这是我的代码://initializedearlier...intheconstructorofaclassboost::mt19937*rng=newboost::mt19937();rng->seed(time(NULL));//actualusehere.for(inti=0;idistribution(10,10);boost::variate_generator>resampler(*rng,distribution);constdoublesample=(resampler)();//alwaysthesamevalue.}我是否滥用了b

c++ - 使用 boost::is_any_of 拆分会混淆定界符 ",,"和 ","

我目前有一个具有以下结构的字符串xxx,xxx,xxxxxxx,,xxxxxx,xxxx现在我使用下面的代码std::vectorvct;boost::split(vct,str,boost::is_any_of(",,"));现在,一旦找到“,”而不是我不想要的“,,”,boost就会拆分字符串。有什么方法可以让我明确指定只有在找到“,,”而不是“,,”时才拆分 最佳答案 is_any_of(",,")将匹配列表中指定的任何内容。在这种情况下,,或,你要找的是沿线boost::algorithm::split_regex(vct,

c++ - boost 中的矩阵求逆

我正在尝试使用boost进行简单的矩阵求逆运算。但是我我收到一个错误。基本上我想找到的是inversted_matrix=逆(反式(矩阵)*矩阵)但是我收到一个错误Checkfailedinfileboost_1_53_0/boost/numeric/ublas/lu.hppatline299:detail::expression_type_check(prod(triangular_adaptor(m),e),cm2)terminatecalledafterthrowinganinstanceof'boost::numeric::ublas::internal_logic'what(

c++ - 如何从 boost::timer::cpu_timer 获取耗时(以秒为单位)?

以下粗略代码,基于thedocumentation,给我从boost中提供的计时器对象中耗时(以秒为单位)。boost::timer::cpu_timertimer;//...dosomework...constboost::timer::nanosecond_typeoneSecond(1000000000LL);returntimer.elapsed().user/oneSecond;这个方法的问题是我的代码中有这个令人不舒服的魔数(MagicNumber)。boost中是否有某种方法可以从nanosecond_type值中为我提供elapsed().user调用中可用的elaps