473,387 Members | 1,899 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Iterators

Is there a way to store the addresses of containers in a container and
have an iterator point to each of the containers in this container?

Example:
vector<stringcontainer_a, container_b, container_ix;

container_a and container_b would be stored in container_ix and an
iterator pointing to a position in container_ix to determine whether you
are looking at container_a or container_b.
May 11 '07 #1
8 1467
* wombat:
Is there a way to store the addresses of containers in a container and
have an iterator point to each of the containers in this container?

Example:
vector<stringcontainer_a, container_b, container_ix;

container_a and container_b would be stored in container_ix
typedef StringVector vector<string>;
vector<StringVectorix(2);
StringVector& a = ix[0];
StringVector& b = ix[1];

and an
iterator pointing to a position in container_ix to determine whether you
are looking at container_a or container_b.
Huh.

What is the problem you're trying to solve?

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
May 11 '07 #2
In article <5a*************@mid.individual.net>,
"Alf P. Steinbach" <al***@start.nowrote:
* wombat:
Is there a way to store the addresses of containers in a container and
have an iterator point to each of the containers in this container?

Example:
vector<stringcontainer_a, container_b, container_ix;

container_a and container_b would be stored in container_ix

typedef StringVector vector<string>;
vector<StringVectorix(2);
StringVector& a = ix[0];
StringVector& b = ix[1];

and an
iterator pointing to a position in container_ix to determine whether you
are looking at container_a or container_b.

Huh.

What is the problem you're trying to solve?
Ok, container_ix contains container_a and container_b:

container_ix.push_back(&container_a);
container_ix.push_back(&container_b);

itr=container_ix.begin();
while(itr!=container_ix.end())
{
// With the first pass, itr points to container_a.
// With the second pass, itr points to container_b.
itr++;
}

Of course this code doesn't work, but it gives (hopefully) an idea of
what I'm looking to try to do.
May 11 '07 #3
* wombat:
In article <5a*************@mid.individual.net>,
"Alf P. Steinbach" <al***@start.nowrote:
>* wombat:
>>Is there a way to store the addresses of containers in a container and
have an iterator point to each of the containers in this container?

Example:
vector<stringcontainer_a, container_b, container_ix;

container_a and container_b would be stored in container_ix
typedef StringVector vector<string>;
vector<StringVectorix(2);
StringVector& a = ix[0];
StringVector& b = ix[1];

>>and an
iterator pointing to a position in container_ix to determine whether you
are looking at container_a or container_b.
Huh.

What is the problem you're trying to solve?

Ok, container_ix contains container_a and container_b:

container_ix.push_back(&container_a);
container_ix.push_back(&container_b);

itr=container_ix.begin();
while(itr!=container_ix.end())
{
// With the first pass, itr points to container_a.
// With the second pass, itr points to container_b.
itr++;
}

Of course this code doesn't work, but it gives (hopefully) an idea of
what I'm looking to try to do.
Huh, the code should work just fine. Provided, of course, you declare
container_ix correctly. Assuming

vector<stringcontainer_a, container_b;

that would be

vector< vector<string>* container_ix;

By the way, please look up the FAQ's posting guidelines, about how to
post a question about Code That Does Not Work.

Hth.,

- Alf

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
May 11 '07 #4
In article <5a*************@mid.individual.net>,
"Alf P. Steinbach" <al***@start.nowrote:
* wombat:
In article <5a*************@mid.individual.net>,
"Alf P. Steinbach" <al***@start.nowrote:
* wombat:
Is there a way to store the addresses of containers in a container and
have an iterator point to each of the containers in this container?

Example:
vector<stringcontainer_a, container_b, container_ix;

container_a and container_b would be stored in container_ix
typedef StringVector vector<string>;
vector<StringVectorix(2);
StringVector& a = ix[0];
StringVector& b = ix[1];
and an
iterator pointing to a position in container_ix to determine whether you
are looking at container_a or container_b.
Huh.

What is the problem you're trying to solve?
Ok, container_ix contains container_a and container_b:

container_ix.push_back(&container_a);
container_ix.push_back(&container_b);

itr=container_ix.begin();
while(itr!=container_ix.end())
{
// With the first pass, itr points to container_a.
// With the second pass, itr points to container_b.
itr++;
}

Of course this code doesn't work, but it gives (hopefully) an idea of
what I'm looking to try to do.

Huh, the code should work just fine. Provided, of course, you declare
container_ix correctly. Assuming

vector<stringcontainer_a, container_b;

that would be

vector< vector<string>* container_ix;

