The answer is "it depends". :)
How much does the user of your class need to know about the internal vector
?
Take as an example the stack
class in the standard library. It uses a standard container internally, but it doesn't even expose iterators. It exposes push and pop methods, and little else.
The user of the class doesn't need to know anything else. The user of the class shouldn't be allowed to access the middle of the stack. If you do that, it is no longer a stack.
Quite often, users of the class don't actually need anything more than iterators. If your Foo
class exposes begin()
and end()
, what else do I need? I'm able to access every element of the internal data structure at will. I can modify each of them, or read each of them.
Do I also need to be able to insert/remove elements? Perhaps, and if so, should I do that directly on the vector, or through your adaptor methods? It depends. What does the object represent? Does it make sense to add objects directly to the vector owned by a Foo
? Or does it make sense to add objects to the Foo
object, and let it delegate to whatever internal implementation it likes?