STD::_DEQUE_ITERATOR(3)

✨ NAME ✨

std::_Deque_iterator< _Tp, _Ref, _Ptr > β€” bestie, it's a deque::iterator. That's the whole vibe. πŸ¦‹

This is one of those libstdc++ internals pages, living in the Library Functions Manual (section 3, iykyk), and honestly? It's the engine room of std::deque. Come with me. πŸ’…


🌸 SYNOPSIS 🌸

First thing, the golden rule of getting to know this girl:

#include <deque>

That's it. That's the entry point. She lives in <deque>. πŸ’–

πŸŽ€ Public Types πŸŽ€

  • typedef __ptr_rebind< _Ptr, _Tp > _Elt_pointer β€” a pointer, but rebranded to point at the element type. glow-up πŸ’«
  • typedef __ptr_rebind< _Ptr, _Elt_pointer > _Map_pointer β€” a pointer to pointers, aka the map of nodes. it's giving "pointer to the pointer store".
  • typedef _Deque_iterator _Self β€” she refers to herself. main character energy, literally. πŸ‘‘
  • typedef __iter< const _Tp > const_iterator β€” the read-only version, no touching.
  • typedef ptrdiff_t difference_type β€” the number type used for distances between iterators.
  • typedef __iter< _Tp > iterator β€” the regular, can-edit-everything version.
  • typedef std::random_access_iterator_tag iterator_category β€” bestie she's a random access iterator, the most powerful category. she can jump around, no cap. πŸ”₯
  • typedef _Ptr pointer β€” plain pointer typedef.
  • typedef _Ref reference β€” plain reference typedef.
  • typedef size_t size_type β€” size things.
  • typedef _Tp value_type β€” the element type itself.

πŸ’œ Public Member Functions πŸ’œ

  • _Deque_iterator (_Elt_pointer __x, _Map_pointer __y) noexcept β€” constructor from an element pointer plus a map pointer.
  • _Deque_iterator (const _Deque_iterator &__x) noexcept β€” copy constructor, noexcept, chill as ever.
  • template<typename _Iter, typename = _Require<is_same<_Self, const_iterator>, is_same<_Iter, iterator>>> _Deque_iterator (const _Iter &__x) noexcept β€” converting constructor, only enabled when _Self is const_iterator and _Iter is iterator. so: iterator β†’ const_iterator, but never the other way round. as it should be. πŸ™ˆ
  • iterator _M_const_cast () const noexcept β€” casts away const-ness and hands you a plain iterator. sneaky but it's right there in the name.
  • void _M_set_node (_Map_pointer __new_node) noexcept β€” get ready to traverse __new_node. (More on her below. ⭐)
  • reference operator* () const noexcept β€” dereference, you get the element. the classic.
  • _Self & operator++ () noexcept β€” pre-increment. move forward one. ➑️
  • _Self operator++ (int) noexcept β€” post-increment. returns the old you, then moves on. character development.
  • _Self & operator+= (difference_type __n) noexcept β€” jump forward __n. zoom zoom.
  • _Self & operator-- () noexcept β€” pre-decrement. back it up. ⬅️
  • _Self operator-- (int) noexcept β€” post-decrement, old copy first.
  • _Self & operator-= (difference_type __n) noexcept β€” jump back __n.
  • pointer operator-> () const noexcept β€” member access through the iterator.
  • _Deque_iterator & operator= (const _Deque_iterator &) = default β€” copy assignment, and it's just the compiler default. she said "no custom logic today". πŸ’…
  • reference operator[] (difference_type __n) const noexcept β€” random access subscripting, because she's a random access iterator and she EARNED it.

🌈 Static Public Member Functions 🌈

  • static size_t _S_buffer_size () noexcept β€” the buffer size, as a static. it's a class-level secret.

🫢 Public Attributes 🫢

  • _Elt_pointer _M_cur β€” where you're currently pointing.
  • _Elt_pointer _M_first β€” start of the current buffer.
  • _Elt_pointer _M_last β€” end of the current buffer.
  • _Map_pointer _M_node β€” the map node this iterator is sitting on.

Four little fields, doing a LOT of heavy lifting. 😭

⭐ Friends ⭐

These are the free functions that get to touch her privates (compiler-speak for it, not my words πŸ’€):

  • _Self operator+ (const _Self &__x, difference_type __n) noexcept β€” iterator plus offset.
  • _Self operator+ (difference_type __n, const _Self &__x) noexcept β€” offset plus iterator, the commutative twin.
  • template<typename _RefR, typename _PtrR> difference_type operator- (const _Self &__x, const _Deque_iterator< _Tp, _RefR, _PtrR > &__y) noexcept β€” distance between two iterators, even when their _Ref/_Ptr differ.
  • difference_type operator- (const _Self &__x, const _Self &__y) noexcept β€” distance between two identical-typed iterators.
  • _Self operator- (const _Self &__x, difference_type __n) noexcept β€” iterator minus offset.
  • strong_ordering operator<=> (const _Self &__x, const _Self &__y) noexcept β€” the three-way spaceship comparison. πŸš€ iconic.
  • template<typename _RefR, typename _PtrR> bool operator== (const _Self &__x, const _Deque_iterator< _Tp, _RefR, _PtrR > &__y) noexcept β€” equality across differing _Ref/_Ptr.
  • bool operator== (const _Self &__x, const _Self &__y) noexcept β€” equality, same types.

πŸ’– Detailed Description πŸ’–

template<typename _Tp, typename _Ref, typename _Ptr>
    struct std::_Deque_iterator< _Tp, _Ref, _Ptr >

Okay so, per the docs: it's a deque::iterator.

And the description is genuinely obsessed with itself, and honestly, correctly:

Quite a bit of intelligence here. Much of the functionality of deque is actually passed off to this class. A deque holds two of these internally, marking its valid range. Access to elements is done as offsets of either of those two, relying on operator overloading in this class.

Translation, bestie: a lot of brain lives in this iterator. deque outsources a huge chunk of its whole personality to this one class. The container keeps two of these inside it at all times, and those two mark the valid range. When you want an element, it's all offsets from one of those two, and the operator overloading in here is what makes that work. 🧚

All the functions are op overloads except for _M_set_node.

That's the whole function list accounted for, fr fr. Every single one is an operator overload except _M_set_node. periodt.


πŸ”₯ Member Function Documentation πŸ”₯

_M_set_node

template<typename _Tp, typename _Ref, typename _Ptr> void
    std::_Deque_iterator< _Tp, _Ref, _Ptr >::_M_set_node (_Map_pointer
    __new_node) [inline],  [noexcept]

She's [inline] and [noexcept], and what she does is: prepares to traverse __new_node.

Here's the important bit, don't skip it: she sets everything except _M_cur. So the caller has to set _M_cur themselves, immediately afterwards, and they figure out the right value based on _M_first and _M_last.

So if you ever call this yourself: set _M_cur right after, or you're just vibing in an uninitialised iterator. πŸ’€

🌷 Author 🌷

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


And that's the whole page, bestie β€” every typedef, every overload, every friend, every field, all accounted for. πŸŽ€

Cute little sign-off before you go: this absolute queen of a page comes to you from libstdc++, the C++ standard library implementation, as rendered by Doxygen, and it sits in the Library Functions Manual as std::_Deque_iterator< _Tp, _Ref, _Ptr >(3). Go forth and index responsibly. 🫢✨

πŸ“¦ 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