草庐IT

some_bucket

全部标签

c++ - Boost ICL : Are some combinations of interval types and functions not implemented?中函数 "contains"的基本使用

我开始使用BoostICL,并且偶然发现了一些非常基础的东西。例如,函数contains应该返回true或false,这取决于给定元素是否在区间内。然而,这适用于[right,left]_open_intervals但不适用于[open,closed]_inteval(请参见下面的示例)。这似乎太明显了,不是疏忽。我正在以预期的方式使用库吗?例如(使用gcc4.8或clang3.3和Boost1.54):#include//neededtomakethisMWEwork,boosticlshouldincludeitinternally#include#include#includei

c++ - Boost::asio socket - 如何在 'throw' 中创建 read_some "timeout"?

所以通常我们会做这样的事情socket.read_some(boost::asio::buffer(buffer,buffer_size));但是如何让它在读取还没有开始的情况下抛出异常比说333秒更长的时间? 最佳答案 您应该考虑使用async_read_some而不是read_some,因为它允许您在读取的同时启动一个新的后台计时器。然后,为您执行的每个新套接字创建一个新计时器:boost::asio::io_serviceio_service;time_t_timertimer(io_service);timer.expire

c++ - 使用挂起的 read_async_some 关闭 boost::asio::serial_port

我正在链接read_async_some()调用以从串行端口异步读取。在某些时候,我需要取消异步读取并在关联的处理程序中检测到这一事实。来自thedocumentationforcancel(),我希望通过检查传递给我的处理程序的error_code来做到这一点:Thisfunctioncausesalloutstandingasynchronousreadorwriteoperationstofinishimmediately,andthehandlersforcancelledoperationswillbepassedtheboost::asio::error::operatio

c++ - boost asio async_read_some 只读取数据片段

我有一个使用boost::asio进行读/写操作的C++服务器-写出消息工作正常-但由于某种原因我无法读取工作我从客户端发送给它的消息是1516位无符号短裤-我的测试消息是这样的:1,34,7,0,0,0,0,0,4,0,0,0,0,0,0现在在服务器上我经常看到这样的事情。读取通常被分解和/或乘以256这是一次发送两次readinglength=8:[134700000]readinglength=3:[102400]readinglength=3:[000]readinglength=8:[134700000]readinglength=6:[102400000]这是第二次发送两次

c++ - 模板 :Name resolution:Point of instantiation: -->can any one tell some more examples for this statement?

这是来自ISOC++标准14.6.4.1实例化点的声明Forafunctiontemplatespecialization,amemberfunctiontemplatespecialization,oraspecializationforamemberfunctionorstaticdatamemberofaclasstemplate,ifthespecializationisimplicitlyinstantiatedbecauseitisreferencedfromwithinanothertemplatespecializationandthecontextfromwhichi

c++ - 键不存在时 unordered_multimap::bucket() 的返回值?

当key不存在时,unordered_multimap::bucket(key)是什么应该回来吗?引用资料说它应该返回包含键的桶的桶号,但没有说明当unordered_multimap中不存在该键时会发生什么。Itrieditmyself但我得到的结果不正确:std::unordered_multimapm={{"jack","foo"},{"jill","bar"}};std::cout输出是:jackisinbucket3jillisinbucket4bjarneisinbucket4这是否意味着我必须使用unordered_multimap::count(key)==0来捕获不存

c++ - decltype(some_vector)::size_type 不能用作模板参数

下面的类不编译:template,classAllocator=std::allocator>classMyContainer{public:std::vectordata;std::vector>order;};我收到以下编译器错误:error:type/valuemismatchatargument2intemplateparameterlistfor‘templatestructstd::pair’为什么编译失败,而下面的代码工作正常?template,classAllocator=std::allocator>classMyContainer{public:std::vecto

c++ - write_some 与 write - boost asio

当write_some可能无法将所有数据传输到对等端时,为什么有人要使用它?来自boostwrite_some文档Thewrite_someoperationmaynottransmitallofthedatatothepeer.Considerusingthewritefunctionifyouneedtoensurethatalldataiswrittenbeforetheblockingoperationcompletes.write_some方法在boost中有write方法的相关性是什么?我浏览了boostwrite_some文档,我猜不出什么。

c++ - 从 std::tuple<some_types...> 开始创建子元组

让我们假设一个std::tuple给出。我想创建一个新的std::tuple其类型是在[0,sizeof...(some_types)-2]中索引的类型.例如,假设起始元组是std::tuple.我想获得一个定义为std::tuple的子元组.我对可变参数模板很陌生。作为第一步,我尝试写一个struct负责存放不同类型的原件std::tuple目的是创建一个新的同类元组(如std::tuplenew_tuple)。templatestructtype_list;templatestructtype_list:publictype_list{typedefTtype;};template

c++ - 均匀填充大小不一的 "buckets"未排序列表的最有效方法是什么

假设我有一个bucket的未排序列表秒。(每个桶都有一个size属性。)假设我有一个数量Q我必须尽可能均匀地分布在桶列表中(即最小化最大值)。如果桶排序的大小越来越大,那么解决方案就很明显了:完全填满每个桶,比如buckets[i],直到Q/(buckets.length-i)size,然后用相同数量的Q/(buckets.length-i)填充剩余的桶,如图:如果桶未排序,解决此问题的最有效方法是什么?我只能想到这样迭代(伪代码):whileQ>0foriin0..buckets.length-1q=Q/(buckets.length-i)ifq>buckets[i]->sizeq=