|
(Note: I'm writing this project for learning only; comments about it being redundant are... uh, redundant. ;)
I'm trying to implement a random access iterator, but I've found very little literature on the subject, so I'm going by trial and error combined...
Answer Snippets (Read the full thread at stackoverflow):
Add one code):
exscape::string::iterator operator+(exscape::string::iterator it, size_t n) { return it += n; } exscape::string::iterator operator....
Your + operator returns a const iterator, but you don't have a const operator* .
|
|
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...
Started by Xavier Nodet on
, 11 posts
by 11 people.
Answer Snippets (Read the full thread at stackoverflow):
An alternative would be to templatize Node may want to look into using boost's iterator facades and adaptors where you can define your own::vector<Arc*> incoming_; public: typedef....
That forwards all its methods to std::vector::iterator.
|
|
I recently learned about the right way to work with reverse iterators in C++ (specifically when you need to erase one). (See this question and this one .)
This is how you're supposed to do it:
typedef std::vector<int> IV; for (IV::reverse_iterator...
Started by Dan on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
Std::find(foo.rbegin(), foo.rend(), L'a').base()....
The reason for reverse iterators is that the standard algorithms do not know(), foo.end(), L'a'); // Returns an iterator pointing // to the first a character.
iterator (Item 26).
|
Ask your Facebook Friends
|
Hi, I'm using std::map to store a lot of elements (pairs of elements) and I have a "little" doubt, what is more efficient to iterate all elements over my std::map, iterator or reverse_iterator?
Thank's.
Salu2.
Started by Miguel Angel on
, 6 posts
by 6 people.
Answer Snippets (Read the full thread at stackoverflow):
Std::reverse_iterator is just a template container, a forward iterator might interact very slightly better with the cache than a reverse iterator to use a reverse_iterator....
Evil." - Donald Knuth There will likely be no difference .
|
|
My workmate claims that for object types preincrement is more efficient than post increment
e.g.
std::vector<std::string> vec; ... insert a whole bunch of strings into vec ... // iterate over and do stuff with vec. Is this more efficient than the...
Started by Matt H on
, 7 posts
by 7 people.
Answer Snippets (Read the full thread at stackoverflow):
What good is that?
Me: That's great! It means nearly all your time prefer the prettiness of iterator-incrementing....
Jacob
Postincrement must return the value the iterator had BEFORE it was incrementing; so in some iterator-increment code.
|
|
I would like to get an istream_iterator-style iterator that returns each line of the file as a string rather than each word. Is this possible?
Started by thehouse on
, 6 posts
by 6 people.
Answer Snippets (Read the full thread at stackoverflow):
An iterator is just://www.drdobbs.com/cpp/18....
It's not that hard.
It is easy to have istream_iterator do what you want:
namespace_inserter(v)); return 0; }
You could write your own iterator.
By someone else in a previous thread.
|
|
Hi,
I have a class called Action , which is essentially a wrapper around a deque of Move objects.
Because I need to traverse the deque of Moves both forward and backwards, I have a forward iterator and a reverse_iterator as member variables of the class...
Started by BeeBand on
, 6 posts
by 6 people.
Answer Snippets (Read the full thread at stackoverflow):
You....
Beware that this isn't an iterator an iterator, then you would do something like
std::deque<Move>::const_iterator Current() const, rbegin and rend ).
A member base() which returns a corresponding forward iterator.
|
|
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 ...
Started by bbxbby on
, 7 posts
by 7 people.
Answer Snippets (Read the full thread at stackoverflow):
The collection doesn'....
For instance, you may want an iterator that skips candy with nuts (though the typical case is to want one.
I would agree.
I think you should keep your collections separate from your iterators.
The iterator.
|
|
Why does the Iterator interface not extend extend Iterable ?
The iterator() method could simply return ' this '.
Is it on purpose or just an oversight of Java's designers?
It would be convenient to be able to use a for-each loop with iterators like this...
Started by lbownik on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
Iterable implys that one may obtain an iterator from an object to traverse over its elements - and there's no need to iterate over a single instance....
Because an iterator generally points to a single instance in a collection.
|
|
Is it possible to iterate through until the end of list in main() function using the const_iterator? I tried using iter->end() but i can't figure it out.
#include <list> #include <string> using std::list; using std::string; class list_return...
Started by Dave17 on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
You need a function....
}
There is no automatic way to know the end of the list given an iterator.
This:
for (std::list<std::string>::const_iterator iter = lr.get_list(); iter != lr.get_list_end(); ++iter) { //...
|