std::list::pop_back(3)

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

🌸 NAME 🌸

okay bestie, this is the page for std::list::pop_back(3) from the C++ Standard Libary manual β€” yes, β€œLibary,” that’s the manual’s spelling, not mine πŸ’…. The whole NAME line is literally std::list::pop_back β€” std::list::pop_back, iconic redundancy, we move.

✨ Synopsis ✨

void pop_back();

She removes the last element of the container. That’s the whole job, and she does it.

Calling pop_back on an empty container results in undefined behavior. No cap, do not do this. That’s the danger zone πŸ’€.

References and iterators to the erased element are invalidated. The ones pointing at the erased element, periodt.

🧚 Parameters 🧚

(none) β€” not a single parameter, bestie.

πŸŽ€ Return value πŸŽ€

(none) β€” she returns nothing, she’s too busy serving.

🌈 Complexity 🌈

Constant. Chill.

πŸ’œ Exceptions πŸ’œ

Throws nothing. Zero drama, zero throwing.

πŸ¦‹ Example πŸ¦‹

The original says // Run this code, so here’s the code:

// Run this code

#include <list>
#include <iostream>

template<typename T>
void print(T const& xs)
{
    std::cout << "[ ";
    for (auto const& x : xs)
        std::cout << x << ' ';
    std::cout << "]\n";
}

int main()
{
    std::list<int> numbers;

    print(numbers);

    numbers.push_back(5);
    numbers.push_back(3);
    numbers.push_back(4);

    print(numbers);

    numbers.pop_back();

    print(numbers);
}

πŸ“€ Output πŸ“€

[ ]
[ 5 3 4 ]
[ 5 3 ]

πŸ‘‘ See also πŸ‘‘

  • pop_front removes the first element (public member function)
  • push_back adds an element to the end (public member function)

mwah πŸ’‹ this one came from source http://cppreference.com, version/date 2024.06.10, and the footer tag std::list::pop_back(3) β€” that’s the whole footer folded into a cute lil sign-off 🫢✨

πŸ“¦ where this page comes from