It appears that the iterator adaptor reverse_iterator
doubly defines most of its nested types. In particular, it inherits publicly from std::iterator
which exposes iterator_category
, value_type
, difference_type
, pointer
and reference
. Except for iterator_category
and value_type
, these are all explicitly typedef
'ed again in the class definition.
24.5.1.1 Class template reverse_iterator [reverse.iterator]
namespace std {
template <class Iterator>
class reverse_iterator : public
iterator<typename iterator_traits<Iterator>::iterator_category,
typename iterator_traits<Iterator>::value_type,
typename iterator_traits<Iterator>::difference_type,
typename iterator_traits<Iterator>::pointer,
typename iterator_traits<Iterator>::reference> {
public:
typedef Iterator iterator_type;
typedef typename iterator_traits<Iterator>::difference_type difference_type;
typedef typename iterator_traits<Iterator>::reference reference;
typedef typename iterator_traits<Iterator>::pointer pointer;
// ... rest of the class
};
Question: why the repetitive definition? Is this just for purposes of exposition, or is there more to it? And why not redefine iterator_category
and value_type
?