I have a class which has an array of pointer objects and I'm converting it to a std::vector implementation. I'm new to "modern" c++.
Currently the class exposes the array sort of like this:
class foo
{
private:
CustomContainer<foo> m_listOfFoos;
public:
foo CreateFoo(); // Makes a foo, adds it to the list.
foo GetFoo( int i ); // Returns a foo
int GetListSize( ); // Returns the number of foos in the list
void RemoveFoo( int i ); // Removes a foo
void SortList(); // Sorts the list of foos in a custom way
};
The company uses a custom container written in 2002 and the foo is actually a pointer to a complicated class, but otherwise this is very close to the real situation. I've already started working out the changeover from this container to an std::vector.
What I'm wondering is what is the best modern C++ practice for providing member functions to interact with the container.
Should I update the member functions we already have? Or is there some modern C++ magic that allows me to give access to the container to another class so they can add, remove, and iterate with the vector in a better way?
Is there maybe a way to make the std::vector public but only allow read access? Or a way to return an iterator class that does this?