Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/container/list/back"

From cppreference.com
< cpp‎ | container‎ | list
m (Shorten template names. Use {{lc}} where appropriate.)
m (langlinks)
 
Line 1: Line 1:
 
{{include page|cpp/container/back|list}}
 
{{include page|cpp/container/back|list}}
  
[[de:cpp/container/list/back]]
+
{{langlinks|de|es|fr|it|ja|pt|ru|zh}}
[[es:cpp/container/list/back]]
+
[[fr:cpp/container/list/back]]
+
[[it:cpp/container/list/back]]
+
[[ja:cpp/container/list/back]]
+
[[pt:cpp/container/list/back]]
+
[[ru:cpp/container/list/back]]
+
[[zh:cpp/container/list/back]]
+

Latest revision as of 07:37, 13 November 2021

 
 
 
 
reference back();
(1)
const_reference back() const;
(2)

Returns a reference to the last element in the container.

Calling back on an empty container causes undefined behavior.

Contents

[edit] Parameters

(none)

[edit] Return value

Reference to the last element.

[edit] Complexity

Constant.

[edit] Notes

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

[edit] Example

#include <cassert>
#include <list>
 
int main()
{
    std::list<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]