Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Common Iterator for the same container

Reply
Thread Tools

Common Iterator for the same container

 
 
utab
Guest
Posts: n/a
 
      03-01-2006
Hi, there

Assume that I have three vectors x,y and z that has the same number of
elements. Can I use a common iterator for these three.

I did it with iterx, itery and iterz but the thing I wondered was: in a
for loop you can write array elements by using the same index such as;

for (int i = 0 ; i!=10; ++i )
cout << x[i] << y[i] << z[i] << endl; Bu

So I just wondered if sth is possible with iterators(common ?) in
order to get the container elements

Thx.

 
Reply With Quote
 
 
 
 
Ben Pope
Guest
Posts: n/a
 
      03-01-2006
utab wrote:
> Hi, there
>
> Assume that I have three vectors x,y and z that has the same number of
> elements. Can I use a common iterator for these three.
>
> I did it with iterx, itery and iterz but the thing I wondered was: in a
> for loop you can write array elements by using the same index such as;
>
> for (int i = 0 ; i!=10; ++i )
> cout << x[i] << y[i] << z[i] << endl; Bu
>
> So I just wondered if sth is possible with iterators(common ?) in
> order to get the container elements


Iterators allow you to traverse a sequence. The elements of different
vectors are not a sequence.

If x, y and z are closely related, do:
struct stuff {
X x;
Y y;
Z z;
}

std::vector<stuff> vec;
iter->x;



Ben Pope
--
I'm not just a number. To many, I'm known as a string...
 
Reply With Quote
 
 
 
 
utab
Guest
Posts: n/a
 
      03-01-2006
Thx,

this is a nice idea if you can not do directly, put them into a form
that they can be handled in the way you want.

I will keep this advice.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can *common* struct-members of 2 different struct-types, that are thesame for the first common members, be accessed via pointer cast to either struct-type? John Reye C Programming 28 05-08-2012 12:24 AM
java.lang.NoSuchMethodError: wm.common.session.Common.getCustRptListFromMax Denny Java 1 05-01-2008 07:33 AM
Common Iterator for different containers utab C++ 3 03-02-2006 01:23 AM
Difference between Java iterator and iterator in Gang of Four Hendrik Maryns Java 18 12-22-2005 05:14 AM
std::container::iterator vs std::container::pointer Vivi Orunitia C++ 11 02-04-2004 08:09 AM



Advertisments