std::deque::push_front(3)

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

πŸŽ€ std::deque::push_front πŸ’…

okay so bestie, welcome to the C++ Standard Libary manual page for std::deque::push_front(3). This one is short, sweet, and honestly kind of a slay: it shoves an element onto the front of a deque. Let’s get into it. ✨


πŸ’– NAME πŸ’–

std::deque::push_front - std::deque::push_front

🌸 Synopsis 🌸

void push_front( const T& value ); (1)
void push_front( T&& value );      (2) (since C++11)

Prepends the given element value to the beginning of the container.

🚨 iterator vibe check: all iterators (including the end() iterator) are invalidated. No references are invalidated. So references are fine, iterators are not β€” periodt.

🫢 Parameters 🫢

  • value β€” the value of the element to prepend

✨ Return value ✨

(none) β€” it returns nothing, bestie. It just does the front-prepend thing.

πŸ’œ Complexity πŸ’œ

Constant.

😭 Exceptions 😭

If an exception is thrown for any reason, these functions have no effect (strong exception safety guarantee).

πŸ¦‹ Example πŸ¦‹

// Run this code

#include <deque>
#include <iomanip>
#include <iostream>
#include <string>

int main()
{
    std::deque<std::string> letters;

    letters.push_front("abc");
    std::string s{"def"};
    letters.push_front(std::move(s));

    std::cout << "std::deque letters holds: ";
    for (auto&& e : letters)
        std::cout << std::quoted(e) << ' ';

    std::cout << "\nMoved-from string s holds: " << std::quoted(s) <<
       '\n';
}

🌈 Possible output 🌈

std::deque letters holds: "def" "abc"
Moved-from string s holds: ""

πŸ‘‘ See also πŸ‘‘

  • emplace_front β€” constructs an element in-place at the beginning (C++11) (public member function)
  • push_back β€” adds an element to the end (public member function)
  • pop_front β€” removes the first element (public member function)
  • front_inserter β€” creates a std::front_insert_iterator of type inferred from the front_inserter argument (function template)

πŸ’– cute sign-off: source/version/date for this std::deque::push_front(3) page are http://cppreference.com, 2024.06.10 β€” bye bestie, go prepend something iconic! πŸ’…βœ¨

πŸ“¦ where this page comes from