草庐IT

is_iterator

全部标签

c++ - 使用带有 split_iterator 的分类器

关于boost字符串算法,我似乎遗漏了一些东西。我正在尝试将split_iterator与使用Clasifier作为拆分点一起使用。所以,例如,我希望能够做这样的事情:make_split_iterator(str,is_space);但是make_split_iterator需要一个Range和一个Finder。所以我需要的是找到一些序列来从分类器创建查找器。有谁知道如何做到这一点,或者甚至可能吗? 最佳答案 您可以使用token_finder,如make_split_iterator(str,token_finder(is_sp

c++ - 术语的含义 - Resource Acquisition Is Initialization

我知道RAII的作用。当/如果代码抛出异常时,这都是为了防止内存泄漏等。现在,我想了解那个智能术语的含义。http://en.wikipedia.org/wiki/AcquisitionAcquisition意味着获得某物。那么,当我们说资源获取就是初始化时,这是什么意思?我只是在这里谈论这个术语的含义,而不是一般的概念。 最佳答案 之前有人说过(可能是ScottMeyers说的,我记不清了),RAII应该被称为“Destructionisresourcerelease”,或者类似的词。“资源获取即初始化”字面上的意思是,当一个对象

c++ - istream_iterator cin 初始化等待输入

我有这个代码片段。istream_iterator对象仅被定义而未被使用,因此我预计它不会执行任何操作并且应用程序会立即完成。但是当我运行应用程序时,在我提供一些输入之前它不会完成。为什么?我在ArchLinux上编译它:gcc4.7.1,命令:g++-std=c++11filename.cpp#include#includeusingnamespacestd;intmain(intargc,char*argv[]){istream_iteratorinput(cin);return0;} 最佳答案 按照标准,24.6.1.1ist

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::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++ - `is_trivially_destructible` 不适用于继承类

#includeusingnamespacestd;classNoConstructOperation{protected:NoConstructOperation()=default;virtual~NoConstructOperation()=default;public:NoConstructOperation(constNoConstructOperation&)=delete;NoConstructOperation&operator=(NoConstructOperation&)=delete;NoConstructOperation(NoConstructOperatio

c++ - map<T,T>::iterator 作为参数类型

我有一个带有私有(private)映射成员的模板类templateclassMyClass{public:MyClass(){}private:std::mapmyMap;}我想创建一个接受映射迭代器的私有(private)方法voidMyFunction(std::map::iterator&myIter){....}但是,这会出现编译错误:标识符“迭代器”。我不需要传递一个抽象迭代器,因为MyFunction知道它是一个映射迭代器(并且只会用作myMap的交互器)并且会这样对待它(访问和修改myIter->second)。将myIter->second传递给MyFunction是不

C++ 初学者 : what is the point of using a variable by reference if using "const"?

我想知道这个函数声明中的逻辑:CMyException(conststd::string&Libelle=std::string(),...按引用使用变量有什么意义?通常,只要变量可能在内部被修改,您就会通过引用传递一个变量...因此,如果您使用关键字const,这意味着它永远不会被修改。这是矛盾的。谁能给我解释一下? 最佳答案 实际上引用是用来避免不必要的对象拷贝。现在,要理解为什么使用const,试试这个:std::string&x=std::string();//error编译会报错。这是因为表达式std::string()创

c++ - "vector iterator + offset out of range"断言有用吗?

这个完美的程序在VisualStudio2013的Debug模式下失败:#include#include#includeusingnamespacestd;voidmain(){vectorv={3,1,4,1,5,9,2,6,5,3};for(autoiFrom=v.cbegin(),iTo=iFrom+5;iFrom!=v.cend();iFrom=iTo,iTo+=5)coutvectoriterator+offsetoutofrange断言失败。它失败是因为iTo>v.cend(),这在这里是无害的。调试器测试没有被取消引用的迭代器的值有什么意义?顺便说一句,我知道我可以将上面

JSON parse error: Illegal character ((CTRL-CHAR, code 31)): only regular white space (\r, \n, \t) is

JSONparseerror:Illegalcharacter((CTRL-CHAR,code31)):onlyregularwhitespace(\r,\n,\t)isallowedbetweentokens;nestedexceptioniscom.fasterxml.jackson.core.JsonParseException:Illegalcharacter((CTRL-CHAR,code31)):onlyregularwhitespace(\r,\n,\t)isallowedbetweentokensat[Source:(org.springframework.util.Strea