STD::REVERSE_ITERATOR(3)

πŸ’– std::reverse_iterator< _Iterator > πŸ’–

okay bestie, welcome to the Library Functions Manual page for std::reverse_iterator< _Iterator > β€” she's a libstdc++ girlie and she's here to walk your container backwards, and honestly? iconic behavior. πŸ¦‹


✨ NAME ✨

std::reverse_iterator< _Iterator > β€” the iterator adaptor that walks your data structure in the opposite direction. periodt.


🌸 SYNOPSIS 🌸

#include <iterator>

Inherits from:

std::iterator< iterator_traits< _Iterator >::iterator_category,
               iterator_traits< _Iterator >::value_type,
               iterator_traits< _Iterator >::difference_type,
               iterator_traits< _Iterator >::pointer,
               iterator_traits< _Iterator >::reference >

πŸ‘‘ Public Types

  • using difference_type
  • using iterator_category
  • using iterator_concept
  • typedef _Iterator iterator_type
  • typedef __traits_type::pointer pointer
  • using reference
  • using value_type

πŸŽ€ Public Member Functions

  • constexpr reverse_iterator () noexcept(/*conditional */)
  • constexpr reverse_iterator (const reverse_iterator &__x) noexcept(/*conditional */)
  • template<typename _Iter> constexpr reverse_iterator (const reverse_iterator< _Iter > &__x) noexcept(/*conditional */)
  • constexpr reverse_iterator (iterator_type __x) noexcept(/*conditional */)
  • constexpr iterator_type base () const noexcept(/*conditional */)
  • constexpr reference operator* () const
  • constexpr reverse_iterator operator+ (difference_type __n) const
  • constexpr reverse_iterator & operator++ ()
  • constexpr reverse_iterator operator++ (int)
  • constexpr reverse_iterator & operator+= (difference_type __n)
  • constexpr reverse_iterator operator- (difference_type __n) const
  • constexpr reverse_iterator & operator-- ()
  • constexpr reverse_iterator operator-- (int)
  • constexpr reverse_iterator & operator-= (difference_type __n)
  • constexpr pointer operator-> () const
  • reverse_iterator & operator= (const reverse_iterator &)=default
  • template<typename _Iter> constexpr reverse_iterator & operator= (const reverse_iterator< _Iter > &__x) noexcept(/*conditional */)
  • constexpr reference operator[] (difference_type __n) const

🧚 Protected Types

  • typedef iterator_traits< _Iterator > __traits_type

πŸ’œ Protected Attributes

  • _Iterator current

🌈 Friends

  • constexpr iter_rvalue_reference_t< _Iterator > iter_move (const reverse_iterator &__i) noexcept(is_nothrow_copy_constructible_v< _Iterator > &&noexcept(ranges::iter_move(--std::declval< _Iterator & >())))
  • template<indirectly_swappable< _Iterator > _Iter2> constexpr void iter_swap (const reverse_iterator &__x, const reverse_iterator< _Iter2 > &__y) noexcept(is_nothrow_copy_constructible_v< _Iterator > &&is_nothrow_copy_constructible_v< _Iter2 > &&noexcept(ranges::iter_swap(--std::declval< _Iterator & >(), --std::declval< _Iter2 & >())))

🫢 Detailed Description 🫢

template<typename _Iterator>
class std::reverse_iterator< _Iterator >

okay so here's the tea β˜• β€” Bidirectional and random access iterators have corresponding reverse iterator adaptors that iterate through the data structure in the opposite direction. They have the same signatures as the corresponding iterators. The fundamental relation between a reverse iterator and its corresponding iterator i is established by the identity:

&*(reverse_iterator(i)) == &*(i - 1)

This mapping is dictated by the fact that while there is always a pointer past the end of an array, there might not be a valid pointer before the beginning of an array. [24.4.1]/1,2

Reverse iterators can be tricky and surprising at first. Their semantics make sense, however, and the trickiness is a side effect of the requirement that the iterators must be safe.

ngl bestie the - 1 in that identity is doing SO much heavy lifting. it's giving "off by one but make it ✨intentional✨". πŸ’…

🌟 Constructor & Destructor Documentation 🌟

template<typename _Iterator> std::reverse_iterator< _Iterator >::reverse_iterator () [inline], [constexpr], [noexcept]

The default constructor value-initializes member current. If it is a pointer, that means it is zero-initialized.

Referenced by std::reverse_iterator< iterator >::operator+(), and std::reverse_iterator< iterator >::operator-().

template<typename _Iterator> std::reverse_iterator< _Iterator >::reverse_iterator (iterator_type __x) [inline], [explicit], [constexpr], [noexcept]

This iterator will move in the opposite direction that x does.

template<typename _Iterator> std::reverse_iterator< _Iterator >::reverse_iterator (const reverse_iterator< _Iterator > & __x) [inline], [constexpr], [noexcept]

The copy constructor is normal.

template<typename _Iterator> template<typename _Iter> std::reverse_iterator< _Iterator >::reverse_iterator (const reverse_iterator< _Iter > & __x) [inline], [constexpr], [noexcept]

A reverse_iterator across other types can be copied if the underlying iterator can be converted to the type of current.


πŸ’… Member Function Documentation πŸ’…

template<typename _Iterator> iterator_type std::reverse_iterator< _Iterator >::base () const [inline], [nodiscard], [constexpr], [noexcept]

Returns : current, the iterator used for underlying work.

Referenced by std::operator==().

template<typename _Iterator> reference std::reverse_iterator< _Iterator >::operator* () const [inline], [nodiscard], [constexpr]

