471,066 Members | 923 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,066 software developers and data experts.

Iterator assignment from a pointer

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
1 1826
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.

Similar topics

38 posts views Thread by Grant Edwards | last post: by
11 posts views Thread by Vivi Orunitia | last post: by
4 posts views Thread by steflhermitte | last post: by
18 posts views Thread by silversurfer | last post: by
reply views Thread by mailforpr | last post: by
16 posts views Thread by Juha Nieminen | last post: by
15 posts views Thread by vivekian | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.