std::deque::pop_front(3)

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

πŸ’… std::deque::pop_front(3) πŸ’…

okay so bestie, welcome to the C++ Standard Libary page β€” yes, the source really spells it Libary, we are keeping the typo, do not come for me 😭 β€” and today's main character is std::deque::pop_front. This is the C++ Standard Library manual, and we are about to pop the front element like it is a bad vibe. πŸ’–

πŸŽ€ NAME πŸŽ€

std::deque::pop_front β€” literally std::deque::pop_front, that is the name, no notes. Periodt. πŸ’…

πŸ¦‹ Synopsis πŸ¦‹

Here is the signature, copy it exactly, no improv:

void pop_front();

Okay so what it does: it removes the first element of the container. That is the whole job. If there are no elements in the container, the behavior is undefined β€” like, not a cute little no-op, actually undefined behavior. So do not call it on an empty deque and expect magic, bestie. 🚨

About iterators and references: iterators and references to the erased element are invalidated. If the element is the last element in the container, the end() iterator is also invalidated. Other references and iterators are not affected. The way that invalidates exactly the erased element and leaves the rest alone? Obsessed. ✨

🫢 Parameters 🫢

(none) β€” not a single parameter, bestie. Zero. Nada. The void is empty. 🫢

πŸ’€ Return value πŸ’€

(none) β€” it returns nothing. No value, no little gift, just the pop. πŸ’€

⭐ Complexity ⭐

Constant. That is the whole note. Constant. Keep it moving. ⭐

😌 Exceptions 😌

Does not throw. It is giving unbothered, no exceptions, no throw. 😌

🌸 Example 🌸

The source literally says // Run this code, so run this, bestie:

#include <deque>
#include <iostream>

int main()
{
    std::deque<char> chars{'A', 'B', 'C', 'D'};

    for (; !chars.empty(); chars.pop_front())
        std::cout << "chars.front(): '" << chars.front() << "'\n";
}

Output:

chars.front(): 'A'
chars.front(): 'B'
chars.front(): 'C'
chars.front(): 'D'

πŸ‘‘ See also πŸ‘‘

  • pop_back β€” removes the last element (public member function)
  • push_front β€” inserts an element to the beginning (public member function)
  • front β€” access the first element (public member function)

mwah πŸ’‹ this page is from http://cppreference.com, dated 2024.06.10, and it is the std::deque::pop_front(3) page β€” periodt, bestie. πŸŽ€βœ¨

πŸ“¦ where this page comes from