| (1) | (since C++20) |
| (2) | (since C++20) |
| | |
The default implementation ofback() member function returns the last element in the view of the derived type. Whether the element is returned by value or by reference depends on theoperator* of the iterator type.
1) Let
derived be
static_cast<D&>(*this). Equivalent to
return*ranges::prev(ranges::end(derived));. The behavior is undefined if
empty() is
true (i.e. the beginning iterator compares equal to the sentinel), even if the iterator obtained in the same way is dereferenceable.
2) Same as(1), except thatderived isstatic_cast<const D&>(*this).
[edit]Return value
The last element in the view.
In C++20, no type derived fromstd::ranges::view_interface in the standard library provides their ownback() member function.
However, following derived types cannot use the default implementations, as they never satisfy neitherbidirectional_range norcommon_range:
The inheritedback() member function is available forstd::ranges::empty_view, but a call to it always results in undefined behavior.
[edit]Example
| This section is incomplete Reason: no example |
[edit]See also
| returns a reverse iterator to the beginning of a container or array (function template)[edit] |
| returns a reverse iterator to a range (customization point object)[edit] |
| returns a reverse iterator to a read-only range (customization point object)[edit] |