[C++ STL] reverse_iterator

오젼·2022년 8월 27일
0

[C++ STL]

목록 보기
8/11

https://cplusplus.com/reference/iterator/reverse_iterator/?kw=reverse_iterator

template <class Iterator> class reverse_iterator;

Description

  • This class reverses the direction in which a bidirectional or random-access iterator iterates through a range.

    👉 bidirectional이나 random-access iterator의 접근 방향을 거꾸로 한 클래스

  • A copy of the original iterator (the base iterator) is kept internally and used to reflect the operations performed on the reverse_iterator: whenever the reverse_iterator is incremented, its base iterator is decreased, and vice versa. A copy of the base iterator with the current state can be obtained at any time by calling member base.

    👉 내부적으로 original iterator의 사본인 base iterator를 가지고 있어야 함. + 이 base iterator는 reverse_iterator의 수행 내역을 나타내는 데 사용. 예를 들어 reverse_iterator가 증가하면 base iterator는 감소하는 식

  • Notice however that when an iterator is reversed, the reversed version does not point to the same element in the range, but to the one preceding it.

    👉 reversed version은 range 안의 동일 elemet가 아니라 그 앞의 원소를 가리켜야 함.
    👉 end, begin을 맞춰주기 위해 : https://welikecse.tistory.com/44

Member types

Member functions

constructor

base

operator*

operator+

operator++

operator+=

operator-

operator--

operator-=

operator->

operator[]

Non-member function overloads

relational operators

operator+

operator-

0개의 댓글