I am reading a book, and I started the Templates chapter. I have already read the chapter about iterators. For practicing, I am trying to implement a doubly-linked class using templates. Below is the header file of my class.
template<typename T>
class list
{
private:
T* first_node;
T* last_node;
struct node_structure
{
T* previous;
T* next;
T content;
};
public:
list();
void push_back( T& item );
void push_front( T& item );
void remove( size_t index );
size_t size() const;
T& get_node( size_t index );
void clear();
~list();
};
I could have set two members:
T* begin();
T* end();
...to act like very basic iterators, but they are not iterators actually. So, I have a question:
How do I implement the custom iterator class to be used with all the arithmetic operations and to have begin()
, cbegin()
, end()
, and cend()
?
(I am aware that creating a list class will not be as efficient as std::list
, but I am doing this just for sake of practicing.)