iterator

restart iterator on exceptions in Scala

I have an iterator (actually a Source.getLines) that's reading an infinite stream of data from a URL. Occasionally the iterator throws a java.io.IOException when there is a connection problem. In such situations, I need to re-connect and re-start the iterator. I want this to be seamless so that the iterator just looks like a normal itera...

c++ vector of iterators

I understand that I can point to number of vectors std::vector<int> using for loop on one vector<int*> onev_point_2_all etc.. but how do i do that using iterators is there a way of creating a vector of iterators instead of a vector of pointers ? ...

how do I generate a cartesian product of several variables using python iterators?

Dear all, Given a variable that takes on, say, three values, I'm trying to generate all possible combinations of, say, triplets of these variables. While this code does the trick, site_range=[0,1,2] states = [(s0,s1,s2) for s0 in site_range for s1 in site_range for s2 in site_range] it's somewhat, uhm, clumsy, and is only getting...

how can I implement iteritems function for my custom iterator?

Objective of the following program is to learn python generators and iterator implementation,in order to understand Python magic methods, I've started working on the following example, Here goes my code, I've stucked implementing the iteritems function - also I want to know whether I'm going on right direction or I'm conceptually wrong ...

Is a std::list empty when it is first constructed - even if it is a member of a class?

I have defined a class that contains a std::list as a member. When I create an object of that class, I expected the std::list to be empty. However, I queried the iterators returned by begin() and end() and found that they were not equal. How can I ensure that my std::list member is empty on initial construction of the object? Here is ...

Iterating over a List of Strings In Java?

I am using OpenCSV to read data from a CSV file and am using some of the sample code from the homepage: CSVReader reader = new CSVReader(new FileReader("stockInfo.csv")); List myEntries = reader.readAll(); And i am now trying to loop through this list and print out each entry. But i cannot seem to figure out the code to perform this. ...

Problem with STL map iterator copying

I have an STL map that I want to iterate through, and can't seem to get the code to work. The code is: //PowerupInfo is a struct defined in this class's header file std::map<std::string, PowerupInfo> powerups; ...populate powerups std::map<std::string, PowerupInfo>::iterator iter; for (iter = powerups.begin(); iter != powerups.end(); ...

ADT - Iterators - operator ++

This isnt a homework question. I took data structures at a Community College and now that i am at the university i talked to the teacher about there data structures class. Now, since its really different and the class i took transferred, He gave me one of there assignments and said play with it. We never did any containers, wrappers,temp...

STL iterator: "dereferencing" iterator to a temporary. Is it possible?

Hi there. I'm writing a 3D grid for my scientific software and I need to iterate through the nodes of the grid to get their coordinates. Instead of holding each node object in the container I'd rather like to just calculate the coordinates on the fly while iterating. The problem is that stl::iterator requires to return reference to a va...

jQuery iteration question (confused by example in a book)

I'm working my way through the O'Reilly jQuery Cookbook. On p. 100 there is an example where I don't get one detail. I'm in my first week of looking at jQuery, so that's no surprise, but I'm hoping someone can clarify. The function is a toggle with a few bells & whistles: onValue and offValue are both Booleans, and must have opposite ...

C# iterators and pointers?

I know there are no pointers in C#, but I am trying to figure out how to do the following, which I would have done with pointers (or better yet, iterators) in C++ (I am taking a course in C#, but I already know C++). We got an assignment to write a simple "store" program (inventory, transactions, etc.). My first idea (coming from C++) w...

Read other items in a python list while iterating through it

Possible Duplicate: Python: Looping through all but the last item of a list Is there a better way of iterating through a list when you also need the next item (or any other arbitrary item) in the list? I use this, but maybe someone can do better... values = [1, 3, 6, 7 ,9] diffs = [] for i in range(len(values)): try: diff...

Iterators in VB.NET vNext, and limitations of iterators in C#

I just saw on the Async CTP website that the next version of VB.NET will have iterators. I guess they included iterators because the rewriting process is similar to the one used for the new async/await feature. But reading the document that explains the feature, I realized that VB.NET iterators will actually have features that are not a...

Fast controled copy from istream to ostream

I have to copy several bytes from a istream to a ostream, there are 2 ways that I know to perform this copy. myostream << myistream.rdbuf(); and copy( istreambuf_iterator<char>(myistream), istreambuf_iterator<char>(), ostreambuf_iterator<char>(myostream) ); I've found that rdbuf version is at least twice as fast as th...

One single class for const and non-const iterators. Is it possible?

Hi there, guys! I'm implementing a custom container with an STL-like interface for a 3D grid control for my scientific software. This is my second question regarding the iterator class for this container. Thanks for helping me with the first! My question is just like "How do you avoid code duplication when implementing const and non-co...