iterator

"Generic" iterator in c++

I have: void add_all_msgs(std::deque<Message>::iterator &iter); How can I make that function "generic", so it can take any kind of inputiterators ? I don't really care if it's iterating a deque,a vector or something else, as long as the iterator is iterating Message's. - is this at all straight forward possible in c++ ? ...

Python: StopIteration exception and list comprehensions

I'd like to read at most 20 lines from a csv file: rows = [csvreader.next() for i in range(20)] Works fine if the file has 20 or more rows, fails with a StopIteration exception otherwise. Is there an elegant way to deal with an iterator that could throw a StopIteration exception in a list comprehension or should I use a regular for l...

sort using timestamp and struts2 tag iterate

Hello, I am using strus2 tags in a jsp to iterate over a collection: <s:if test="parent.entries.size > 0"> <table border="3"> <s:iterator value="parent.entries"> <tr /> <td><s:property value="entry"></td> <td><s:property value="date" ></td> </tr> </s:iterator> </table> </s:if> I ...

Issue with Iterator.remove() with JSONObject in GWT

Hey everyone, I have succesfully been able to parse a JSON into a JSONTree, however, my tree shows the iterators. I have tried iterator.remove(), but I get the error: Error: java.lang.UnsupportedOperationException: Remove not supported on this list Can someone please look at my code, and let me know of anything I can do? Thanks! publ...

how can a compiler that recognizes the iterators be implemented?

I have been using iterators for a while and I love them. But although I have thought hard about it, I could not figure out "how a compiler that recognizes the iterators" be implemented. I have also researched about it, but could not find any resource explaining the situation in the compiler-design context. To elaborate, most of the art...

Writing a reusable data iterator for SQL Server 2005/2008

i am trying to write a data iterator for SQL, it looks like the best approach is to cook up some dynamic sql for this problem. I want the iterator to support paging, sorting, and filtering of the data, and ideally not iterate over a memory copy but to not even select the data in the first place, perhaps LINQ to SQL or Entity Framework w...

Named Iterator & Exceptions

Hi, I am writing a method which needs to check some parameters and if they are validated return an IEnumerable. E.g. public static IEnumerable<double> GetEnum(int param) { if (!IsValidParameter(param)) { throw new Exception(); } while(true) { yield return 5.0; } } However, I believe because of...

Python iterators – how to dynamically assign self.next within a new style class?

As part of some WSGI middleware I want to write a python class that wraps an iterator to implement a close method on the iterator. This works fine when I try it with an old-style class, but throws a TypeError when I try it with a new-style class. What do I need to do to get this working with a new-style class? Example: class Iterator...

C++ container of iterators and circular references

I'd like to create two containers that contain iterators to each other. I'd like to do this hopefully without introducing any intermediate/indirect types. Is this possible or do iterator types depending on knowing the size of the container's data type? Here is some sample code that I'd like to get compiling: #include <map> #include <de...

Java Joda Time - Implement a Date range iterator

Hi all, I'm trying to implement without success a Date iterator with Joda time. I need something that allows me to iterate all the days form startDate to endDate Do you have any idea on how to do that? ...

hitting a next button for a UITableViewcell

Hello all , I was wondering how I can realize the following: Creating a next button and when it's tapped the next UITableview row will be selected. Since a picture is worth a thousand words I've added a screenshot. http://img529.imageshack.us/img529/4341/picture5uuj.png As you can see below I added a toolbar and if I press the rig...

Comparing default-constructed iterators with operator==

Does the C++ Standard say I should be able to compare two default-constructed STL iterators for equality? Are default-constructed iterators equality-comparable? I want the following, using std::list for example: void foo(const std::list<int>::iterator iter) { if (iter == std::list<int>::iterator()) { // Something } } ...

Calling remove in foreach loop in Java

In Java, is it legal to call remove on a collection when iterating through the collection using a foreach loop? For instance: List<String> names = .... for (String name : names) { // Do something names.remove(name). } As an addendum, is it legal to remove items that have not been iterated over yet? For instance, //Assume that...

Does it make sense to implement iterators for containers which has no obvious end - e.g. trees?

I`m writing binary search tree template for two reasons - learning C++ and learning most common algorithms and data structures. So, here is the question - as long as I want to implement iterators, it seems to me that there is no strict definition for where tree ends. What are your suggestions? How do I do this? ...

Need to get the rest of an iterator in python

Say I have an iterator. After iterating over a few items of the iterator, I will have to get rid of these first few items and return an iterator(preferably the same) with the rest of the items. How do I go about? Also, Do iterators support remove or pop operations (like lists)? ...

Why do we need iterators in c#?

Can somebody provide a real life example regarding use of iterators. I tried searching google but was not satisfied with the answers. ...

Java parallel work iterator?

I'm looking for a class where I can override a method to do the work, and return the results like an iterator. Something like this: ParallelWorkIterator<Result> itr = new ParallelWorkIterator<Result>(trials,threads) { public Result work() { //do work here for a single trial... return answer; } }; while (itr.hasNext()) { ...

How do I alter array keys and values while using a RecursiveArrayIterator?

I suspect I'm doing something stupid here, but I'm confused by what seems like a simple problem with SPL: How do I modified the contents of an array (the values in this example), using a RecursiveArrayIterator / RecursiveIteratorIterator? Using the follow test code, I can alter the value within the loop using getInnerIterator() and off...

how to init an iterator

hi folks, i just intent to initialize an iterator over a generic linked list like that (generic typ T seems to be erased in here since the site interpret it as tag) public <T> LinkedList<T> sort(LinkedList<T> list){ Iterator<T> iter = new list.iterator(); ... but i got the error: "list cannot be resolved" what's wrong? ...

Is there a generic way to iterate over a specific variable in a group of objects?

Lets say I have a linked list with a bunch of different data in it. class Node { public: Node* next; AAA dataA; BBB dataB; CCC dataC; }; Is there a way I make one iterator that would iterate over whatever variable I specify (rather than making three separate ones for each variable). I understand that the iterator coul...