By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,538 Members | 875 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,538 IT Pros & Developers. It's quick & easy.

Iterator assignment from a pointer

P: n/a
What exactly can you assign to a set iterator, by assignment or
initialisation? (is this covered in Josuttis? I can't find it).

Some (limited) digging around in the Gnu code shows no operator=, but
2 ctors for iterators, and 3 for const_iterators. For const_iterator,
there's a no-parameter ctor, and a ctor which takes another
const_iterator. The 3rd one is more interesting - it takes a pointer
to a node in the R/B tree, and the iterator itself is actually a
pointer to a node.

This makes me think that there may actually be a way to assign a
pointer to an iterator, with the right runes. If there isn't one, can
anyone tell me why this isn't allowed?

Thanks

Dom
Aug 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Dom Gilligan wrote:
What exactly can you assign to a set iterator, by assignment or
initialisation? (is this covered in Josuttis? I can't find it).
You mean like

set<int>::iterator it;

it = ??? // what is allowed here?

From what I see in the Standard, the iterators for containers are
implementation-defined, and the only requirement on the std::set iterators
is that they are of the bidirectional kind. The only assignment defined
for a bidirectional iterator is from another bidirectional iterator.
Some (limited) digging around in the Gnu code shows no operator=, but
2 ctors for iterators, and 3 for const_iterators. For const_iterator,
there's a no-parameter ctor, and a ctor which takes another
const_iterator. The 3rd one is more interesting - it takes a pointer
to a node in the R/B tree, and the iterator itself is actually a
pointer to a node.
The absence of an explicit operator= suggests that only the compiler-
generated copy assignment can be used. Just like I said, only assignment
from another iterator.
This makes me think that there may actually be a way to assign a
pointer to an iterator, with the right runes. If there isn't one, can
anyone tell me why this isn't allowed?


Assignment from a pointer will yield creation of a temporary iterator
from the pointer and the assignment from that iterator:

set<int>::iterator it;
it = somepointer;

is the same as

set<int>::iterator it;
it = set<int>::iterator(somepointer);

Since set<int>::iterator is implementation-defined, there is nothing
in C++ to say about what constructors it should or should not have.

V
Aug 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.