std::front_...r::operator=(3)

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

✨ std::front_...r::operator=(3) ✨

okay so this one is from the C++ Standard Libary manual (their spelling, not mine πŸ’…), and it's all about std::front_insert_iterator::operator= β€” the assignment operator that literally pushes stuff onto the front. it's giving β€œoperator= but make it push_front” energy 🌸.

✨ NAME ✨

std::front_insert_iterator::operator= β€” std::front_insert_iterator::operator=

(yes, the NAME section says it twice. iconic. no notes. πŸ’–)

🌸 Synopsis 🌸

front_insert_iterator<Container>&
    operator=( typename Container::const_reference value );      // (until C++11)

front_insert_iterator<Container>&
    operator=( const typename Container::value_type& value );    // (since C++11) (until C++20)

constexpr front_insert_iterator<Container>&
    operator=( const typename Container::value_type& value );    // (1) (since C++20)

front_insert_iterator<Container>&
    operator=( typename Container::value_type&& value );         // (2) (since C++11) (until C++20)

constexpr front_insert_iterator<Container>&
    operator=( typename Container::value_type&& value );         // (since C++20)

lowkey the whole lore: Inserts the given value value to the container. (yes, value twice β€” we're keeping it exactly as the page says 🫢).

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

πŸŽ€ Parameters πŸŽ€

  • value β€” the value to insert.

πŸ‘‘ Return value πŸ‘‘

*this β€” that's the whole return value, bestie. it returns itself. main character energy, periodt ✨.

🧚 Example 🧚

Run this code:

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

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

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

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

🌈 Output 🌈

9 8 7 6 5 4 3 2 1 0

source: http://cppreference.com ✨ version/date: 2024.06.10 ✨ page: std::front_...r::operator=(3) β€” mwah, that's the page, bestie πŸ’–

πŸ“¦ where this page comes from