Here in this Stack Overflow answer it is listed the iterator invalidation rules for the standard containers in C++11. Particularly, there are for insertion : [multi]{set,map} : all iterators and references unaffected [23.2.4/9] unordered_[multi]{set,map} : all iterators invalidated when rehashing occurs, but references unaffected [23.2.5/8]. Rehashing does not occur if the insertion does no
在这个Stack Overflow答案中,它列出了C ++ 11中标准容器的迭代器失效规则。 特别是有插入 : [multi]{set,map} :所有迭代器和引用不受影响[23.2.4 / 9] unordered_[multi]{set,map} :所有迭代器在发生重新哈希时都失效,但引用不受影响[23.2.5 / 8]。 如果插入不会导致容器的大小超过z * B ,则不会发生重新散列,其中z是最大加载因子, B是当前桶的数量。 [23.2.5 / 14] 擦除 : [multi]{set,map}和unordered_[mu
I've read a few posts concerning iterator invalidation, and it seems that inserts that require a vector reallocation would invalidate iterators. Also shouldn't erases in the middle of the vector cause an invalidation? I don't have a clear understanding of this, not sure why using these iterators after resizes and erases from begin, middle, and end doesn't break them: #include
我读过一些关于迭代器失效的帖子,似乎需要向量重新分配的插入会使迭代器无效。 也不应该删除矢量中间导致无效? 我对此没有清楚的理解,不确定为什么在从开始,中间和结束调整大小和擦除之后使用这些迭代器不会破坏它们: #include <cstdlib> #include <iostream> #include <vector> #include <algorithm> using namespace std; int main(int argc, char** argv) { vector<int> v;
The most popular post on C++ Iterator invalidation rules claims that it's not clear if the past-the-end iterators (ie, those returned by end() , cend() , rend() , and crend() ) are invalidated according to the same rules as normal iterators, which point to elements in the container. These claims, made for both 2003 and 2011 C++, defer to a post discussing End iterator invalidation rules, whe
C ++ Iterator失效规则中最受欢迎的帖子声称,不清楚过去最终迭代器(即由end() , cend() , rend()和crend() )返回的迭代器是否根据与常规迭代器相同的规则,它指向容器中的元素。 针对2003年和2011年C ++制定的这些声明都遵循讨论End迭代器失效规则的帖子,其中接受的答案表明2003年的标准在这个问题上含糊不清。 这个结论是基于23.1 / 10中的一个评论(在swap() ),这似乎意味着当规范没有明确提到过时端迭代器的失效时
The STL standard defines that when an erase occurs on containers such as std::deque, std::list etc iterators are invalidated. My question is as follows, assuming the list of integers contained in a std::deque, and a pair of indicies indicating a range of elements in the std::deque, what is the correct way to delete all even elements? So far I have the following, however the problem here is th
STL标准定义,当在诸如std :: deque之类的容器上发生擦除时,std :: list等迭代器将失效。 我的问题如下,假设包含在一个std :: deque中的整数列表和一对指示std :: deque中元素范围的标记,那么删除所有偶数元素的正确方法是什么? 到目前为止,我有以下内容,但是这里的问题是擦除后假定的结束是无效的: #include <cstddef> #include <deque> int main() { std::deque<int> deq; for (int i = 0
Just now, I'm reading Josuttis' STL book. As far as I know -- c++ vector is a c-array that can be reallocated. So, I understand, why after push_back() all iterators and references can become invalid. But my question is about std::deque. As I know it is array of large blocks (c-array of c-arrays). So push_front() inserts element at the beginning and if there is no space, deque alloc
刚才,我正在阅读Josuttis的STL书。 据我所知 - c ++向量是一个可以重新分配的c数组。 所以,我明白,为什么在push_back()之后所有迭代器和引用都可能失效。 但我的问题是关于std :: deque。 据我所知它是一个大块数组(c数组的c数组)。 因此,push_front()在开始处插入元素,如果没有空间,则deque分配新块,并将该元素放置在分配块的末尾。 在中间插入()后,所有引用和迭代器都变为无效,我明白为什么 - 所有
I'm bit confused regarding iterator invalidation in deque. (In the context of this question) Following is the excerpts from -- The C++ Standard Library: A Tutorial and Reference, By Nicolai M. Josuttis Any insertion or deletion of elements other than at the beginning or end invalidates all pointers, references, and iterators that refer to elements of the deque. Following is the excerpt
我对有关迭代器无效的问题感到困惑。 (在这个问题的背景下) 以下是由Nicolai M. Josuttis撰写的“C ++标准库:教程和参考”摘录 任何插入或删除除开头或结尾之外的元素均会使所有指向双端队列元素的指针,引用和迭代器无效。 以下是SGI网站的摘录: iteque失效的语义如下。 插入(包括push_front和push_back )会使所有引用deque的迭代器失效。 在deque中间擦除将导致所有引用deque的迭代器失效。 擦除在deque的开始
I have a hello world cpp file. If I compile it by c++ test.cpp -o test i get "test" file that is executable ( -rwxr-xr-x ) and if I execute it, it is executed and generates an expected result. However, if I use ${CXX} -std=c++0x -I${INCLUDE_DIR1} -c test.cpp -o test -L{LIB_DIR1} -llib_name I also get the "test" file but in this case it is not executable. So, I cannot execu
我有一个你好世界cpp文件。 如果我用c++ test.cpp -o test编译它c++ test.cpp -o test我得到可执行文件( -rwxr-xr-x )的“test”文件,如果我执行它,它会被执行并生成预期的结果。 但是,如果我使用${CXX} -std=c++0x -I${INCLUDE_DIR1} -c test.cpp -o test -L{LIB_DIR1} -llib_name我也会得到“测试”文件,但在这种情况下,不可执行。 所以,我无法执行它。 我尝试了chmod +x ,它获得了执行权限,但是如果我尝试执行它,
This question already has an answer here: What is an undefined reference/unresolved external symbol error and how do I fix it? 27 answers I think the problem is with the 'extern' keyword. That keyword specifies that those values be declared somewhere else in your code. Perhaps you're missing another .c/.cpp file to compile which contains the declarations of those variables. Ag
这个问题在这里已经有了答案: 什么是未定义的引用/未解析的外部符号错误,我该如何解决它? 27个答案 我认为问题在于'extern'关键字。 该关键字指定将这些值在代码中的其他位置声明。 也许你错过了另一个.c / .cpp文件来编译,其中包含这些变量的声明。 同样,包含这个头文件实际上并没有定义任何变量 - 它只是要求它们存在于别的地方! 你已经包含了头文件但没有包含所需的库(实现这些extern对象)。 这
When debugging my code I quite often want to know the value of #define'd constants. But the debugger does not appear to know their values. This means I have to chase around looking at include paths etc to find the #define line. Is there some trick to make this easier? UPDATE: I had to award the green tick to Tony D for his detailed answer of the headline question, but I have also upvoted
在调试我的代码时,我经常想知道#defined'd常量的值。 但调试器似乎并不知道它们的值。 这意味着我必须四处寻找包含路径等以查找#define行。 有一些技巧可以让这更简单吗? 更新:我必须授予托尼D绿色记号标题问题的详细答案,但我也upvoted使用const而不是#define(我也测试过, enum也可以)。 最后,使用F12来查找原始的#define行是另一个好主意。 对于Google的价值10分钟,似乎Visual Studio不支持这一点。 有
This question already has an answer here: How does the compilation/linking process work? 5 answers 在Makefile中Makefile与源文件分开的目标文件是有意义的,因为这样就不需要从未触及的源文件中重新生成目标文件。
这个问题在这里已经有了答案: 编译/链接过程如何工作? 5个答案 在Makefile中Makefile与源文件分开的目标文件是有意义的,因为这样就不需要从未触及的源文件中重新生成目标文件。