草庐IT

boost-move

全部标签

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,

java - 小铁杆: Do you know any parallel modified moving average algorithm?

你知道任何并行修正移动平均算法吗?我想快速计算移动平均线而不是sequentialalgorithms.我想使用并行算法,但我仍然没有找到解决方案。我发现最好的算法是顺序算法modifiedmovingaverageformeasuringcomputerperformance:new_avg=alfa(new_time,previous_time)*new_value+(1-alfa(new_time,previous_time))*previous_avgalfa(new_time,previous_time)=1-exp(-(new_time-previous_time)/mov

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

c++ - 为简单结构定义哪个复制/move 构造函数/运算符?

我的程序使用一个简单的结构Rect定义为structRect{intx1,y1,x2,y2;Rect():x1(0),y1(0),x2(0),y2(0){}Rect(intx1,inty1,intx2,inty2):x1(x1),y1(y1),x2(x2),y2(y2){}};我应该定义复制/move构造函数或赋值运算符,还是可以依靠编译器自动生成它们?问题与速度和使用原因有关(例如,move构造函数会影响程序执行速度)。构造函数和运算符是非常重复的工作,如果能依靠编译器自动生成就好了。Rect(constRect&r):x1(r.x1),y1(r.y1),x2(r.x2),y2(r.

c++ - 为什么 boost::any 不保存字符串文字?

#include#include#include#includestruct_time_t{intmonth;intyear;};intmain(){std::stringstr="hahastr";_time_tt;std::vectorobjVec;objVec.push_back(1);char*pstr="haha";//boost::anycharArr="haha";notcompile//objVec.push_back("haha");notcompileobjVec.push_back(pstr);objVec.push_back(str);objVec.push_b

c++ - 使用英特尔编译器构建 boost 库

除了VisualStudio2012之外,我还在一台32位Windows7机器上安装了IntelParallelStudioXE2013。我已尝试按照link中的说明使用Intel编译器构建Boost1.53。.我有这个错误:.\boost/config/select_stdlib_config.hpp(18):catastrophicerror:cannotopensourcefile"cstddef"请问有遇到同样问题的吗?我欢迎任何链接ICC标准库以boost构建过程的建议。提前致谢。 最佳答案 经过一番搜索,终于找到了解决办

c++ - 使用 std::move 和 std::shared_ptr 有什么好处和风险(如果有的话)

我正在学习C++11的特性,作为其中的一部分,我首先进入了unique_ptr和shared_ptr的世界。开始时,我编写了一些专门使用unique_ptr的代码,因此当我传递我的变量时,我需要使用std::move来完成它(或者让我明白)。经过一番努力,我意识到我确实需要shared_ptr而不是我正在做的事情。稍后快速查找/替换,我的指针被切换到共享,但我懒洋洋地只是留下了move()调用。令我惊讶的是,它不仅可以编译,而且在我的程序中表现得非常好,我得到了我期望的每一点功能......特别是,我能够“move”一个shared_ptr从ObjectA到ObjectB,并且两个对象