C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

referring contents of another container.

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
toton
Guest





PostPosted: Mon Nov 13, 2006 10:10 am    Post subject: referring contents of another container. Reply with quote



Hi,
I am facing problem some times, and not finding a suitable answer to
solve it.
I have a vector (or some other container, sometimes) of some class,
named CC
like vector<CC> v, NOT vector<CC*> ;

I want another class say Segment to refer a portion of this vector. I
can't store the iterator for vector as a member function to the class,
as
1) The iterators have different invalidation strategy, and may
invalidate the stored iterators when some new elements are added to the
vector.
2) The iterators are not default constructible, where I need to
calculate the range after Segment class is formed.

Someone suggested, storing raw index of the position, as size_t, and
construct iterator from that. But that looks little error prone.

Things are much easy if I use vector<shared_ptr<CC> > rather than
vector<CC> , where I can copy a portion of the vector inside Segment,
as it copies only the pointers (Which looks much like Java collections,
list, subList etc ). However, I want the vector to store CC directly
like vector<CC>,
and Segment to use a reference of the portion (like
vector<shared_ptr<CC> > , as vector<CC&> is not possible , or vector
<CC*> also not possible as the elements in a vector are movable and may
invalidate the pointer , or use iterators).

In actual case, lots of different hierarchical views are associated
with the vector<CC> all of them points to a range in the vector.
Hope, the problem statement is understandable. If needed, I will be
able to supply more detail.
Looking for an elegant solution.
Thanks in advance.
abir
Back to top
Gianni Mariani
Guest





PostPosted: Mon Nov 13, 2006 10:10 am    Post subject: Re: referring contents of another container. Reply with quote



toton wrote:
....
Quote:
Looking for an elegant solution.

Have you considered using a std::list ?

There is also another container posted by Martin Knoblauch on
comp.std.c++ recently that may be better.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.