草庐IT

it_begin

全部标签

c++ - regex_token_iterator *it++ 错误?

对于以下代码:#include#includeusingnamespacestd;intmain(intargc,char*argv[]){regexreg("/");strings="Split/Values/Separated/By/Slashes";sregex_token_iteratorit{std::begin(s),std::end(s),reg,-1};sregex_token_iteratorend;while(it!=end){cout应该输出:SplitValuesSeparatedBySlashes但是它输出这个:ValuesSeparatedBySlashes

c++ - cppcheck 认为我有 "Redundant code: Found a statement that begins with numeric constant"

Cppcheck(version1.46.1)对像这样的枚举发出以下警告:enumDATABASE_TYPE{DATABASE_TYPE_UNKNOWN=-1,//Redundantcode:Foundastatementthatbeginswithnumericconstant我不认为这是多余的。能够做那样的事情非常重要。这是cppcheck的错误还是我没有看到什么?更新我设法将它归结为一个最小的例子。这因为cppcheck有2个(更多)错误而变得复杂,这使得我的减少看起来没有效果。共有5个文件:a.h、a.cpp、b.h、b.cpp和inc。h包含以下内容。VC9在没有警告的情况下

c++ - std::nth_element(a.begin(), a.end(), a.end()) 有什么作用?

我在http://www.sgi.com/tech/stl/nth_element.html阅读了std::nth_element的描述templatevoidnth_element(RandomAccessIteratorfirst,RandomAccessIteratornth,RandomAccessIteratorlast);注意前提是[first,nth)是一个有效范围。[nth,last)是一个有效范围。我的问题是:调用std::nth_element(a.begin(),a.end(),a.end())是否有效?如果有,它的作用是什么?无论如何,它不违反上述先决条件。语言

c++ - std::begin 和 R 值

最近我试图修复一个非常困难的const-correctness编译器错误。它最初表现为Boost.Python深处的多段模板呕吐错误。但这无关紧要:这一切都归结为以下事实:C++11std::begin和std::end迭代器函数没有重载到取R值。std::begin的定义是:templateautobegin(C&c)->decltype(c.begin());templateautobegin(constC&c)->decltype(c.begin());因此,由于没有R值/通用引用重载,如果您将R值传递给它,您将获得一个const迭代器。那我为什么要关心呢?好吧,如果你有某种“范

c++ - 用已知数量的元素填充 vector : specify its size in constructor or by using reserve method?

我想通过从流中读取单个元素来创建某种复杂类型的vector。我提前知道vector大小。是在vector构造函数中指定元素个数更好,还是使用reserve方法更好?这两个哪个更好?intmyElementCount=stream.ReadInt();vectormyVector(myElementCount);for(inti=0;i或intmyElementCount=stream.ReadInt();vectormyVector;myVector.reserve(myElementCount);for(inti=0;i如果我只是创建一个intvector或其他一些简单类型呢?

c++ - 使用 static_cast 处理混合(基础和派生)对象的 vector 是否存在性能风险? (又名 "it this a dumb idea?")

给定基类gameObject和派生类animatedGameObject,我认为将它们的所有实例存储在std::vector。如果vectorGameObjects声明为gameObject*的基类型,则派生对象实例需要强制转换。例子:vectorGameObjects;gameObjectA*=newgameObject(...init...);animatedGameObjectB*=newanimatedGameObject(...init...);GameObjects.push_back(A);GameObjects.push_back(B);//toaccesstheani

C++ 继承 : Calling virtual method when it has been overridden

我正在尝试构建一个可以在单独的线程中运行(即执行它的run()函数)的service对象。这是服务对象#include#include#include#includeclassservice:publicboost::noncopyable{public:service():stop_(false),started_(false){}virtual~service(){stop();if(thread_.joinable()){thread_.join();}}virtualvoidstop(){stop_=true;}virtualvoidstart(){if(started_.lo

c++ - 环绕模式 std::begin;返回开始(c);进入一个功能

有没有办法将模式包装到一个通用的模板函数中?templateautoBegin(C&&c)->???{usingstd::begin;returnbegin(std::forward(c));}这里的问题是这里函数的返回类型怎么写?我想要这个的原因是我想写一个模板变量templateconstexprboolIsBidirectionalContainer=std::is_base_of()))>::iterator_category>::value;这里的问题是std::begin不会通过ADL为C找到begin的自定义重载。如果有人对此有解决方法,也欢迎使用。

c++ - 作为类成员的可变大小数组 : why does it compile?

我有这种情况,我无法解释它编译的原因:#includeusingnamespacestd;classX{public:X(){cout我正在定义一个可变大小的X数组作为类Y的成员。在类外这样定义X肯定会导致编译错误,但在类内不会。更重要的是,X的构造函数从未被调用。那么这里发生了什么? 最佳答案 C99,6.7.2.1/16(n1256)Asaspecialcase,thelastelementofastructurewithmorethanonenamedmembermayhaveanincompletearraytype;thi

c++ - 提神气 : Take a rule's attribute and set it as a field of an enclosing rule's struct attribute?

像许多其他问题一样,我正在尝试使用Boost.Spirit.Qi将简单语法解析为结构树。我会尽量提炼我正在尝试做的事情,以尽可能最简单的情况。我有:structInteger{intvalue;};BOOST_FUSION_ADAPT_STRUCT(Integer,(int,value))稍后,在语法结构中,我有以下成员变量:qi::ruleinteger;我用它来定义integer=qi::int_;但是,当我尝试实际解析一个整数时,使用qi::phrase_parse(iter,end,g,space,myInteger);myInteger.value在成功解析后始终未初始化。同