iterator

How to define an iterator in a template?

Hello, I'm trying to define an iterator to iterate my map to erase it (destructor) I'm getting an error : incompatible iterator. My destructor looks like this : Consortium<S,T>::~Consortium() { map<const S, Node<T>*>::iterator deleteIterator; for (m_consortiumMap.begin() ; deleteIterator != m_consortiumMap.end() ; del...

How Do I define a Double Brackets/Double Iterator Operator, Similar to Vector of Vectors'?

I'm porting code that uses a very large array of floats, which may trigger malloc failures from c to c++. I asked a question about whether I should use vectors or deques and Niki Yoshiuchi generously offered me this example of a safely wrapped type: template<typename T> class VectorDeque { private: enum TYPE { NONE, DEQUE, VECTOR }; ...

How to generate a random partition from an iterator in Python

Given the desired number of partitions, the partitions should be nearly equal in size. This question handles the problem for a list. They do not have the random property, but that is easily added. My problem is, that I have an iterator as input, so shuffle does not apply. The reason for that is that I want to randomly partition the nodes...

returning an iterator

How i return iterator form function : i worte this : . .. template<class S,class T> class Database { public: . .. map<S,Node<T>*> m_map::iterator Find (S keyToFind); . .. .... private: . .. map<S,Node<T>*> m_map; .. . }; . .. template<class S,class T> map<S,Node<T>*> m_map::iterator Find (S keyToFind) { map<S,Node<T>*>::iterator ...

Python: binary tree traversal iterators without using conditionals

I am trying to create a module in python for iterating over a binary tree using the 4 standard tree traversals (inorder, preorder, postorder and levelorder) without using conditionals and only using polymorphic method dispatch or iterators. The following examples should work. for e in t.preorder(): print(e) for e in t.postorder(): ...

What are C# Iterators and Generators, and how could I utilize them

I am a VB.Net developer, kind of newbie in C#, While looking in C# documentation I came through Iterators and Generators, could not fully understand the use, I there anyone who can explain (in vb perceptive; if possible) ...

RunTime Error : map/set iterators incompatible

hi, i have Runtime Error "map/set iterators incompatible" in line &&&&&& void Manager::Simulate(Military* military, Shalishut* shalishut,char* args[]){ Simulation* simulation = Simulation::GetInstance(); Time* time = Time::GetInstance(); multimap<int,Task*>::iterator itTasks; itTasks = simulation->GetTasks().begin(); while(itTa...

Runtime Error : RunTime Error : map/set iterators incompatible

void Manager::Simulate(Military* military, Shalishut* shalishut,char* args[]){ Simulation* simulation = Simulation::GetInstance(); Time* time = Time::GetInstance(); multimap<int,Task*>::const_iterator itTasks; itTasks = simulation->GetTasks().begin(); while(itTasks != simulation->GetTasks().end()){ while (itTa...

What is the Perl version of a Python iterator?

I am learning Perl at my work and enjoying it. I usually do my work in Python but boss wants Perl. Most of the concepts in Python and Perl match nicely: Python dictionary=Perl hash; Python tuple=Perl list; Python list=Perl array; etc. Question: Is there a Perl version of the Python form of an Iterator / Generator? An example: A Cla...

Why is this vector iterator not incrementable?

i'm trying to delete the vector's content and i'm getting an error - vector iterator is not incrementable, why is that? this is my destructor City::~City() { vector <Base*>::iterator deleteIterator; for (deleteIterator = m_basesVector.begin() ; deleteIterator != m_basesVector.end() ; deleteIterator++) m_basesVector....

Java NIO for merging sorted files?

I have a bunch of text files on disk, each one is just a sorted list of nonnegative integers, newline delimited: 2 14 67 134 654 1130 My files are pretty big - they can easily contain hundreds of millions of numbers. I want to write a Java program to read each of these files and write out a new text file containing all of the numbers ...

Creating an O(1)-memory Iterable from an initial object and a function which generates the next object, in Scala

I want a convenient way to generate an Iterable, given a initial object and a function to produce the next object from the current one, that consumes O(1) memory (i.e., it doesn't cache old results; if you want to iterate a second time, the function has to be applied again). It doesn't seem like there's library support for this. In Scal...

How to use an iterator in this case ?

I have to iterate through an arraylist in this manner. ArrayList<Integer> li = new ArrayList<Integer>(); li.add(20); li.add(30); li.add(40); li.add(50); li.add(70); for (int i = 0; i < li.size() - 1; i++) System.out.println(li.get(i) + " " + li.get(i + 1)); Output: 20 30 30 40 40 50 50 70 How to do the same using an iterator? ...

How do you do nested iterators in groovy?

Does groovy support any kind of nested iterator notation? In the example below, I want to somehow get the projectName value, that came from the outer iterator, into my inner iterator. Is this possible without storing in a variable? In my example I get a runtuime error that "project" is not found it.myprojects.project.each{ println...

Why do I need a Forward Iterator to implement my customized std::search

I am studying the book "Accelerated C++" from Koenig & Moo. Exercise 8-2 ask me to implement on my own some templatized functions from <algorithm> and <numeric>, and to specify what kind of iterator does my implementation require. When trying to implement std::search, I determined that I need only "input" iterators. Here is my code s...

Using Insert Iterators when reading from file.

can you use Insert Iterators while reading from a file to put the data into STL container? for example: FILE *stream; fread(back_inserter(std::list), sizeof(int), 1, stream); ...

C++: Loop over two vectors, remove elements of 1

Hi there, I have the following toy code, intended to remove duplicates from a vector: void overlap_removal(vector<int> &vec1, vector<int> &vec2) { for (vector<int>::iterator it1 = vec1.begin(); it1 != vec1.end(); ++it1) { for (vector<int>::iterator it2 = vec2.begin(); it2 != vec2.end(); ++it2) { if ((*it1)*(*it2) < 10) { ...

LinkedList implementation in Java with generics and enhanced for

Hi. I need you to review my implementation of a Singly Linked List (SLL) please. The implementation should use generics and be able to use the enhanced for. The problem is that, when I do for (Number n : list) being list a MyLinkedList<Integer> or MyLinkedList<Double>, I get the error: "Type mismatch: cannot convert from element type O...

How to write "First of every month in Ruby"

I'm trying to write an iterator in ruby that sends a callback on the first of every month. How would you write something like that? ...

Ruby iterator for non-seekable stream

I want to read data records from a non-seekable stream in Ruby. I want to leave it up to the user whether the current record should be skipped or read. Usually you would include Enumerable and provide the necessary methods for it to have an iterator in Ruby, but in my case data can be skipped and only one iteration is possible, so I'm no...