草庐IT

STD_PROP_LIST

全部标签

c++ - 未捕获的 std::exception 在核心中不正确的堆栈跟踪

这是我的代码:#include#includeusingnamespacestd;usingnamespacestd::tr1;usingnamespacestd::tr1::placeholders;classEvent{public:typedefstd::tr1::functionHandler;voidset(Handlerh){m_handler=h;}templatevoidset(T*obj,Fmemfn){set(std::tr1::bind(memfn,obj));}voidoperator()(){m_handler();}staticvoidfire(Event*

c++ - std::forward of rvalue ref to lambda?

考虑以下两个片段:附件A:templateintperform_calc(CalcFuncT&&calcfunc){precalc();intconstcalc=calcfunc();postcalc();returncalc;}intmain(){perform_calc([]{return5*foobar_x()+3;});//toFutureperform_calc([]{return5*foobar_y()-9;});//toPast}图表B:templateintperform_calc(CalcFuncT&&calcfunc){precalc();intconstcalc=

c++ - 我的 SFINAE 检查 std::map/std::vector 有什么问题?

我有一个简单的SFINAE场景来区分标准容器,如std::map:templatestructHasKeyType:sfinae_test{//(C)templatestaticYestest(typenameContainer::key_type*);//(A)templatestaticNotest(...);enum{value=(sizeof(test(null))==sizeof(Yes))};//(B)};与structsfinae_test{typedefcharYes;typedeflongNo;staticvoid*constnull;};当我用HasKeyType>

c++ - std::find 用于继承对象 C++

1.所以我有:ClassA;ClassB:publicA;ClassC:publicB;2.还有一个B类型的指针vector:vectorvec;3.然后:C*ptr=newC();vec.push_back(ptr);那么问题来了,这样用std::find靠谱吗?std::find(vec.begin(),vec.end(),prt);此外,使用this->指针进行搜索可以吗?std::find(vec.begin(),vec.end(),this);//insideofatypeCobject提前致谢。 最佳答案 是的,这是安全

c++ - std::wostream_iterator

为什么C++中没有std::wostream_iterator?这有什么好的理由吗?#include#include#include#includeintmain(){std::vectormyvec={L"first",L"second"};std::wofstreamf("New.txt");//std::copy(myvec.begin(),myvec.end(),std::wostream_iterator(f));//Error//std::copy(myvec.begin(),myvec.end(),std::ostream_iterator(f));//Errorstd:

c++ - 使用 TBB 的并行性——我们的 list 中应该包含什么?

直到最近,并行编程的前景才引起了我的注意。从那时起,我使用了各种并行编程库。也许我的第一站是英特尔线程构建模块(TBB)。但是,经常成为瓶颈的是由于舍入等因素以及这些程序在不同处理器架构中的不可预测行为而导致的错误。下面是一段代码,用于计算两组值的PIL逊相关系数。它采用了TBB的非常基本的并行模式——*parallel_for*和*parallel_reduce*://AprogrammetocalculatePearsonsCorrelationcoefficient#include#include#include#include#include#include#include#i

C++11:std ref 全局变量和非函数局部 thread_local 初始化顺序?

C++11中具有非平凡构造函数的全局变量是在静态初始化阶段在进入main之前构造的。同样,非函数局部thread_local变量是在每个线程的“thread_local初始化阶段”构建的。C++11标准是否规定了这些变量的构造顺序?在这两种情况下,如果有两个变量://globalscopeA::A(){b.f();}//AconstructorusesglobalbAa;Bb;C++11标准是否指定了它们应按什么顺序进行初始化,或者如果使用未初始化的变量应该产生错误?同样适用于非函数本地thread_local://globalscopeA::A(){b.f();}//Aconstru

c++ - forward_list::splice_after( const_iterator pos, forward_list& other, const_iterator i ) 功能

我正在阅读有关此功能工作方式的不同解释。cplusplus.com说这个函数应该“直接在i之后移动元素”。然而cppreference.com表示它拼接元素ATi。MSvisualstudio同意cplusplus.com。但是,实际上正确的行为是什么?我倾向于认为“在i之后”移动更合乎逻辑(&不需要N时间来找到前面的节点)。(PS:没有forward-list标签?) 最佳答案 23.3.4.6voidsplice_after(const_iteratorposition,forward_list&x,const_iterator

c++ - 比较两组 std::weak_ptr

我正在尝试使用GCC4.7.2比较两组C++11weak_ptr。下面的代码显示了重现错误的最小可能样本:std::set,std::owner_less>>set1;std::set,std::owner_less>>set2;boolresult=(set1==set2);尝试编译以上内容会导致一长串错误,其中第一个实际错误如下:/usr/include/c++/4.7/bits/stl_algobase.h:791:6:error:nomatchfor‘operator==’in‘__first1.std::_Rb_tree_const_iterator::operator*>(

c++ - 如何正确退出可能正在等待 std::condition_variable 的 std::thread?

我有一个类使用互斥锁和两个条件变量实现线程化生产者/消费者系统以进行同步。当有元素要使用时,生产者向消费者线程发出信号,而消费者在消费完元素时向生产者线程发出信号。线程继续生产和消费,直到析构函数通过设置bool变量请求它们退出。因为任何一个线程都可能在等待条件变量,所以我必须对quit变量进行第二次检查,这感觉不对而且很乱......我已将问题简化为以下(使用g++4.7在GNU/Linux上工作)示例://C++11andBoostrequired.#include//std::rand()#include#include#include#include#include#inclu