std::forwar...::pop_front(3)

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

πŸ’– NAME πŸ’–

okay so bestie, this is the std::forwar...::pop_front(3) page from the C++ Standard Libary manual (yes, that's the spelling on the page β€” don't come for me πŸ’€). The NAME line is out here being extra: std::forward_list::pop_front β€” std::forward_list::pop_front. She's the function that pops the front element of a std::forward_list. Main character energy only. πŸ’…

✨ Synopsis ✨

void pop_front();  (since C++11)

Translation: she removes the first element of the container. That's the move. But if there are no elements in the container, the behavior is undefined β€” like, full stop, undefined. Do not pass go, do not collect vibes. 🫠

Also important: references and iterators to the erased element are invalidated. So if you had a ref or iterator to that first element, after the pop it's invalidated. No cap. πŸ¦‹

🌸 Parameters 🌸

(none) β€” no arguments, no drama. She takes nothing. πŸŽ€

πŸŽ€ Return value πŸŽ€

(none) β€” returns nothing. Does the thing and leaves. Iconic. πŸ’–

⚑ Complexity ⚑

Constant. Literally constant. No scaling arc. ✨

πŸ¦‹ Exceptions πŸ¦‹

Does not throw. Periodt. πŸ’œ

πŸ“ Example πŸ“

The page drops // Run this code, so run this code, bestie:

// Run this code

#include <forward_list>
#include <iostream>

int main()
{
    std::forward_list<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 πŸ’œ

  • push_front β€” inserts an element to the beginning (public member function). The opposite-direction bestie. 🫢
  • front β€” access the first element (public member function). The peek before the pop, iykyk. 🌈

mwah πŸ’‹ β€” source: http://cppreference.com, version/date: 2024.06.10. That's the whole page, bestie. Slay forever. πŸ‘‘πŸ’–

πŸ“¦ where this page comes from