A
Azumanga
I am trying to define a series of iterators for a container I am
building, and as forward, bidirectional and random access iterators are
very similar I thought it would be handy to put them into a heirachy,
much like the code below:
struct MyForwardIterator {
typedef forward_iterator_tag iterator_category;
// forward iterator functions
};
struct MyBidirIterator : public MyForwardIterator {
typedef bidirectional_iterator_tag iterator_category;
// extra bidir functions
};
struct MyRandomAccessIterator : public MyBidirIterator {
typedef random_access_iterator_tag iterator_category;
//extra random access functions
};
While this appears to work fine, I feel a little nervous about
overloading typedefs in the different classes. Should I be worried and
is there any unpleasent errors that could arise from this kind of thing?
PS: I know that if I can provide a random access iterator then I don't
have to provide bidirectional and forward iterators
building, and as forward, bidirectional and random access iterators are
very similar I thought it would be handy to put them into a heirachy,
much like the code below:
struct MyForwardIterator {
typedef forward_iterator_tag iterator_category;
// forward iterator functions
};
struct MyBidirIterator : public MyForwardIterator {
typedef bidirectional_iterator_tag iterator_category;
// extra bidir functions
};
struct MyRandomAccessIterator : public MyBidirIterator {
typedef random_access_iterator_tag iterator_category;
//extra random access functions
};
While this appears to work fine, I feel a little nervous about
overloading typedefs in the different classes. Should I be worried and
is there any unpleasent errors that could arise from this kind of thing?
PS: I know that if I can provide a random access iterator then I don't
have to provide bidirectional and forward iterators