R
Rob McDonald
I am interested in having a container which has properties of both the
STL's list and vector. (I want my cake and to eat it too).
In my application, I will need to add/remove items from arbitrary
points in the container.
I will also need to be able to perform random access to elements of
the container -- accessed by index, not associatively.
Fortunately, in my application, I don't need to do both of these
things at the same time. I.e. I will do a bunch of adding/removing,
followed by a bunch of random access. Then I may go back to a bunch
of adding/removing, and then a whole bunch of random access.
So, my idea right now is to implement a container which is backed by a
list, but when you need to do random access, the list is 'frozen'. At
that point, a vector (or a boost array) is created to satisfy the
random access needs. Then, when you want to go back to inserting/
removing, the list is 'thawed' and the vector is destroyed.
I am still debating whether to make this freeze/thaw explicit or
automatic. Automatic is nice, but explicit would make sure the user
(me) doesn't screw up. Opinions appreciated.
Does this sort of thing exist already? Perhaps there is a keyword I'm
not searching for. Any pointers are appreciated.
I would rather not have to implement a complete STL container from
scratch, but from what I've read, they really aren't set up for
inheritance. What is the best way to go about implementing this idea?
Thanks in advance for any tips,
Rob
STL's list and vector. (I want my cake and to eat it too).
In my application, I will need to add/remove items from arbitrary
points in the container.
I will also need to be able to perform random access to elements of
the container -- accessed by index, not associatively.
Fortunately, in my application, I don't need to do both of these
things at the same time. I.e. I will do a bunch of adding/removing,
followed by a bunch of random access. Then I may go back to a bunch
of adding/removing, and then a whole bunch of random access.
So, my idea right now is to implement a container which is backed by a
list, but when you need to do random access, the list is 'frozen'. At
that point, a vector (or a boost array) is created to satisfy the
random access needs. Then, when you want to go back to inserting/
removing, the list is 'thawed' and the vector is destroyed.
I am still debating whether to make this freeze/thaw explicit or
automatic. Automatic is nice, but explicit would make sure the user
(me) doesn't screw up. Opinions appreciated.
Does this sort of thing exist already? Perhaps there is a keyword I'm
not searching for. Any pointers are appreciated.
I would rather not have to implement a complete STL container from
scratch, but from what I've read, they really aren't set up for
inheritance. What is the best way to go about implementing this idea?
Thanks in advance for any tips,
Rob