CARVIEW |
Select Language
HTTP/1.1 301 Moved Permanently
Server: nginx
Date: Sat, 19 Jul 2025 18:22:55 GMT
Content-Type: text/html; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
Location: /reference/iterator/reverse_iterator/
HTTP/1.1 200 OK
Server: nginx
Date: Sat, 19 Jul 2025 18:22:55 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
ETag: W/"8cd2-rbRZZljVyaZSau74OXAwI1HbfpA"
Content-Encoding: gzip
This class reverses the direction in which a bidirectional or random-access iterator iterates through a range.
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.
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. This is so, in order to arrange for the past-the-end element of a range: An iterator pointing to a past-the-end element in a range, when reversed, is pointing to the last element (not past it) of the range (this would be the first element of the reversed range). And if an iterator to the first element in a range is reversed, the reversed iterator points to the element before the first element (this would be the past-the-end element of the reversed range).
Reference
C library:
- <cassert> (assert.h)
- <cctype> (ctype.h)
- <cerrno> (errno.h)
-
<cfenv> (fenv.h)C++11
- <cfloat> (float.h)
-
<cinttypes> (inttypes.h)C++11
- <ciso646> (iso646.h)
- <climits> (limits.h)
- <clocale> (locale.h)
- <cmath> (math.h)
- <csetjmp> (setjmp.h)
- <csignal> (signal.h)
- <cstdarg> (stdarg.h)
-
<cstdbool> (stdbool.h)C++11
- <cstddef> (stddef.h)
-
<cstdint> (stdint.h)C++11
- <cstdio> (stdio.h)
- <cstdlib> (stdlib.h)
- <cstring> (string.h)
-
<ctgmath> (tgmath.h)C++11
- <ctime> (time.h)
-
<cuchar> (uchar.h)C++11
- <cwchar> (wchar.h)
- <cwctype> (wctype.h)
Containers:
-
<array>C++11
- <deque>
-
<forward_list>C++11
- <list>
- <map>
- <queue>
- <set>
- <stack>
-
<unordered_map>C++11
-
<unordered_set>C++11
- <vector>
-
Input/Output:
Multi-threading:
-
<atomic>C++11
-
<condition_variable>C++11
-
<future>C++11
-
<mutex>C++11
-
<thread>C++11
-
Other:
- <algorithm>
- <bitset>
-
<chrono>C++11
-
<codecvt>C++11
- <complex>
- <exception>
- <functional>
-
<initializer_list>C++11
- <iterator>
- <limits>
- <locale>
- <memory>
- <new>
- <numeric>
-
<random>C++11
-
<ratio>C++11
-
<regex>C++11
- <stdexcept>
- <string>
-
<system_error>C++11
-
<tuple>C++11
-
<type_traits>C++11
-
<typeindex>C++11
- <typeinfo>
- <utility>
- <valarray>
<iterator>
- iterator
- iterator_traits
functions
- advance
- back_inserter
-
beginC++11
- distance
-
endC++11
- front_inserter
- inserter
-
make_move_iteratorC++11
-
nextC++11
-
prevC++11
iterator categories
predefined iterators
reverse_iterator
- reverse_iterator::reverse_iterator
member functions
- reverse_iterator::base
- reverse_iterator::operator-
- reverse_iterator::operator--
- reverse_iterator::operator-=
- reverse_iterator::operator->
- reverse_iterator::operator[]
- reverse_iterator::operator*
- reverse_iterator::operator+
- reverse_iterator::operator++
- reverse_iterator::operator+=
-
reverse_iterator::operator=C++11
non-member overloads
- Reference
- <iterator>
- reverse_iterator
class template
<iterator>
std::reverse_iterator
template <class Iterator> class reverse_iterator;
Reverse iterator
- iterator
- reverse_iterator
This class reverses the direction in which a bidirectional or random-access iterator iterates through a range.
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.
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. This is so, in order to arrange for the past-the-end element of a range: An iterator pointing to a past-the-end element in a range, when reversed, is pointing to the last element (not past it) of the range (this would be the first element of the reversed range). And if an iterator to the first element in a range is reversed, the reversed iterator points to the element before the first element (this would be the past-the-end element of the reversed range).
Template parameters
- Iterator
- A bidirectional iterator type.
Or a random-access iterator, if an operator that requires such a category of iterators is used.
Member types
member | definition in reverse_iterator | description |
---|---|---|
iterator_type | Iterator | Iterator's type |
iterator_category | iterator_traits<Iterator>::iterator_category | Preserves Iterator's category |
value_type | iterator_traits<Iterator>::value_type | Preserves Iterator's value type |
difference_type | iterator_traits<Iterator>::difference_type | Preserves Iterator's difference type |
pointer | iterator_traits<Iterator>::pointer | Preserves Iterator's pointer type |
reference | iterator_traits<Iterator>::reference | Preserves Iterator's reference type |
Member functions
- (constructor)
- Constructs reverse_iterator object (public member function)
- base
- Return base iterator (public member function)
- operator*
- Dereference iterator (public member function)
- operator+
- Addition operator (public member function)
- operator++
- Increment iterator position (public member function)
- operator+=
- Advance iterator (public member function)
- operator-
- Subtraction operator (public member function)
- operator--
- Decrease iterator position (public member function)
- operator-=
- Retrocede iterator (public member function)
- operator->
- Dereference iterator (public member function)
- operator[]
- Dereference iterator with offset (public member function)
Non-member function overloads
- relational operators
- Relational operators for reverse_iterator (function template)
- operator+
- Addition operator (function template)
- operator-
- Subtraction operator (function template)
Home page | Privacy policy
© cplusplus.com, 2000-2025 - All rights reserved - v3.3.4s
Spotted an error? contact us
© cplusplus.com, 2000-2025 - All rights reserved - v3.3.4s
Spotted an error? contact us