Browsing Questions About iterator (1)
Build a Basic Python Iterator
How would one create an iterative function (or iterator object) in python?
How to make a tree in C++?
How do I make a tree data structure in C++ that uses iterators instead of pointers? I couldn't find anything in the STL that can do this. What I would like to do is to be able to create and manipulate trees like this:
#include <iostream>
#include <tree>
using namespace std;
int main()
{
tree…
How do I write a for loop in bash
I'm looking for the basic loop like:
for(int i = 0; i < MAX; i++) {
doSomething(i);
}
but for bash.
Assigning a Boost Xpressive token iterator range to a vector
I'm having some trouble getting Boost Xpressive to work as I expect. I'm trying to split a line of text into fields delimited by tab characters:
wstring ws = L"Field1\tField2\tField3";
wsregex_token_iterator fieldIt(ws.begin(), ws.end(), as_xpr(L'\t'), -1);
wsregex_token_iterator endIt;
So…
Iterators in C++ (stl) vs Java, is there a conceptual difference?
I'm returning to c++ after being away for a bit and trying to dust off the old melon.
In Java Iterator is an interface to a container having methods: hasNext(), next() and remove(). The presence of hasNext() means it has the concept of a limit for the container being traversed.
//with an Ite…
Iterate with for loop or while loop?
I often see code like:
Iterator i = list.iterator();
while(i.hasNext()) {
...
}
but I write that (when Java 1.5 isn't available or for each can't be used) as:
for(Iterator i = list.iterator(); i.hasNext(); ) {
...
}
because
It is shorter
It keeps i in a smaller scope
It …
Python idiom to chain (flatten) an infinite iterable of finite iterables?
Suppose we have an iterator (an infinite one) that returns lists (or finite iterators), for example one returned by
infinite = itertools.cycle([[1,2,3]])
What is a good Python idiom to get an iterator (obviously infinite) that will return each of the elements from the first iterator, then e…
Returning an 'any kind of input iterator' instead of a vector::iterator or a list::iterator
Suppose I want to implement in C++ a data-structure to store oriented graphs. Arcs will be stored in Nodes thanks to STL containers. I'd like users to be able to iterate over the arcs of a node, in an STL-like way.
The issue I have is that I don't want to expose in the Node class (that will act…
Is a variable named i unacceptable?
As far as variable naming conventions go, should iterators be named i or something more semantic like count ? If you don't use i , why not? If you feel that i is acceptable, are there cases of iteration where it shouldn't be used?
Why use iterators instead of array indices?
Take the following two lines of code:
for (int i = 0; i < some_vector.size(); i++)
{
//do stuff
}
And this:
for (some_iterator = some_vector.begin(); some_iterator != some_vector.end();
some_iterator++)
{
//do stuff
}
I'm told that the second way is preferred. Why exactly is th…
Algorithm for implementing C# yield statement
I'd love to figure it out myself but I was wondering roughly what's the algorithm for converting a function with yield statements into a state machine for an enumerator? For example how does C# turn this:
IEnumerator<string> strings(IEnumerable<string> args)
{ IEnumerator<string> enumerator2 =…
What is the best way to obtain an index into a vector when using Iterators to loop over it
When iterating over elements of a vector it is preferred to use iterators instead of an index (see Why use iterators instead of array indices? ).
std::vector<T> vec;
std::vector<T>::iterator it;
for ( it = vec.begin(); it != vec.end(); ++it )
{
// do work
}
However, it can be necessary to…
splice() on std::list and iterator invalidation
The 3-argument form of list::splice() moves a single element from one list to the other. SGI's documentation explicitly states that all iterators, including the one pointing to the element being moved remain valid. Roguewave's documentation does not say anything about iterator invalidation prope…
C++ Creating my own Iterators
I'm trying to learn C++ so forgive me if this question demonstrates a lack of basic knowledge, you see, the fact is, I have a lack of basic knowledge.
I want some help working out how to create an iterator for a class I have created.
I have a class 'Shape' which has a container of Points.
I…
C++ last loop iteration (STL map iterator)
I'm trying to figure out the best way to determine if I'm in the last iteration of a loop over a map in order to do something like the following:
for (iter = someMap.begin(); iter != someMap.end(); ++iter) {
bool last_iteration;
// do something for all iterations
if (!last_iteration) {
…
Next Page >