473,405 Members | 2,421 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,405 software developers and data experts.

extending an stl container and iterator to also find groups of elements

HI

First off, thanks for taking the time to read this.

I have an class inheritance hierachy say:
base class "E" and a bunch of derived classes (from "E") "A",
"P", and "S"

I have an STL vector (might change to a list) std::vector<Ewhich is
populated by
A's, P's, and S's

Certain sequences of A's, P's and S's can be grouped to form other
classes (composite):
class M consists of one P and one S
class C consists of one A and any number of M's

What I am looking for is a way to extend/modify the STL container/
iterator to:
Allow me to iterate though the single vector using different types of
iterators:
i.e. vector<E*>::iterator, vector<M*>::iterator, vector<C*>::iterator,
vector<A*>::iterator

Basicly I'm looking to be able to iterate a single vector/list in a
number of different ways so I don't have to maintain multiple vectors/
lists for each of the composite types and specific operations I have
to perform.
Thanks for any advice and input
- A

Aug 18 '07 #1
1 1850
al******@gmail.com wrote:
HI

First off, thanks for taking the time to read this.

I have an class inheritance hierachy say:
base class "E" and a bunch of derived classes (from "E") "A",
"P", and "S"

I have an STL vector (might change to a list) std::vector<Ewhich is
populated by
A's, P's, and S's
I doubt that, all a vector of E can hold is E objects. Did you intend
to write std::vector<E*>?
Certain sequences of A's, P's and S's can be grouped to form other
classes (composite):
class M consists of one P and one S
class C consists of one A and any number of M's
Explain "consists of". Are you using multiple inheritance with virtual
bases or does an M have a P and an S as members?
What I am looking for is a way to extend/modify the STL container/
iterator to:
Allow me to iterate though the single vector using different types of
iterators:
i.e. vector<E*>::iterator, vector<M*>::iterator, vector<C*>::iterator,
vector<A*>::iterator
If you want to do this, there is probably something broken in your design.
Basicly I'm looking to be able to iterate a single vector/list in a
number of different ways so I don't have to maintain multiple vectors/
lists for each of the composite types and specific operations I have
to perform.
What problem are you trying to solve this way that you can't solve
through polymorphism and virtual methods?

--
Ian Collins.
Aug 18 '07 #2

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

Similar topics

9
by: kazio | last post by:
Hello, So, I need to have double linked, circular list (last element point to the first one and first one points to the last one). I thought maybe I could use list container from STL, but...
1
by: Wolfgang Lipp | last post by:
my question is: do we need container elements for repeating elements in data-centric xml documents? or is it for some reason very advisable to introduce containers in xml documents even where not...
41
by: AngleWyrm | last post by:
I have created a new container class, called the hat. It provides random selection of user objects, both with and without replacement, with non-uniform probabilities. Uniform probabilities are a...
4
by: Carl Youngblood | last post by:
I imagine this subject has probably been brought up numerous times. Forgive me for bringing it up again. I was googling through old posts on this newsgroup about it and found a good suggestion on...
19
by: Nafai | last post by:
Hi I want to write a function which erases al the repeated elements in a range. How should be the prototype? template <class Iterator> void eraseRepeated(Iterator begin, Iterator end); ...
16
by: forester | last post by:
lets say its common situation when object have subobjects in container and receives callbacks from contained items. and object want to move objects in containers on signal(callback). iterator is...
0
by: nick | last post by:
Hi, I need to manage a "layered" collection of objects, where each layer grows independently, e.g, o--+--+--+--+--+ 1st layer | o 2nd layer (empty) | o--+--+--+ 3rd...
8
by: toton | last post by:
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<CCv, NOT vector<CC*; ...
7
by: ademirzanetti | last post by:
Hi there !!! I would like to listen your opinions about inherit from a STL class like list. For example, do you think it is a good approach if I inherit from list to create something like...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
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...
0
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...
0
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,...

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.