iterator

Segmentation fault from std::_Rb_tree_const_iterator<Type>::operator++

I get a segmentation fault when iterating over a set. The stack trace points to std::_Rb_tree_const_iterator<Type>::operator++ std::_Rb_tree_increment() but I get nothing more informative. The iterator is over a set returned by a function for (FactSet::factset_iterator fact_it = (*binSet_it).getDependencyGraph().getExtentionalFactSe...

Custom STL-like iterator for RedBlackTree implementation

I need an STL-like bidirectional iterator (operator<, begin(), rbegin(), end(), rend()) as an inner class to the following (I already spent considerable time all by myself to put together a working tree from a C# article in J of Object Tech and translated it to C++): template<typename K, typename V> class rbtree { public: rbtree()...

Does a Java container offer a fail-safe iterator

Here is my problem: This piece of code throws a java.util.ConcurrentModificationException, because the Vector listeners is modified while there exists an Iterator for this data structure. The java-doc says that this container offers only a fail-fast iterator. Is there a possibility to get an Iterator over a standard container like Vec...

[newb] C++ const iterator C2662

Hi All, Having problems iterating. Problem has to do with const correctness, I think. I assume B::getGenerate() should be const for this code to work, but I don't have control over B::getGenerate(). Any help is greatly appreciated. Thanks in advance, jbu Code follows: int A::getNumOptions() const { int running_total = 0; BL...

What is the best way to get the first item from an iterable matching a condition?

In Python, I would like to get the first item from a list matching a condition. For example, the following function is adequate: def first(the_iterable, condition = lambda x: True): for i in the_iterable: if condition(i): return i This function could be used something like this: >>> first(range(10)) 0 >>> firs...

Checking if an iterator references an item in a list

Hey, i just want to check, if the iterator points on an object in a list. What's the cmd? Thank you. :) SkyThe EDIT: Hmm,.. ok i tried it. Now there is a Error: "Expression: list iterators incompitable" Maybe some code: #include <list> list<obj> list; list<obj>::iterator it; if(it != list.end()){ //here the error pops up when i ...

MovePrevious & MoveNext iterator in C#

Hi, I have implement Wizard type of screen windows forms application. In the wizard screen contains Back,Next & Finish buttons. When i click Next button i have to launch next screen in Wizard form, suppose i click Back button i have to launch previous screen in to Wizard Form. I don't know how to handle screen information in Back&Ne...

Input stream iterators and exceptions

I was playing around with istream iterators and exception handling a few days ago and I came across with this curiousity: #include <iostream> #include <fstream> #include <iterator> #include <algorithm> using namespace std; int main(int argc, char* argv[]) { if (argc < 2) { cout << argv[0] << " <file>" << endl; return -1...

Using a std::string iterator to find the start and end of it's string

Hi, Given just a std::string iterator, is it possible to determine the start and end points of the string? Supposing that I don't have access to the string object and so cannot call string.begin() and string.end(), and all I can do is increment or decrement the iterator and test the value. Thanks, Phil ...

Can't create a list of elements linked by a "Parent".

I'm trying to create a method (using the A* algorithm) that solves a puzzle and returns the steps to that solution. The solution it's easy.. but I can't return the path to that. I used a list of Nodes and then every time a push back a new Node I set the parent pointing to the Node which new came; list<Node> opened; list<Node> closed; ...

Efficient looping through AS3 dictionary

for (var k in dictionary) { var key:KeyType = KeyType(k); var value:ValType = ValType(dictionary[k]); // <-- lookup // do stuff } This is what I use to loop through the entries in a dictionary. As you can see in every iteration I perform a lookup in the dictionary. Is there a more efficient way of iterating the dictionary (while...

How to navigate through a vector using iterators? (C++)

The goal is to access the "nth" element of a vector of strings instead of the [] operator or the "at" method. From what I understand, iterators can be used to navigate through containers, but I've never used iterators before, and what I'm reading is confusing. If anyone could give me some information on how to achieve this, I would appr...

Iterator is used in java?

In java while using the HashMap, they are using the Iterator class. But I can't understand for what purpose they are using Iterator in HashMap? ...

C++: building iterator from bits

I have a bitmap and would like to return an iterator of positions of set bits. Right now I just walk the whole bitmap and if bit is set, then I provide next position. I believe this could be done more effectively: for example build statically array for each combination of bits in single byte and return vector of positions. This can't be ...

Inserting into a specific part of a string using iterators? (C++)

string str = "one three"; string::iterator it; string add = "two "; Lets say I want to add: "two " right after the space in "one". the space would be str[3] correct? so: in this case, n = 3; for (it=str.begin(); it < str.end(); it++,i++) { if(i == n) { // insert string add at current position ...

Is perl's each function worth using?

From perldoc -f each we read: There is a single iterator for each hash, shared by all each, keys, and values function calls in the program; it can be reset by reading all the elements from the hash, or by evaluating keys HASH or values HASH. The iterator is not reset when you leave the scope containing the each(), and this can le...

Iterator from both ends of a Vector

Hi, I have a vector of IntRect: vector. How can I iterate from both ends of the list and stop the iterator when the iterator intersects? vector<IntRect>::iterator itr = myVector.begin(); vector<IntRect>::reverse_iterator revItr.rbegin(); for (; /*check itr and revItr does not intersect, and itr and revItr do not end */ ; ++itr, +...

String vectors not working as expected with newline and iterators? (C++)

I have a text file made of 3 lines: Line 1 Line 3 (Line 1, a blank line, and Line 3) vector<string> text; vector<string>::iterator it; ifstream file("test.txt"); string str; while (getline(file, str)) { if (str.length() == 0) str = "\n"; // since getline discards the newline character, replacing blank strings with newline ...

Vector iterator

I have class CBase { ....... }; class CDerived : public CBase { ...... }; vector<CBase*> mpBase; vector<CDerived*>::iterator InfoIt; InfoIt=mpBase.begin(); VC++ 2008 generates error C2679. What's wrong? ...

How to save Columns of a grid as rows in db.

I want to save grid columns as rows in db. Please see the following image. Columns 'Full Package' is saved as row in db but I have make it as column. 'Package for 1' is new record, each Event Member must be saved as individual record in db. There might be more columns like this. I need to save/update records in one go. Thanks. ...