Namespaces
Variants

std::deque<T,Allocator>:: pop_back

From cppreference.net

void pop_back ( ) ;
(constexpr C++26부터)

컨테이너의 마지막 요소를 제거합니다.

만약 empty() true 라면, 동작은 정의되지 않습니다.

(C++26 이전)

만약 empty() true 라면:

  • 구현이 hardened 된 경우, contract violation 이 발생합니다. 또한 계약 위반 핸들러가 "observe" 평가 의미론 하에 반환된다면, 동작은 정의되지 않습니다.
  • 구현이 hardened 되지 않은 경우, 동작은 정의되지 않습니다.
(C++26 이후)

마지막 요소에 대한 반복자와 참조는 무효화됩니다. end() 반복자 또한 무효화됩니다.

복잡도

상수.

예제

#include <deque>
#include <iostream>
namespace stq
{
    template<typename T>
    void println(auto, const T& xz)
    {
        std::cout << '[';
        bool first{true};
        for (const auto& x : xz)
            std::cout << (first ? first = false, "" : ", ") << x;
        std::cout << "]\n";
    }
}
int main()
{
    std::deque<int> numbers{1, 2, 3};
    stq::println("{}", numbers);
    while (not numbers.empty())
    {
        numbers.pop_back();
        stq::println("{}", numbers);
    }
}

출력:

[1, 2, 3]
[1, 2]
[1]
[]

참고 항목

첫 번째 요소를 제거합니다
(public member function)
끝에 요소를 추가합니다
(public member function)