I am implementing an iterator for a custom container in c++11
I get the following error:
no type named 'value_type' in 'struct std::iterator_traits<PixBuffer<float>::seq_read_iterator>'
typedef typename iterator_traits<_OI>::value_type _ValueTypeO;
I have read before the answer here: How to implement an STL-style iterator and avoid common pitfalls?
It states that I can:
- specialize
std::iterator_traits<youriterator>
: This is not the preferred method according to the author, for code readability, as this type declaration is not nested in the class - Put the same typedefs in the iterator itself : I did this but I still have the error above
- Inherit from std::iterator : will this fix my problem, and what is the proper way to use this method?
This interator works as a back_inserter. The current class definition is:
template<typename T>
class PixBuffer
{
public:
friend class seq_read_iterator;
/* container class implementation removed from here */
public:
class seq_read_iterator
{
public:
typedef T value_type;
seq_read_iterator(PixBuffer & pb);
seq_read_iterator & operator*(T val);
seq_read_iterator & operator++();
seq_read_iterator operator++(int);
seq_read_iterator & operator=(T val);
/* iterator class implementation removed from here */
};
seq_read_iterator seqReadIterator() { return seq_read_iterator(*this); }
};
Thanks in advance