How to give access to a Class' list ?

If this were 5 years ago, I'd be objecting to this question. But its not and I'm a little rusty, so thanks.

I have a class contaning a list of something......

To give a user of this class the chance to traverse the list (but not modify it)
I know that I could do these things. Which is considered best? Or is the best answer not listed? thanks again:

1. Return the actual list by const reference
2. Return a copy of the list (doesn't matter if its modified)
3. Return a Map of begin/end const_iterators
4. Add first, next, prev, curr methods to containing class (and call them)

#4 seems to duplicate what list<> can already do.
You can return const iterators with begin and end.
You can allow the user to specify a callback which is called for each element.
#1 and #2 are definitely way better than #3 or #4, but the question can't really
be answered generically--it depends on your situation.

(I wouldn't object as much to #3 if it said it returned an iterator pair.)

Topic archived. No new replies allowed.