Random_access_iterator
구현은 거의 비슷하다.
1. pubilic member
public:
typedef std::random_access_iterator_tag iterator_category;
typedef T value_type;
typedef T* pointer;
typedef T& reference;
typedef std::ptrdiff_t difference_type;
typedef random_access_iterator<T> iterator;
typedef random_access_iterator<const T> const_iterator;
2. protected member
protected:
pointer _ptr;
3. canonical, constructor
random_access_iterator(void) : _ptr(NULL) {}
random_access_iterator(pointer ptr) : _ptr(ptr) {}
random_access_iterator(const random_access_iterator &x)
{
*this = x;
}
operator const_iterator() const
{
return const_iterator(_ptr);
}
random_access_iterator &operator=(const random_access_iterator &x)
{
if (this != &x)
_ptr = x._ptr;
return (*this);
}
~random_access_iterator(void) {}
4. 나머지는 reverse_iterator와 비슷함.
참고)
https://github.com/hyungyoo/42_Cursus/blob/main/Circle_06/ft_containers/inc/random_access_iterator.hpp