I recently wrote my first program from the ground up, but being not a professional of the field, I fear I might not have used the most appropriate solution.
In my program I have to use lists (and lists of lists) of objects in which I continuously add and remove elements, not necessarily at the beginning or end of the lists.
Using lists of pointers is not an option, giving the requirements.
When I started I knew only the std::vector
class and thus I used it, despite knowing that it requires contiguous memory and thus this choice would have caused repeated re-allocations.
While trying to solve another problem I discovered that there exist other classes that might be better suited for this task, such as std::list
and std::deque
.
I mostly access the objects by the use of indexing
myvector[index].function();
and the standard functions that I use the most are
myvector.size();
myvector.begin();
myvector.pop_back();
myvector.push_back();
myvector.insert(myvector.begin()+offset, number, new_element);
and I haven't overloaded any function/operator.
Could you suggest the best container/doubly-linked list for my scope?
Is it possible to seamlessly substitute std::vector
with any other standard container?
Are there special issues I have to pay attention to?