iterator

How do I abstract away from using RogueWave in legacy code?

I have been tasked with removing RogueWave components from a legacy C++ codebase. To do so, I am attempting to build wrappers around the existing components, make sure that the code functions the same, and then choose a different library like boost to stick into the wrappers. One of the problems I am coming against is that much of the ...

Does readlines() return a list or an iterator in Python 3?

I've read in "Dive into Python 3" that "The readlines() method now returns an iterator, so it is just as efficient as xreadlines() was in Python 2". See here: http://diveintopython3.org/porting-code-to-python-3-with-2to3.html . I'm not sure that it's true because they don't mention it here: http://docs.python.org/release/3.0.1/whatsnew/3...

What substitutes xreadlines() in Python 3?

In Python 2, file objects had an xreadlines() method which returned an iterator that would read the file one line at a time. In Python 3, the xreadlines() method no longer exists, and realines() still returns a list (not an iterator). Does Python 3 has something similar to xreadlines()? I know I can do for line in f: instead of for ...

const_reference or iterator for map (when not actually iterating)

I have some code that uses an iterator to loop through all elements of an unordered_map, but within that loop there are several other processes where I store iterators to particular elements in the map, and generally do lots of jumping around but not iterating (excluding the outermost iterator). It seemed to me that it may be more suita...

STL set of map iterators

I have an stl unordered_map and I would like to store references to elements in that map. I would like there to be no duplicate references. I thought I could create an set of iterators which pointed to elements. For one I wasn't sure that it would recognise , but even so I got some long template errors which I think boiled down to the...

Can't insert element into nested stl set of ints

I have a nested set of ints but I cannot insert elements into the nested sets. std::set<std::set<int> > centre_as_set = bitset_to_set(centre->second->bit_partitions); std::set<std::set<int> >::iterator set_itr; for ( set_itr = centre_as_set.begin(); set_itr != centre_as_set.end(); ++set_itr ) { set_itr->insert(4); std::set<int>:...

Why does this segfault?

for(ItemTemplateListIterator iter = item_template_list.begin(); iter != item_template_list.end(); ++iter) { int id = iter->first; string description = iter->second->description; some_file_stream << id << endl; some_file_stream << description << endl; } Where item_template_list is a map of <int, MyClass*>, ItemTemplateL...

Ruby iterator practice

Hi guys, I am currently learning Ruby and I am wondering whether you guys can suggest some medium to difficult iterators to implemet? Thanks ...

How do I split a string and rejoin it without creating an intermediate list in Python?

Say I have something like the following: dest = "\n".join( [line for line in src.split("\n") if line[:1]!="#"] ) (i.e. strip any lines starting with # from the multi-line string src) src is very large, so I'm assuming .split() will create a large intermediate list. I can change the list comprehension to a generator expression, but i...

c++ uint , unsigned int , int

Hi i have a program that deals alot with vectors and indexes of the elements of these vectors , and I was wondering : is there a difference between uint and unsigned int which is better to use one of the above types or just use "int" as I read some people say compiler does handle int values more efficiently , but if i used int i will ...

How to iterate through map, modify map but restore at each iteration?

I have a std::map<int,int> lets call it my_map I iterate through this map using iterators and a for loop. Within each iteration I want to modify many elements in this map but restore it again to its original values for next iteration of the loop. I thought I could create a temporary copy of the iterator my_temp_map , but then I wouldn...

What's the easiest go to use dynamic array in c/c++ in windows xp?

I need to save instances of type HANDLE to an array container and iterate over it, finally remove some of them when necessary, Which container should I use for the purpose of easiness? ...

how to access properties in the test attribute of a struts if tag

I'm iterating over an array of beans called 'classifications'. How do I access the parentID property within the tag? I tried %{parentID} but that does not work. <s:iterator value="classifications" status="theStatus"> <s:if test="%{parentID} == -1"> <p>-1: <s:property value="subjectName" /></p> </s:if> <s:else> ...

What's the 'Ruby way' to iterate over two arrays at once

More of a syntax curiosity than a problem to solve... I have two arrays of equal length, and want to iterate over them both at once - for example, to output both their values at a certain index. @budget = [ 100, 150, 25, 105 ] @actual = [ 120, 100, 50, 100 ] I know that I can use each_index and index into the arrays like so: @budget...

How to correctly implement custom iterators and const_iterators ?

I have a custom container class for which I'd like to write the iterator and const_iterator classes. I never did this before and I failed to find an appropriate how-to. What are the guidelines regarding iterator creation, and what should I be aware of ? I'd also like to avoid code duplication (I feel that const_iterator and iterator sh...

Iterable objects and array type hinting?

I have a lot of functions that either have type hinting for arrays or use is_array() to check the array-ness of a variable. Now I'm starting to use objects that are iterable. They implement Iterator or IteratorAggregate. Will these be accepted as arrays if they pass through type hinting, or undergo is_array()? If I have to modify my ...

Can't write new elements to IteratorAggregate?

Am I correct in thinking that IteratorAggregate only provides array-like read access to an object? If I need to write to the object-as-array, then I need to use Iterator? Demonstration of an IteratorAggregate object causing a fatal error when trying to add a new element follows: <? class foo implements IteratorAggregate { public ...

Get Java's list iterator to return something other than Object

I use Java. I already have a class for a custom object called "Subject". I have another class that only contains a Linked List of Subject objects. (called subjectsList) I wrote one of the methods (called "getSubject()") in the subjectsList class that is meant to return the Subject object at a specific index in the Linked List. To do t...

Is there a way to test a variable for "isForEachable"

Using PHP, is there a function/method/way to check if a variable contains something that would be safe to put into a foreach construct? Something like //the simple case, would probably never use it this bluntly function foo($things) { if(isForEachable($things)) { foreach($things as $thing) { $thing->...

Visual C++: How is checked_array_iterator useful?

On compiling code at Warning Level 4 (/W4), I get C4996 warnings on std::copy() calls whose parameters are C arrays (not STL containers like vectors). The recommended solution to fix this seems to be to use stdext::checked_array_iterator. What is the use of stdext::checked_array_iterator? How does it work? Why does it not give any comp...