Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::deque<T,Allocator>::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)
       
      reference back();
      (1)(constexpr since C++26)
      const_reference back()const;
      (2)(constexpr since C++26)

      Returns a reference to the last element in 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)

      Contents

      [edit]Return value

      Reference to the last element.

      [edit]Complexity

      Constant.

      [edit]Notes

      For a non-empty containerc, the expressionc.back() is equivalent to*std::prev(c.end()).

      [edit]Example

      Run this code
      #include <cassert>#include <deque> int main(){std::deque<char> letters{'a','b','c','d'};assert(letters.back()=='d');}

      [edit]See also

      access the first element
      (public member function)[edit]
      returns a reverse iterator to the beginning
      (public member function)[edit]
      (C++11)
      returns an iterator to the end
      (public member function)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/container/deque/back&oldid=135172"

      [8]ページ先頭

      ©2009-2025 Movatter.jp