std::back_i...::operator=(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

NAME πŸ’–

std::back_insert_iterator::operator= β€” std::back_insert_iterator::operator=. This is the std::back_i...::operator=(3) page from the C++ Standard Libary manual, bestie, and it's all about assigning into a back insert iterator. Periodt.


Synopsis ✨

Okay so the overload lineup is giving timeline energy, and every variant returns a back_insert_iterator<Container>& unless it's the constexpr era one. Here's the whole squad:

back_insert_iterator<Container>&
    operator=( typename Container::const_reference value );

(until C++11)

back_insert_iterator<Container>&
    operator=( const typename Container::value_type& value );

(since C++11) (until C++20)

constexpr back_insert_iterator<Container>&
    operator=( const typename Container::value_type& value );

(1) (since C++20)

back_insert_iterator<Container>&
    operator=( typename Container::value_type&& value );

(2) (since C++11) (until C++20)

constexpr back_insert_iterator<Container>&
    operator=( typename Container::value_type&& value );

(since C++20)

Inserts the given value value to the container. Yes, the page has that little duplicated β€œvalue” moment and we're keeping it, no cap.

  1. Results in container->push_back(value).
  2. Results in container->push_back(std::move(value)).

Parameters 🧚

  • value β€” the value to insert.

Return value πŸŽ€

*this β€” that's it, that's the return. Slay.


Example 🌸

// Run this code πŸ‘‡

        #include <deque>
        #include <iostream>
        #include <iterator>

        int main()
        {
            std::deque<int> q;
            std::back_insert_iterator<std::deque<int>> it(q);

            for (int i = 0; i < 10; ++i)
                it = i; // calls q.push_back(i)

            for (auto& elem : q)
                std::cout << elem << ' ';
            std::cout << '\n';
        }

Output πŸ”₯

0 1 2 3 4 5 6 7 8 9

okay that's the whole page, bestie 🫢 β€” source/version: http://cppreference.com, date: 2024.06.10, page: std::back_i...::operator=(3). periodt πŸ’…

πŸ“¦ where this page comes from