iterator

More pythonic way to iterate

I am using a module that is part of a commercial software API. The good news is there is a python module - the bad news is that its pretty unpythonic. To iterate over rows, the follwoing syntax is used: cursor = gp.getcursor(table) row = cursor.next() while row: #do something with row row = cursor.next() What is the most ...

How do you iterate through each email in your inbox using python?

I'm completely new to programming and I'm trying to build an autorespoder to send a msg to a specific email address. Using an if statement, I can check if there is an email from a certain address in the inbox and I can send an email, but if there are multiple emails from that address, how can I make a for loop to send an email for eve...

Is iterator being invalidated?

Is iterator invalidated after: string b "Some string"; auto beg_ = b.begin(); auto end_ = b.end(); b.erase(beg_); ...

Java - Iterator: "Syntax error, parameterized types are only available if source level is 5.0"

Hi! I'm purposely targeting Java OS 1.4.2 I'm trying to use an iterator combined with apache's POI to read an excel spreadsheet. The code runs perfectly in java 1.5, but in the 1.4.2 version I get the error listed in the question subject. the code is: Iterator<HSSFRow> myIter = null; *Updated - Removed the null declaration, and im...

C++ Iterators and inheritance

Have a quick question about what would be the best way to implement iterators in the following: Say I have a templated base class 'List' and two subclasses "ListImpl1" and "ListImpl2". The basic requirement of the base class is to be iterable i.e. I can do: for(List<T>::iterator it = list->begin(); it != list->end(); it++){ ... } ...

Refactoring a "dumb" function into generic STL-style with iterators to containers

I've managed to wrap my head around some of C++'s functional capacities (for_each, mapping functions, using iterators...) but the construction of the templates and function argument lists for taking in generic containers and iterators still eludes me. I have a practical example I'm hoping someone can illustrate for me: Take the followin...

Visual Studio C++ list iterator not decementable

I keep getting an error on visual studio that says list iterator not decrementable: line 256 My program works fine on Linux, but the Visual Studio compiler throws this error. Anyway, do you see what my problem is? #include <iostream> #include <fstream> #include <sstream> #include <list> using namespace std; int main(){ /** crea...

Clean solution to this ruby iterator trickiness?

k = [1,2,3,4,5] for n in k puts n if n == 2 k.delete(n) end end puts k.join(",") # Result: # 1 # 2 # 4 # 5 # [1,3,4,5] # Desired: # 1 # 2 # 3 # 4 # 5 # [1,3,4,5] This same effect happens with the other array iterator, k.each: k = [1,2,3,4,5] k.each do |n| puts n if n == 2 k.delete(n) end end puts k.join(",") ha...

Vector iterators in for loops, return statements, warning, c++

Had 3 questions regarding a hw assignment for C++. The goal was to create a simple palindrome method. Here is my template for that: #ifndef PALINDROME_H #define PALINDROME_H #include <vector> #include <iostream> #include <cmath> template <class T> static bool palindrome(const std::vector<T> &input) { std::vector<T>::const_iterat...

Modify iterator

I have a iterator (ite) created from a set (a): var a = Set(1,2,3,4,5) var ite = a.iterator If I remove 2 element of my set: a -= 2 Now, if I move iterator for all elements, I get all elements (2 element included). It's ok, but... How I can tell to iteratator to delete 2 element? ...

How shall I declare Iterator?

Which form is preferred: String my = "Which form shall I use?"; Iterator iter = my.iterator(); or Iterator<String> iter = my.iterator(); I personally preferr the former but in my materials from uni they use the latter. ...

How can I check if an object is an iterator in Python?

I can try if it has a next() method or something like that. Is there a standard way? ...

Trying to find USB device on iphone with IOKit.framework

Hi all, i'm working on a project were i need the usb port to communicate with a external device. I have been looking for exemple on the net (Apple and /developer/IOKit/usb exemple) and trying some other but i can't even find the device. In my code i blocking at the place where the fucntion looks for a next iterator (pointer in fact) wit...

How to get the number of loop when using an iterator, in C++?

Dear reader, I'm working on a aplication where I draw a couple of images, like this: void TimeSlice::draw(float fX, float fY) { list<TimeSliceLevel*>::iterator it = levels.begin(); float level_x = x; float level_y = y; while(it != levels.end()) { (*it)->draw(level_x,level_y); level_y += (*it)->height; ++it; } } Though th...

Rationale of C# iterators design (comparing to C++)

I found similar topic: http://stackoverflow.com/questions/56347/iterators-in-c-stl-vs-java-is-there-a-conceptual-difference Which basically deals with Java iterator (which is similar to C#) being unable to going backward. So here I would like to focus on limits -- in C++ iterator does not know its limit, you have by yourself compare th...

STL iterators - advantages

What advantages have STL iterators? Why programmers created that notion? ...

[c++/STL] Selective iterator

FYI: no boost, yes it has this, I want to reinvent the wheel ;) Is there some form of a selective iterator (possible) in C++? What I want is to seperate strings like this: some:word{or other to a form like this: some : word { or other I can do that with two loops and find_first_of(":") and ("{") but this seems (very) inefficient t...

STL ostream_iterator writes to screen even though I overwrote it?

In my code, I have the following: ostream_iterator<double> doubleWriter(cout, " ~ "); // ... *doubleWriter = 1.1; doubleWriter++; *doubleWriter = 2.2; *doubleWriter = 3.3; // shouldn't 2.2 be overwritten? doubleWriter++; *doubleWriter = 44.2; cout << endl << endl; I expected it to output this: 1.1 ~ 3.3 ~ 44.2 ~ Instead, the outp...

Strange iterator behaviour

#include "stdafx.h" int _tmain(int argc, _TCHAR* argv[]) { string s = "Haven't got an idea why."; auto beg = s.begin(); auto end = s.end(); while (beg < end) { cout << *beg << '\n'; if (*beg == 'a') {//whithout if construct it works perfectly beg = s.erase(beg); } ...

How to select a random element in std::set?

How can I select a random element in an std::set? I naively tried this: int GetSample(const std::set<int>& s) { double r = rand() % s.size(); return *(s.begin() + r); // compile error } But the operator+ is not allowed in this way. ...