std::vector::pop_back(3)

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

πŸŽ€ std::vector::pop_back(3) πŸŽ€

okay so welcome to the C++ Standard Libary manual page, bestie β€” this is the page for std::vector::pop_back.


πŸ’– NAME πŸ’–

std::vector::pop_back β€” std::vector::pop_back

πŸ¦‹ Synopsis πŸ¦‹

void pop_back();  (constexpr since C++20)

Removes the last element of the container. <span>✨</span>

⚠️ Calling pop_back on an empty container results in undefined behavior. no cap, do not do that, bestie 😭

Iterators (including the end() iterator) and references to the last element are invalidated.

🌸 Parameters 🌸

(none) β€” literally none, she takes no arguments πŸ’…

πŸŽ€ Return value πŸŽ€

(none) β€” nothing comes back out, she just does the thing 🫢

⭐ Complexity ⭐

Constant.

πŸ’œ Exceptions πŸ’œ

Throws nothing.

🧚 Example 🧚

// Run this code

#include <vector>
#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::vector<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 πŸ‘€

  • push_back β€” adds an element to the end (public member function)

mwah πŸ’‹ β€” source: http://cppreference.com, version/date: 2024.06.10, page: std::vector::pop_back(3) ✨

πŸ“¦ where this page comes from