I currently have a class that can satisfy the API requirement with a random access iterator. However, I can imagine a situation where the implementation changes, and only a direct iterator can be provided.
Therefore, I would like to limit the use of callers to random access features. I know that I can write my own implementation (for example, limited_bar_iterator), but I wondered if there is anything simpler (i.e. Requires less coding).
class BAR { ... };
class FOO {
public:
typedef std::vector<BAR>::iterator bar_iterator;
bar_iterator begin_bar() const;
bar_iterator end_bar() const;
class restricted_bar_iterator :
public std::iterator< std::forward_iterator_tag, BAR > { ... };
};
void baz()
{
FOO foo;
bar_iterator it = foo.begin_bar() + 5;
}
Markb source
share