How to get the current loop index when using Iterator ?
greetings all i am using an Iterator to iterate through collection and i want to get the current loop index any ideas how to do that ? ...
greetings all i am using an Iterator to iterate through collection and i want to get the current loop index any ideas how to do that ? ...
Lets say I have some kind of collection an I obtained an iterator for the beginning of it. Now lets say I modified the collection. Can I still use the iterator safely? (regardless of the type of the collection or the iterator) To avoid confusion , Here is the order of operations I talk about: Get an iterator of the collection. Modify ...
Why doesn't Set.size() match the number of elements in the set's iterator? I'm using a HashSet, and I added some duplicate values. Those duplicates were automatically eliminated since I used a set. Set.size() is returning 16. When I actually iterate over the elements, I get 13. What can be causing this difference? Am I doing it rig...
I'm defining an iterator type that does not store its current value explicitly. Instead, it's a wrapper around another iterator, and returns std::pairs of the underlying iterator's values and another value. The relevant part of the class definition: class MyIterator : public std::iterator<input_iterator, std::pair<Foo *, Bar *> > { ...
Hi, I'm using Symfony 1.2.7 and Doctrine 1.1. I have $activities (sfOutputEscaperIteratorDecorator - Doctrine_Collection). I'm escaping everything on settings.yml with ESC_SPECIALCHARS method. If I weren't escaping it, it would work without any problem, so I think the problem is related with sfOutputEscaperIteratorDecorator. If I do ec...
Is there an efficient way to know how many elements are in an iterator in Python, in general, without iterating through each and counting? thanks. ...
Hi I'm trying to swap two std::list< dontcare* >::iterators under Visual 2005. Iter it1 = ... ,it2 = ...; // it1 and it2 are ok, not end() or such if(...){ std::swap(it1,it2); } The swap works, but when I leave the if() scope, it1 points to 0xbaadfood. It2 is ok though.I tried several variations, including swap_iter and a hand-ma...
While getting ready for interviews, I decided to code the classic "Find if there are two elements in an array that sum up to a given number" question using iterator logic, so that it can be generalized to other containers than vector. Here's my function so far // Search given container for two elements with given sum. // If two such e...
I am looking through some text file for a certain string with the method. re.finditer(pattern,text) I would like to know when this returns nothing. meaning that it could find nothing in the passed text. I know that callable iterators, have next() and __iter__ I would like to know if I could get the size or find out if it returns no s...
Hi, So I've got a expanding/collapsing tree that I'm keeping track of in session data. I want to be able to render the tree in Django based upon the session data. I am saving the state with something like: request.session['treedata'][item_id] = state # (0 or 1) In my template for rendering, I'm looping through the items and for e...
I have a problem with what appears to be some sort of implicit casting to const when I use iterators. I'm not really sure which code is relevant (if I did I probably wouldn't be asking this question!) so I will try my best to illustrate my problem. typedef set<SmallObject> Container; //not const void LargeObject::someFunct...
I declare: typedef std::tr1::shared_ptr<ClassA> SharedPtr; And then: std::vector<SharedPtr> mList; And: typedef std::vector<SharedPtr>::iterator ListIterator; The return of mList.size() is 0, but when I use iterators, it iterates over the vector which is empty ! This is how I use the iterator: for(ListIterator it = mList.begin(...
I have a std::set and I need to erase similar adjacet elements: DnaSet::const_iterator next = dna_list.begin(); DnaSet::const_iterator actual = next; ++next; while(next != dna_list.end()) // cycle over pairs, dna_list is the set { if (similar(*actual, *next)) { Dna dna_temp(*actual); // copy constructor dna_lis...
Having class : template<class T> class Link { Link* myParent_; Link* myLeft_; Link* myRight_; T* myData_; void assign_(Link<T>*& marker, Link<T>*& aLink); void insert_(const T&);//inserts new data into a link void insert_(const T*); void remove_();//removes data...
Hi, I am trying to write an iterator class which returns a getter function return value when it is dereferenced. The code works fine, my only problem is that I would like to write the member_ptr_functor using only one template parameter and not 3, since I am supposed to be able to deduce the types of the argument and return value from th...
In C#, I can create an iterator (or IEnumerable in C# land) which takes another iterator and selects a member of the original type: class ParentType { public MemberType member { get; private set; } } // And somewhere else IEnumerable<MemberType> getMembers(IEnumerable<ParentType> parents) { for each (ParentType parent in paren...
I'm looking for a better/more Pythonic solution for the following snippet count = sum(1 for e in iterable if e) ...
For any STL container that I'm using, if I declare an iterator (of this particular container type) using the iterator's default constructor, what will the iterator be initialised to? For example, I have: std::list<void*> address_list; std::list<void*>::iterator iter; What will iter be initialised to? ...
I'd like to know what happens when I pass the result of a generator function to python's enumerate(). Example: def veryBigHello(): i = 0 while i < 10000000: i += 1 yield "hello" numbered = enumerate(veryBigHello()) for i, word in numbered: print i, word Is the enumeration iterated lazily, or does it slurp ...
Greetings all, ERROR: Program received signal 'SIGSEGV', Segmentation fault. I am having some issues with the following code creating the above fault in Code::Blocks. It is for a chatbox I am using for a network chat program where the vector is filled with the strings of text for each line of the chat log. I don't see why its throwing...