I want to design a data structure with the following properties:
- Accessible as a single array of some type say
T. For examples[i]. - Ability to access named ranges in it. For example
s.GoodObjects[i],s.BadObjects[j]. - Iterate over it as a whole (STL algorithms etc.).
- Converting the name-index to index in the whole array. Here the interface is a good question too.
Also the desired behaviour would be the ability to
- I really want ranges names to be checked at compile time, not some string-named ranges, but C++ identifier-named.
- Add or remove elements to subarrays.
s.BadObjects.push_back(yourMom). - Implement it without using macros, just good C++ and templates, but readability of usages is of course the #1 priority.
- Possibly range arrays could have element type of a pointer to derived class where
Tis a pointer to base class.
So, how would you design such a structure?
Edit
Looks like I haven't stated it too explicitly, but the 4th requirement (the first list) is actually very important one. Maybe a more general question would be as follows: how to properly design an indexed collection of objects of different types (having a common superclass) with easy indexed access to objects of particular subtype? So, having a through index is a neccesity.
One can assume that all the types are known at compile-time, and amount of every particular object in the whole array is constant (from config file).
s[config->numOfBadObjects + config->numOfGoodOnes + config->numOfBearableOnes + j], wherejis the index of somedisgustingobject I want from that array. This looks error-prone and confusing. This is the reason for the question.