Should I write iterators for a class that is just a wrapper for a vector?
The only private member of my class called Record is a vector.
I want to be able to do this:
for (auto& elem : record) {
}
where the record is of type Record. To do this, I need to implement iterators for the Record class. But I can do it too:
for (auto& elem : record.elems) {
}
where record.elems is the vector I mentioned. But so I will need to make it publicly available.
Another approach:
for (auto& elem : record.getElems()) {
}
This way I get the iteration and the member remains private. This is probably the best way to go.
My main question is: why should I try to implement iterators for the Record class when it's just a wrapper for a vector? My colleague insists that I implement iterators, and he cannot even explain to me why this is simply stupid.