Hi,
Personally, I find the range of functionality provided by java.util.Iterator to be fairly pathetic. At a minimum, I'd like to have methods such as:
peek() returns next element without moving the iterator forward
previous() returns the previous element
Though there are lots of other possibilities such as first() and last().
Does...
I have an old project that was built using visual studio 2003 and I recompiled it with vs2005 recently. However, during runtime, I get the following error:
list iterator not incrementable
I traced the program to this function:
void InputQueue::update()
{
list<PCB>::iterator iter;
list<PCB>::iterator iterTemp;
for(iter = b...
I'm trying to get my head around SPL iterators and I've come up with 2 ways to handle it. I see the first version to be less complicated but the second version has composition feel to it (I think).
What am I not seeing is which one is preferable over the other? Or am I just over complicating this?
Here are my thoughts:
The object impl...
Suppose I have a hash_map and a code like
// i is an iterator
i = hash_map.erase(i)
But GCC's STL doesn't return iterator in erase, but a void. Now is a code like
hash_map.erase(i++)
safe (i.e. does not invalidate the iterator or does any other unexpected or unpleasant things)? Please note this is a hash_map.
...
I have two iterators, a list and an itertools.count object (i.e. an infinite value generator). I would like to merge these two into a resulting iterator that will alternate yield values between the two:
>>> import itertools
>>> c = itertools.count(1)
>>> items = ['foo', 'bar']
>>> merged = imerge(items, c) # the mythical "imerge"
>>> m...
This is rather the inverse of What can you use Python generator functions for?: python generators, generator expressions, and the itertools module are some of my favorite features of python these days. They're especially useful when setting up chains of operations to perform on a big pile of data--I often use them when processing DSV fil...
Hi,
I'm trying to code opposite action to this:
std::ostream outs; // properly initialized of course
std::set<int> my_set; // ditto
outs << my_set.size();
std::copy( my_set.begin(), my_set.end(), std::ostream_iterator<int>( outs ) );
it should be something like this:
std::istream ins;
std::set<int>::size_type size;
ins >> size;
s...
Hello,
I want to implement the iterator pattern in VB.net, which does not have the yield keyword.
Any ideas or links please?
...
Is there a simple way to sort an iterator in PHP (without just pulling it all into an array and sorting that).
The specific example I have is a DirectoryIterator but it would be nice to have a solution general to any iterator.
$dir = new DirectoryIterator('.');
foreach ($dir as $file)
echo $file->getFilename();
I'd like to be abl...
I'm just getting back into C++ after a couple of years of doing a lot of C#, and recently Objective C.
One thing I've done before is to roll my own iterator adapter for std::map that will deref to just the value part, rather than the key-value pair. This is quite a common and natural thing to do. C# provides this facility with its Keys ...
I'd like to compare two consecutive elements in a std::list while iterating through the list. What is the proper way to access element i+1 while my iterator is at element i?
Thanks
Cobe
...
In the following code I loop through a map and test if an element needs to be erased. Is it safe to erase the element and keep iterating or do I need to collect the keys in another container and do a second loop to call the erase()?
map<string, SerialdMsg::SerialFunction_t>::iterator pm_it;
for (pm_it = port_map.begin(); pm_it != port_...
I'm trying to write an iterator for results from a PDO statement but I can't find any way of rewinding to the first row. I would like to avoid the overhead of calling fetchAll and storing all the result data.
// first loop works fine
foreach($statement as $result) {
// do something with result
}
// but subsequent loops don't
foreac...
I have just converted a project from Visual Studio 2003 to 2005 and although most of it 'converted' fine, I have a series of STL errors from the following line:
void SomeFn( std::vector<CSomeObject*>::iterator it,
std::vector<CSomeObject*>::iterator itBegin = NULL,
std::vector<CSomeObject*>::iterator itEnd = NULL );
The Visual Studio ...
Say I have a method that needs to pull 8 values from a map with 100 elements in it. Which do you think would be preferable:
Walk in a for loop from begin to end once, pulling the elements out by switching on the key?
Or using find 8 times to get those values?
...
I just want to verify, is yield return a shortcut for implementing IEnumerable and IEnumerator?
Thanks,
John
...
I am looking for the highest key value (a defined by the comparison operator) of a std::map.
Is this guaranteed to be
map.rbegin()->first
?
(I am a bit shaky on reverse iterators, and how much freedom there is in the implementation of std::map)
If not, please advise. I cannot change the data structure.
...
Is there an Iterator implementation that merges multiple iterators?
class MergedIterator<T> implements Iterator<T>
{
MergedIterator(Iterator<T>... iters)
....
}
And the next method should move on to iters[1] when !iters[0].hasNext() etc
...
What is the difference between a ::const_iterator and an ::iterator and where would you use one over the other?
...
I have a function which searches an STL container then returns the iterator when it finds the position, however I am getting some funny error messages, can tell me what I am doing wrong?
Function:
std::vector< CClass >::iterator CClass::SearchFunction( const std::string& strField )
{
...
return it;
...
}
Error:
error C2664: 'st...