Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

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

      From cppreference.com
      <cpp‎ |container‎ |deque

      [edit template]
       
       
       
      std::deque
      Member types
      Member functions
      Non-member functions
      (until C++20)(until C++20)(until C++20)(until C++20)(until C++20)
      Deduction guides(C++17)
       
      void pop_back();
      (constexpr since C++26)

      Removes the last element of the container.

      Ifempty() istrue, the behavior is undefined.

      (until C++26)

      Ifempty() istrue:

      • If the implementation ishardened, acontract violation occurs. Moreover, if the contract-violation handler returns under “observe” evaluation semantic, the behavior is undefined.
      • If the implementation is not hardened, the behavior is undefined.
      (since C++26)

      Iterators and references to the last element are invalidated. Theend() iterator is also invalidated.

      [edit]Complexity

      Constant.

      [edit]Example

      Run this code
      #include <deque>#include <iostream> namespace stq{template<typename T>void println(auto,const T& xz){std::cout<<'[';bool first{true};for(constauto& 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);}}

      Output:

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

      [edit]See also

      removes the first element
      (public member function)[edit]
      adds an element to the end
      (public member function)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/container/deque/pop_back&oldid=135185"

      [8]ページ先頭

      ©2009-2025 Movatter.jp