Skip to content

Std::iterator

Features

  • ++it, it++가 정의 될 것. 단 ++it는 자기 자신의 타입의 리퍼런스를 반환해야함.
  • "*it = 값" 이 정의되어야함. (중요)
  • 다시 이전 iterator를 접근하는 일은 없음.

Category

Category to which the iterator belongs to. It must be one of the following iterator tags:

Iterator category

Defined operations

ContiguousIterator

RandomAccessIterator

BidirectionalIterator

ForwardIterator

InputIterator

  • read
  • increment (without multiple passes)
  • increment (with multiple passes)
  • decrement
  • random access
  • contiguous storage

Iterators that fall into one of the above categories and also meet the requirements of OutputIterator are called mutable iterators.

OutputIterator

  • write
  • increment (without multiple passes)

Contiguous Iterator

RandomAccess Iterator

Bidirectional Iterator

Forward Iterator

Forward iterators are iterators that can be used to access the sequence of elements in a range in the direction that goes from its beginning towards its end.

Performing operations on a forward iterator that is dereferenceable never makes its iterator value non-dereferenceable. This enables algorithms that use this category of iterators to use multiple copies of an iterator to pass more than once by the same iterator values.

All bidirectional and random-access iterators are also valid forward iterators.

There is not a single type of forward iterator: Each container may define its own specific iterator type able to iterate through it and access its elements. But all forward iterators support -at least- the following operations:

property

valid expressions

Is default-constructible1, copy-constructible, copy-assignable and destructible.

  • X a;
  • X b(a);
  • b = a;

Can be compared for equivalence using the equality/inequality operators
(meaningful when both iterator values iterate over the same underlying sequence).

  • a == b
  • a != b

Can be dereferenced as an rvalue (if in a dereferenceable state).

  • *a
  • a->m

For mutable iterators (non-constant iterators):
Can be dereferenced as an lvalue (if in a dereferenceable state).

  • *a = t

Can be incremented (if in a dereferenceable state).
The result is either also dereferenceable or a past-the-end iterator.
Two iterators that compare equal, keep comparing equal when both are increased.

  • ++a
  • a++
  • *a++

Lvalues are swappable. (C++11)

  • swap(a,b)

Input Iterator

Output Iterator

Favorite site

Class & Function References

References


  1. std::is_default_constructible 

  2. Mayple_Story_-cpp-stl-_iterator.pdf