草庐IT

col_iterator

全部标签

c++ - 如何将 BOOST_FOREACH 与仅支持 const_iterator 的容器一起使用?

我有这个容器:class/*final*/Row{public:typedefFieldIteratorconst_iterator;typedefFieldIteratoriterator;FieldIteratorbegin()const;FieldIteratorend()const;FieldIteratorbegin();FieldIteratorend();...};鉴于此,以下代码可以正常编译:BOOST_FOREACH(Fieldfield,row){}但是,Row类不应该有可变迭代器,所以我更改了Row类,删除了可变访问:class/*final*/Row{publi

c++ - 重载 >> istream_iterator 对

这个问题在这里已经有了答案:Dependentnameresolution&namespacestd/StandardLibrary(1个回答)关闭7年前。我正在尝试构建对上的ifstream_iterator。我的代码如下:typedefpairT;istream&operator>>(istream&stream,T&in){stream>>in.first>>in.second;returnstream;}intmain(intargc,char**argv){ifstreaminfile("dummy2");istream_iteratoriit(infile);istream

c++ - Visual Studio regex_iterator 错误?

我在使用VisualStudio2013,我看到了一个我认为是错误的东西,我希望有人可以确认吗?stringfoo{"A\nB\rC\n\r"};vectorbar;for(sregex_iteratori(foo.cbegin(),foo.cend(),regex("(.*)[\n\r]{1,2}"));i!=sregex_iterator();++i){bar.push_back(i->operator[](1).str());}此代码在VisualStudio正则表达式库中命中调试断言:regex_iteratororphaned如果我在for循环之外定义regex没问题:str

c++ - 用 gcc 编译 std::regex_iterator

我可以使用g++-ctest.cpp-std=c++0x创建.o文件,但无法链接它,出现下一个错误:test.cpp:(.text+0xe5):undefinedreferenceto`std::regex_iterator>::regex_iterator(charconst*,charconst*,std::basic_regex>const&,std::bitset)'test.cpp:(.text+0xf1):undefinedreferenceto`std::regex_iterator>::regex_iterator()'代码:#include#include#inclu

c++ - std::filesystem::directory_iterator 链接器问题 (C++17)

这个问题在这里已经有了答案:LinkerrorsusingmembersinC++17(4个答案)关闭4年前。在尝试使用C++17标准中的std::filesystem::directory_iterator时,我的C++构建出现问题。代码如下:std::vectorIO::getDirectoryList(std::filesystem::path&dirPath){std::vectorfiles;for(auto&file:std::filesystem::directory_iterator(".")){files.push_back(file.path());}returnf

c++ - 特化 iterator_traits

我想专攻std::iterator_traits对于不具有通常的嵌套typedef(如value_type、difference_type等)的容器类模板的迭代器,我不应该修改其源代码。基本上我想做这样的事情:templatestructiterator_traits::iterator>{typedefTvalue_type;//etc.};除了这不起作用,因为编译器无法推断出T来自Container::iterator.有什么可行的方法可以达到同样的目的吗?例如:templateclassSomeContainerFromAThirdPartyLib{typedefTValueTy

C++ 标准 : Unexpected const_iterator in multiset

我最近遇到了一个奇怪的问题,在遍历多重集时,我得到的是const_iterator而不是预期的iterator。结果证明这对MSVC来说不是问题,但g++给了我一个错误:error:invalidinitializationofreferenceoftype'myPtr&'fromexpressionoftype'constboost::shared_ptr'相关代码:typedefstd::multisetmyList;myList_mystuff;voidtick(floatdt){for(myList::iteratori=_mystuff.begin();i!=_mystuff

C++ 模板 std::vector::iterator 错误

在C++中,我试图获得std::vector::iterator对于我的模板类。但是,当我编译它时,出现错误:errorC2146:syntaxerror:missing';'beforeidentifier'iterator',errorC4430:missingtypespecifier-intassumed.Note:C++doesnotsupportdefault-int.我也收到警告:warningC4346:'std::vector::iterator':dependentnameisnotatype:#includetemplateclassv1{typedefstd::

c++ - 可以安全地存储 list::iterator 供以后使用吗?

假设我有一个列表,其中没有添加或删除新节点。但是,节点可能会被打乱。保存一个迭代器,指向列表中的一个节点,并在以后任意时间访问它是否安全?编辑(后续问题):list::splice()的文档说它从参数列表中删除元素。这是否意味着如果我调用splice,使用相同的列表作为函数的参数,现有的迭代器将失效? 最佳答案 是的。迭代器进入列表的标准受赠者不会失效,除非他们指向(比喻地说)的项目从列表中删除。从这个页面:http://www.sgi.com/tech/stl/List.htmlListshavetheimportantprope

c++ - 为什么 opencv 的 Mat::rows 和 Mat::cols 是有符号的而不是无符号的?

我正在用gcc的-Wall标志编译一个程序。我在某些时候对Mat::cols和Mat::rows进行了比较(使用无符号整数),并收到有关比较有符号和无符号整数的警告。虽然放弃它没什么大不了的,但我很好奇Mat具有负大小的基本原理是什么。从逻辑上讲,矩阵不能比空矩阵(0行0列)更空,那么具有-1行或-1列的矩阵意味着什么?Theredoesn'tseemtobemuchperformancedifferencebetweencomputationsonsignedandunsignedintseither. 最佳答案 我想是因为int