473,586 Members | 2,682 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1919
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>::itera tor 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>::itera tor it;
it = somepointer;

is the same as

set<int>::itera tor it;
it = set<int>::itera tor(somepointer );

Since set<int>::itera tor 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

38
3653
by: Grant Edwards | last post by:
In an interview at http://acmqueue.com/modules.php?name=Content&pa=showpage&pid=273 Alan Kay said something I really liked, and I think it applies equally well to Python as well as the languages mentioned: I characterized one way of looking at languages in this way: a lot of them are either the agglutination of features or they're a...
6
4363
by: greg | last post by:
Hello all, I havent used STL containers much, as I am used to MFC containers/classes always ..The differences that I could see is iterators and algorithms. The algorithms providing some basic functinaloties which are also present in respective MFc container classes, I wanted to know what is the main powers in Iterators ?? I have written...
11
3030
by: Vivi Orunitia | last post by:
Hi all, I tried looking this up in the sgi docs but it didn't provide any concrete answer to what I'm looking for. Basically, is there any difference between using ::iterator for a container vs using ::pointer? I did a quick experiment and replaced all the ::iterator in my code with ::pointer and it seems to work the same. What I'm think...
4
2496
by: steflhermitte | last post by:
Dear cpp-ians, I am working with a structure struct segment { .... vector <meta_segment>::iterator it_Z; .... };
18
2548
by: silversurfer | last post by:
Ok, this should be fairly easy for most of you (at least I hope so), but not for me: Let us say we have got the following elements: std::vector<Entry> models; //Entry is a struct std::vector<Entry>::iterator modelIterator; In a method, I am currently writing, I need to get a pointer to an entry in the vector.. I thought of the following:
0
2667
by: mailforpr | last post by:
Hi. Let me introduce an iterator to you, the so-called "Abstract Iterator" I developed the other day. I actually have no idea if there's another "Abstract Iterator" out there, as I have never looked for one on the net (I did browse the boost library though). It doesn't matter right now, anyway. To put it simply, Abstract Iterator is...
16
6062
by: Juha Nieminen | last post by:
I'm actually not sure about this one: Does the standard guarantee that if there's at least one element in the data container, then "--container.end()" will work and give an iterator to the last element in the container? Or is there a cleaner way of getting an iterator to the last element?
15
4145
by: vivekian | last post by:
Hi, I have this following class class nodeInfo ; class childInfo { public: int relativeMeshId ;
1
6231
by: David Bilsby | last post by:
All Apologies for cross posing this but I am not sure if this is a VC 8 STL bug or simply an invalid use of the iterator. I have a PCI card access class which basically abstracts a third party library from the higher level classes. This low level class is used to allocate locked pages of memory before doing a DMA. The third party library...
0
8202
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8338
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7959
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8216
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6614
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5710
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
1
2345
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1449
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.