std::deque::pop_back(3)

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

🌸 NAME 🌸

okay so bestie, welcome to the C++ Standard Libary manual β€” yes, that spelling is literally in the header, we are leaving it β€” and today’s main character is std::deque::pop_back(3). πŸ’–

std::deque::pop_back - std::deque::pop_back


✨ Synopsis ✨

void pop_back();

It removes the last element of the container. Like, the actual last one. No cap. πŸŽ€

Calling pop_back on an empty container results in undefined behavior. do NOT do that, bestie β€” undefined behavior is not a vibe, it’s a whole glitch era. πŸ’€

Iterators and references to the erased element are invalidated. The end() iterator is also invalidated. Other references and iterators are not affected. πŸ¦‹


πŸŽ€ Parameters πŸŽ€

(none) β€” not a single parameter. Empty plate, clean hands. 🍽️


πŸ’– Return value πŸ’–

(none) β€” it doesn’t hand you anything back. It just does the thing and leaves. πŸ’…


⭐ Complexity ⭐

Constant. That’s it. One little pop, constant energy. ✨


πŸ¦‹ Exceptions πŸ¦‹

Throws nothing. Zero exceptions. Unbothered, moisturized, in its lane. 🧚


🌈 Example 🌈

// Run this code

#include <deque>
#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::deque<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)

xoxo, your Unix bestie πŸ’– β€” source: http://cppreference.com, version/date: 2024.06.10.

πŸ“¦ where this page comes from