By the way, please look up the FAQ's posting guidelines, about how to
post a question about Code That Does Not Work.

Hth.,

- Alf
Ok, I glanced over the FAQ about posting.. didn't see anything. There
were several links that I visited and still didn't find it. I even did a
search. Came up with two results but off hand still didn't find
anything. I didn't post how I declared the container, didn't think of
that so if that was the problem sorry for any problems I'm causing.

I got the code to work, declared the iterator as follows:

vector<vector<string>*>::iterator itr;

It does hold the correct address of the container it's pointing to (like
a pointer should) but actually using it is still a problem. Using *itr
would work for a regular iterator.

I've googled for anything I could think of that would relate to what I'm
trying to do but it's like trying to find a needle in a hay stack, and I
haven't even found the needle yet - or if I'm looking up info correctly.
May 11 '07 #5
wombat wrote:
In article <5a*************@mid.individual.net>,
"Alf P. Steinbach" <al***@start.nowrote:
>[..]
By the way, please look up the FAQ's posting guidelines, about how to
post a question about Code That Does Not Work.

Hth.,

- Alf

Ok, I glanced over the FAQ about posting.. didn't see anything.
Didn't see section 5? Then please do go back and this time _read_ it,
don't just "glance over".
[..]
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
May 11 '07 #6
On Fri, 11 May 2007 13:57:25 +0000, wombat wrote:
In article <5a*************@mid.individual.net>,
"Alf P. Steinbach" <al***@start.nowrote:
>* wombat:
In article <5a*************@mid.individual.net>,
"Alf P. Steinbach" <al***@start.nowrote:

* wombat:
Is there a way to store the addresses of containers in a container
and have an iterator point to each of the containers in this
container?

Example:
vector<stringcontainer_a, container_b, container_ix;

container_a and container_b would be stored in container_ix
typedef StringVector vector<string>;
vector<StringVectorix(2);
StringVector& a = ix[0];
StringVector& b = ix[1];
and an
iterator pointing to a position in container_ix to determine
whether you are looking at container_a or container_b.
Huh.

What is the problem you're trying to solve?

Ok, container_ix contains container_a and container_b:

container_ix.push_back(&container_a);
container_ix.push_back(&container_b);

itr=container_ix.begin();
while(itr!=container_ix.end())
{
// With the first pass, itr points to container_a. // With the second
pass, itr points to container_b. itr++;
}

Of course this code doesn't work, but it gives (hopefully) an idea of
what I'm looking to try to do.

Huh, the code should work just fine. Provided, of course, you declare
container_ix correctly. Assuming

vector<stringcontainer_a, container_b;

that would be

vector< vector<string>* container_ix;

By the way, please look up the FAQ's posting guidelines, about how to
post a question about Code That Does Not Work.

Ok, I glanced over the FAQ about posting.. didn't see anything.
Post compileable, complete, minimal code + error messages:

http://www.parashift.com/c++-faq-lit...t.html#faq-5.8

--
Lionel B
May 11 '07 #7
On 2007-05-11 15:57, wombat wrote:
In article <5a*************@mid.individual.net>,
"Alf P. Steinbach" <al***@start.nowrote:
>* wombat:
In article <5a*************@mid.individual.net>,
"Alf P. Steinbach" <al***@start.nowrote:

* wombat:
Is there a way to store the addresses of containers in a container and
have an iterator point to each of the containers in this container?

Example:
vector<stringcontainer_a, container_b, container_ix;

container_a and container_b would be stored in container_ix
typedef StringVector vector<string>;
vector<StringVectorix(2);
StringVector& a = ix[0];
StringVector& b = ix[1];
and an
iterator pointing to a position in container_ix to determine whether you
are looking at container_a or container_b.
Huh.

What is the problem you're trying to solve?

Ok, container_ix contains container_a and container_b:

container_ix.push_back(&container_a);
container_ix.push_back(&container_b);

itr=container_ix.begin();
while(itr!=container_ix.end())
{
// With the first pass, itr points to container_a.
// With the second pass, itr points to container_b.
itr++;
}

Of course this code doesn't work, but it gives (hopefully) an idea of
what I'm looking to try to do.

Huh, the code should work just fine. Provided, of course, you declare
container_ix correctly. Assuming

vector<stringcontainer_a, container_b;

that would be

vector< vector<string>* container_ix;

By the way, please look up the FAQ's posting guidelines, about how to
post a question about Code That Does Not Work.

Hth.,

- Alf

Ok, I glanced over the FAQ about posting.. didn't see anything. There
were several links that I visited and still didn't find it. I even did a
search. Came up with two results but off hand still didn't find
anything. I didn't post how I declared the container, didn't think of
that so if that was the problem sorry for any problems I'm causing.

