In C++, std::deque::back() returns the last element of a std::deque. You do not need to calculate size() - 1 yourself.
It returns a reference, so you can read the value or change it. The deque must have at least one element. Include <deque> to use it.
This is a member of std::deque<T>, a double-ended queue. A deque is fast at adding and removing at both ends, and it allows access by index like std::vector. Unlike a vector, its elements are stored in several blocks, not in one contiguous block.
Syntax
Call back with empty brackets. It takes no arguments.
C++
d.back();
d.back() = 99;
Call
What it does
d.back()
Reads the last element.
d.back() = 99
Replaces the last element with a new value.
The first element has a matching function: front(). To remove the last element, use pop_back().
Library declarations
C++
reference back();
const_reference back() const;
Parameters
Parameter
Description
None
back() takes no parameters. Call it with empty brackets.
Return Value
Return Value
Description
Reference
A reference to the last element, which is the same as d[d.size() - 1].