iterator

Mutable wrapper of value types to pass into iterators

I'm writing an iterator that needs to pass around a mutable integer. public IEnumerable<T> Foo(ref int valueThatMeansSomething) { // Stuff yield return ...; } This nets me "Error 476 Iterators cannot have ref or out parameters". What I need is this integer value to be modified in the iterator and usable by the caller of the...

Can a Ruby method yield as an iterator or return an array depending on context?

I have an arbitrary method in Ruby that yields multiple values so it can be handed to a block: def arbitrary yield 1 yield 2 yield 3 yield 4 end arbitrary { |x| puts x } I'd like to modify this method so that, if there is no block, it just returns the values as an array. So this construct would work as well: myarray = arbitr...

Implementing a generic fixed size array with iterator support [C++]

I need an array where size is known at compile time. I know I can use std::vector or boost::array. But that's doesn't teach me how it works internally. Also I couldn't find how to add items into boost::array other than using the initializer. I have written the following code for a generic array. My intention is to get familiar with itera...

Converting Enumeration to Iterator

I have the following implicit conversion for java.util.Enumerations implicit def enumerationIterator[A](e : Enumeration[A]) : Iterator[A] = { new Iterator[A] { def hasNext = e.hasMoreElements def next = e.nextElement def remove = throw new UnsupportedOperationException() } } Unfortunately it doe...

Search an attribute inside a Vector on Java

I've a Vector of objects, and have to search inside for a random attribute of those objects (For example, a Plane class, a Vector containing Plane; and I've to search sometimes for destination, and others to pilotName). I know I can traverse the Vector using an Iterator, but I've got stuck at how do I change the comparison made between ...

Iteration in JQuery

Hi, I am new to jQuery. I am having a variable increment in my code which shows how many divs inn mne of the panel. I want to iterate through those divs to get the properties of the labels, input type ,size everything inside each div. Starting from 1, i want to iterate up to increment .. How can i do so in JQUery? Please give me a su...

How to increment an iterator by 2?

Hi Can anybody tell me how to increment the iterator by 2 times. iter++ is available - I have to do iter+2 how can I achieve this. ...

What if I increment an iterator by 2 when it points onto the last element of a vector?

In this question asking how to adjust the iterator to an STL container by 2 elements two different approaches are offered: either use a form of arithmetic operator - +=2 or ++ twice or use std::advance() I've tested both of them with VC++ 7 for the edge case when the iterator points onto the last element of the STL container or beyon...

"On-line" (iterator) algorithms for estimating statistical median, mode, skewness, kurtosis?

Is there an algorithm to estimate the median, mode, skewness, and/or kurtosis of set of values, but that does NOT require storing all the values in memory at once? I'd like to calculate the basic statistics: mean: arithmetic average variance: average of squared deviations from the mean standard deviation: square root of the varianc...

C++ : How to write a const_iterator?

I've written my own container template with an iterator. How do I implement const_iterator? template <class T> class my_container { private: ... public: my_container() : ... { } ~my_container() { } class iterator : public std::iterator<std::bidirectional_iterator_tag, T> { public: ... ...

Expression: String iterator not dereferencable

I'm having a hard time using std::string::iterators in C++. This code compiles fine (still not getting correct output, but that's my fault: TODO, fix algorithm) in Dev-C++, and I don't get runtime errors. The error is with Visual Studio Express 2008 C++, where I'm getting an error pointing to < xstring>: "Expression: string iterator not ...

Different types of iterators

Are there other types of iterators? Any links that show different types of iterators? The only one I know is .NET's IEnumerable. Particularly for C#, but all others are welcomed too. ...

How to iterate over a STL map full of strings in C++

I have the following issue related to iterating over an associative array of strings defined using std::map. -- snip -- class something { //... private: std::map<std::string, std::string> table; //... } In the constructor I populate table with pairs of string keys associated to string data. Somewhere else I have a method toS...

Is referencing and calling methods via strings in PHP a bad idea?

I've always worry about calling methods by referencing them via strings. Basically in my current scenario, I use static data mapper methods to create and return an array of data model objects (eg. SomeDataMapper::getAll(1234)). Models follow the Active Record design pattern. In some cases, there could be hundreds of records returned, an...

Incrementing iterators: ++it more efficient than it++?

Possible Duplicate: Is there a performance difference between i++ and ++i in C++? I am writing a program where an iterator is used to loop through a std::vector. Somebody told me that doing ++it in the for statement leads to more efficient code. In other words, they are saying that: for ( vector<string>::iterator it=my_vector.b...

Why is there no first(iterable) built-in function in Python?

I'm wondering if there's a reason that there's no first(iterable) in the Python built-in functions, somewhat similar to any(iterable) and all(iterable) (it may be tucked in a stdlib module somewhere, but I don't see it in itertools). first would perform a short-circuit generator evaluation so that unnecessary (and a potentially infinite ...

What is the purpose/advantage of using yield return iterators in C#?

All of the examples I've seen of using yield return x; inside a C# method could be done in the same way by just returning the whole list. In those cases, is there any benefit or advantage in using the yield return syntax vs. returning the list? Also, in what types of scenarios would yield return be used that you couldn't just return the...

Get all factors of a number (iterators showdown :)

You are given all the prime factors of a number, along with their multiplicities (highest powers). The requirment is to produce all the factors of that number. Let me give an example: Prime factors: 2 (power: 3) 3 (power: 1) (meaning the number is 2^3 * 3^1 = 24) The expected result is: 1, 2, 3, 4, 6, 8, 12, 24 I'm thinking of d...

C++: Replacing part of string using iterators is not working.

Hello, I am writing a simple program, which is trying to find next palindrome number after given number. As for now, I am stuck at this point: string::iterator iter; // iterators for the string string::iterator riter; //testcases is a vector<string> with strings representing numbers. for (unsigned int i = 0; i < testcases.size() ; ...

Java: compare object values

I am trying to compare the value of 2 instances of x inside an iterator. x is a reference type containing its own data members. I am trying to compare one instance of x against another to determine if the values inside each are the same. if (x.equals(x)) keeps evaluating to true when actually the value of each instance of x is differe...