I got the code to work, declared the iterator as follows:

vector<vector<string>*>::iterator itr;

It does hold the correct address of the container it's pointing to (like
a pointer should) but actually using it is still a problem. Using *itr
would work for a regular iterator.
Just a guess (since I can't really understand your problem either) but
is your problem the fact that when you dereference iter such as this:

*iter

You can't use what is returned? In that case the solution is simple,
what *iter returns is a std::vector<string>* (a pointer to a vector of
strings, so you have to dereference that pointer too: *(*iter), or when
calling one of the vector's methods: (*iter)->begin().

--
Erik Wikström
May 11 '07 #8
In article <f2**********@south.jnrs.ja.net>, Lionel B <me@privacy.net>
wrote:
On Fri, 11 May 2007 13:57:25 +0000, wombat wrote:
In article <5a*************@mid.individual.net>,
"Alf P. Steinbach" <al***@start.nowrote:
* wombat:
In article <5a*************@mid.individual.net>,
"Alf P. Steinbach" <al***@start.nowrote:

* wombat:
Is there a way to store the addresses of containers in a container
and have an iterator point to each of the containers in this
container?

Example:
vector<stringcontainer_a, container_b, container_ix;

container_a and container_b would be stored in container_ix
typedef StringVector vector<string>;
vector<StringVectorix(2);
StringVector& a = ix[0];
StringVector& b = ix[1];
and an
iterator pointing to a position in container_ix to determine
whether you are looking at container_a or container_b.
Huh.

What is the problem you're trying to solve?

Ok, container_ix contains container_a and container_b:

container_ix.push_back(&container_a);
container_ix.push_back(&container_b);

itr=container_ix.begin();
while(itr!=container_ix.end())
{
// With the first pass, itr points to container_a. // With the second
pass, itr points to container_b. itr++;
}

Of course this code doesn't work, but it gives (hopefully) an idea of
what I'm looking to try to do.

Huh, the code should work just fine. Provided, of course, you declare
container_ix correctly. Assuming

vector<stringcontainer_a, container_b;

that would be

vector< vector<string>* container_ix;

By the way, please look up the FAQ's posting guidelines, about how to
post a question about Code That Does Not Work.
Ok, I glanced over the FAQ about posting.. didn't see anything.

Post compileable, complete, minimal code + error messages:

http://www.parashift.com/c++-faq-lit...t.html#faq-5.8
I found the answer to my problem by accident, about an hour ago.
Everything is working as it should now. Thanks.
May 11 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Steven Bethard | last post by:
So, as I understand it, in Python 3000, zip will basically be replaced with izip, meaning that instead of returning a list, it will return an iterator. This is great for situations like: zip(*)...
18
by: deancoo | last post by:
I have gotten into the habit of often using copy along with an insert iterator. There are scenarios where I process quite a lot of data this way. Can someone give me a general feel as to how much...
1
by: Marcin Kaliciñski | last post by:
template<class RanAccIt> void some_algorithm(RanAccIt begin, RanAccIt end) { // this algorithm involves calling std::lexicographical_compare // on range [begin, end), and on reverse of this range...
3
by: codefixer | last post by:
Hello, I am trying to understand if ITERATORS are tied to CONTAINERS. I know the difference between 5 different or 6(Trivial, on SGI). But what I fail to understand is how can I declare all 5...
8
by: babak | last post by:
Hi everyone I have a problem with Iterators and containers in STL that hopefully someone can help me with. This is what I try to do: I have an associative (map) container and I have a...
24
by: Lasse Vågsæther Karlsen | last post by:
I need to merge several sources of values into one stream of values. All of the sources are sorted already and I need to retrieve the values from them all in sorted order. In other words: s1 = ...
14
by: Jiri Kripac | last post by:
Languages such as Simula 67 contain a general concept of coroutines that allow the execution of a method to be suspended without rolling back the stack and then later resumed at the same place as...
2
by: ma740988 | last post by:
typedef std::vector < std::complex < double > > complex_vec_type; // option1 int main() { complex_vec_type cc ( 24000 ); complex_vec_type dd ( &cc, &cc ); } versus
90
by: John Salerno | last post by:
I'm a little confused. Why doesn't s evaluate to True in the first part, but it does in the second? Is the first statement something different? False print 'hi' hi Thanks.
18
by: desktop | last post by:
1) I have this code: std::list<intmylist; mylist.push_back(1); mylist.push_back(2); mylist.push_back(3); mylist.push_back(4);
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...

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.