STD::INSERT_ITERATOR(3)

πŸ’– std::insert_iterator< _Container >(3) πŸ’–

okay bestie, you found the std::insert_iterator< _Container >(3) page β€” it lives in the Library Functions Manual, and it's the one that turns your boring little assignment into a whole insertion moment. no cap. πŸ¦‹


🌸 NAME 🌸

std::insert_iterator< _Container > β€” turns assignment into insertion. that's it, that's the whole personality. πŸ’…


✨ 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. yes, whatever container, she's flexible like that.
  • using difference_type β€” that's it, that's the whole line, bestie. πŸ™ˆ
  • typedef output_iterator_tag iterator_category β€” one of the tag types. iconic little label.
  • 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 insert_iterator (_Container &__x, _Iter __i) β€” the constructor, she's constexpr, she's lowkey everything.
  • constexpr insert_iterator & operator* () β€” simply returns *this. no thoughts, just vibes.
  • constexpr insert_iterator & operator++ () β€” simply returns *this. (this iterator does not move.) periodt.
  • constexpr insert_iterator & operator++ (int) β€” simply returns *this. (this iterator does not move.) still not moving, bestie.
  • constexpr insert_iterator & operator= (const typename _Container::value_type &__value) β€” the main character. assignment that inserts. more below ⬇️
  • constexpr insert_iterator & operator= (typename _Container::value_type &&__value) β€” the rvalue-flavored twin. also slay.

🌈 Protected Attributes 🌈

  • _Container * container β€” your container, held close.
  • _Iter iter β€” your position, held closer.

🧚 Detailed Description 🧚

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

Turns assignment into insertion.

these are output iterators, constructed from a container-of-T. assigning a T to the iterator inserts it in the container at the iterator's position, rather than overwriting the value at that position. so rude of overwriting, honestly. πŸ’€

(sequences will actually insert a copy of the value before the iterator's position. important detail, don't skip it.)

Tip: using the inserter function to create these iterators can save typing. 🫢

⭐ Member Typedef Documentation ⭐

template<typename _Container> typedef _Container std::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::insert_iterator< _Container >::insert_iterator (_Container & __x, _Iter __i) [inline], [constexpr]

the only way to create this iterator is with a container and an initial position (a normal iterator into the container). no shortcuts, no secret menu, this is the way. ✨

references std::__addressof().


πŸ’… Member Function Documentation πŸ’…

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

simply returns *this.


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

simply returns *this. (this iterator does not move.). 😭


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

simply returns *this. (this iterator does not move.). yes, again. she said what she said.


template<typename _Container> insert_iterator & std::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.

this kind of iterator maintains its own position in the container. assigning a value to the iterator will insert the value into the container at the place before the iterator.

the position is maintained such that subsequent assignments will insert values immediately after one another. for example,

// vector v contains A and Z

insert_iterator i (v, ++v.begin());
i = 1;
i = 2;
i = 3;

// vector v contains A, 1, 2, 3, and Z

look at that glow-up. A and Z were just vibing and now the whole friend group is there. πŸ“


πŸ‘‘ Author πŸ‘‘

generated automatically by Doxygen for libstdc++ from the source code. it didn't even have to try. πŸ’–


and that's the whole page, bestie β€” footer credits libstdc++ with the std::inser...ontainer >(3) title holding it down at the bottom. now go insert something before your iterator's position. iykyk. πŸŒˆπŸ¦‹βœ¨

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