Returns : A reference to the value at --current

This requires that --current is dereferenceable.

⚠️ Warning β€” This implementation requires that for an iterator of the underlying iterator type, x, a reference obtained by *x remains valid after x has been modified or destroyed. This is a bug: http://gcc.gnu.org/PR51823
bestie this is a real bug, not a vibe. don't come for me, come for PR51823. 😭

template<typename _Iterator> reverse_iterator std::reverse_iterator< _Iterator >::operator+ (difference_type __n) const [inline], [nodiscard], [constexpr]

Returns : A reverse_iterator that refers to current - __n

The underlying iterator must be a Random Access Iterator.

template<typename _Iterator> reverse_iterator & std::reverse_iterator< _Iterator >::operator++ () [inline], [constexpr]

Returns : *this

Decrements the underlying iterator.

template<typename _Iterator> reverse_iterator std::reverse_iterator< _Iterator >::operator++ (int ) [inline], [constexpr]

Returns : The original value of *this

Decrements the underlying iterator.

template<typename _Iterator> reverse_iterator & std::reverse_iterator< _Iterator >::operator+= (difference_type __n) [inline], [constexpr]

Returns : *this

Moves the underlying iterator backwards __n steps. The underlying iterator must be a Random Access Iterator.

template<typename _Iterator> reverse_iterator std::reverse_iterator< _Iterator >::operator- (difference_type __n) const [inline], [nodiscard], [constexpr]

Returns : A reverse_iterator that refers to current - __n

The underlying iterator must be a Random Access Iterator.

template<typename _Iterator> reverse_iterator & std::reverse_iterator< _Iterator >::operator-- () [inline], [constexpr]

Returns : *this

Increments the underlying iterator.

template<typename _Iterator> reverse_iterator std::reverse_iterator< _Iterator >::operator-- (int ) [inline], [constexpr]

Returns : A reverse_iterator with the previous value of *this

Increments the underlying iterator.

template<typename _Iterator> reverse_iterator & std::reverse_iterator< _Iterator >::operator-= (difference_type __n) [inline], [constexpr]

Returns : *this

Moves the underlying iterator forwards __n steps. The underlying iterator must be a Random Access Iterator.

template<typename _Iterator> pointer std::reverse_iterator< _Iterator >::operator-> () const [inline], [nodiscard], [constexpr]

Returns : A pointer to the value at --current

This requires that --current is dereferenceable.

template<typename _Iterator> reference std::reverse_iterator< _Iterator >::operator[] (difference_type __n) const [inline], [nodiscard], [constexpr]

Returns : The value at current - __n - 1

The underlying iterator must be a Random Access Iterator.

🌈 quick vibe check: notice how ++ on a reverse iterator decrements the underlying one and -- increments it. that's not a typo, that's the whole point. it's giving "everything you know is backwards" and she ATE. πŸ”₯

✍️ Author ✍️

Generated automatically by Doxygen for libstdc++ from the source code.


and that's the whole page, bestie!! πŸ’– she's from libstdc++, she lives in the Library Functions Manual section (that's section 3, the library functions girlies πŸŽ€), and she was generated automatically by Doxygen for libstdc++ from the source code. no cap. now go reverse something. πŸ¦‹βœ¨πŸ‘‘

πŸ“¦ where this page comes from
  • arch rolling: gcc 16.2.1+r23+gd564253eb6c8-1 Β· GPL-3.0-or-later WITH GCC-exception-3.1 AND GFDL-1.3-or-later
  • fedora 44: libstdc++-docs 16.0.1-0.10.fc44 Β· GPL-3.0-or-later AND LGPL-3.0-or-later AND (GPL-3.0-or-later WITH GCC-exception-3.1) AND (GPL-3.0-or-later WITH Texinfo-exception) AND (LGPL-2.1-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GNU-compiler-exception) AND BSL-1.0 AND GFDL-1.3-or-later AND Linux-man-pages-copyleft-2-para AND SunPro AND BSD-1-Clause AND BSD-2-Clause AND BSD-2-Clause-Views AND BSD-3-Clause AND BSD-4-Clause AND BSD-Source-Code AND Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 WITH LLVM-Exception) AND ZPL-2.1 AND ISC AND LicenseRef-Fedora-Public-Domain AND HP-1986 AND curl AND Martin-Birgmeier AND HPND-Markus-Kuhn AND dtoa AND SMLNJ AND AMD-newlib AND OAR AND HPND-merchantability-variant AND HPND-Intel
  • fedora 44: libstdc++-docs 16.2.1-2.fc44
  • fedora 44: libstdc++-docs 16.2.1-3.fc44 Β· GPL-3.0-or-later AND LGPL-3.0-or-later AND (GPL-3.0-or-later WITH GCC-exception-3.1) AND (GPL-3.0-or-later WITH Texinfo-exception) AND (LGPL-2.1-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GNU-compiler-exception) AND BSL-1.0 AND GFDL-1.3-or-later AND Linux-man-pages-copyleft-2-para AND SunPro AND BSD-1-Clause AND BSD-2-Clause AND BSD-2-Clause-Views AND BSD-3-Clause AND BSD-4-Clause AND BSD-Source-Code AND Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 WITH LLVM-Exception) AND ZPL-2.1 AND ISC AND LicenseRef-Fedora-Public-Domain AND HP-1986 AND curl AND Martin-Birgmeier AND HPND-Markus-Kuhn AND dtoa AND SMLNJ AND AMD-newlib AND OAR AND HPND-merchantability-variant AND HPND-Intel
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms