STD::FRONT_INSERT_ITERATOR(3)

πŸ’– std::front_insert_iterator< _Container > β€” from the Library Functions Manual (section 3) πŸ’–

okay bestie, sit down, hydrate, and let me tell you about the iterator that just inserts at the front like it owns the place πŸ‘‘


✨ NAME ✨

std::front_insert_iterator< _Container > β€” turns assignment into insertion. that's it, that's the whole job, and she does it flawlessly πŸ’…


🌸 SYNOPSIS 🌸

#include <iterator>

Inherits std::iterator< output_iterator_tag, void, void, void, void >.


πŸŽ€ Public Types πŸŽ€

  • typedef _Container container_type β€” a nested typedef for the type of whatever container you used.
  • using difference_type β€” yep, she's there.
  • typedef output_iterator_tag iterator_category β€” one of the tag types.
  • typedef void pointer β€” this type represents a pointer-to-value_type.
  • typedef void reference β€” this type represents a reference-to-value_type.
  • typedef void value_type β€” the type "pointed to" by the iterator.

πŸ’œ Public Member Functions πŸ’œ

  • constexpr front_insert_iterator (_Container &__x) β€” the only way to create this iterator is with a container. no container, no iterator, no exceptions.
  • constexpr front_insert_iterator & operator* () β€” simply returns *this.
  • constexpr front_insert_iterator & operator++ () β€” simply returns *this. (this iterator does not move.) 😭 iconic behaviour honestly
  • constexpr front_insert_iterator operator++ (int) β€” simply returns *this. (this iterator does not move.) still not moving. still slaying.
  • constexpr front_insert_iterator & operator= (const typename _Container::value_type &__value)
  • constexpr front_insert_iterator & operator= (typename _Container::value_type &&__value)

🌈 Protected Attributes 🌈

  • _Container * container

πŸ¦‹ Detailed Description πŸ¦‹

template<typename _Container>
    class std::front_insert_iterator< _Container >

Turns assignment into insertion.

These are output iterators, constructed from a container-of-T. Assigning a T to the iterator prepends it to the container using push_front. 🫢

Tip: using the front_inserter function to create these iterators can save typing. your fingers will thank you.

⭐ Member Typedef Documentation ⭐

template<typename _Container>
    typedef _Container std::front_insert_iterator< _Container >::container_type

A nested typedef for the type of whatever container you used.

typedef output_iterator_tag
    std::iterator< output_iterator_tag, void, void, void, void >::iterator_category
    [inherited]

One of the tag types.

typedef void
    std::iterator< output_iterator_tag, void, void, void, void >::pointer
    [inherited]

This type represents a pointer-to-value_type.

typedef void
    std::iterator< output_iterator_tag, void, void, void, void >::reference
    [inherited]

This type represents a reference-to-value_type.

typedef void
    std::iterator< output_iterator_tag, void, void, void, void >::value_type
    [inherited]

The type "pointed to" by the iterator.


πŸ’€ Constructor & Destructor Documentation πŸ’€

template<typename _Container>
    std::front_insert_iterator< _Container >::front_insert_iterator (_Container & __x)
    [inline], [explicit], [constexpr]

The only way to create this iterator is with a container.

References std::__addressof().


πŸ”₯ Member Function Documentation πŸ”₯

template<typename _Container>
    front_insert_iterator &
    std::front_insert_iterator< _Container >::operator* ()
    [inline], [nodiscard], [constexpr]

Simply returns *this.

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

Simply returns *this. (This iterator does not move.)

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

Simply returns *this. (This iterator does not move.)

template<typename _Container>
    front_insert_iterator &
    std::front_insert_iterator< _Container >::operator= (const typename _Container::value_type & __value)
    [inline], [constexpr]

Parameters

  • __value β€” an instance of whatever type container_type::const_reference is; presumably a reference-to-const T for container<T>.

Returns

  • this iterator, for chained operations. chain her up, she's ready 🫢

This kind of iterator doesn't really have a position in the container (you can think of the position as being permanently at the front, if you like). Assigning a value to the iterator will always prepend the value to the front of the container. main character energy: always first, never moves. periodt. πŸ’…βœ¨


πŸ‘‘ Author πŸ‘‘

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


okay that's the whole vibe check, bestie πŸ’– this page is part of the libstdc++ manual, section 3 (Library Functions Manual), and it was generated for that libstdc++ source β€” mwah, go forth and push_front 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