std::ranges...erface::back(3)
okay so bestie, we're cracking open std::ranges...erface::back(3) from the C++ Standard Libary manual, and it's giving niche C++20 icon energy π
β¨. Buckle up, because this one is short but the requires clauses are doing the most.
π NAME π
std::ranges::view_interface::back - std::ranges::view_interface::back
yes, it's the same thing twice, she said what she said π«Ά
β¨ Synopsis β¨
Here's the signature, and bestie, the requires clauses are lowkey carrying the whole fit:
constexpr decltype(auto) back()
requires ranges::bidirectional_range<D> &&
(1) (since C++20)
ranges::common_range<D>;
constexpr decltype(auto) back() const
requires ranges::bidirectional_range<const D> &&
(2) (since C++20)
ranges::common_range<const D>;
The default implementation of the back() 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 the operator* of the iterator type.
- Let
derivedbestatic_cast<D&>(*this). Equivalent toreturn *ranges::prev(ranges::end(derived));. The behavior is undefined ifempty()istrue(i.e. the beginning iterator compares equal to the sentinel), even if the iterator obtained in the same way is dereferenceable. That undefined behavior is not a vibe, so do not play with it π - Same as (1), except that
derivedisstatic_cast<const D&>(*this).
π Parameters π
(none) β no parameters at all, she's low-maintenance π
πΈ Return value πΈ
The last element in the view. That's the whole return value, periodt β¨.
π¦ Notes π¦
In C++20, no type derived from std::ranges::view_interface in the standard library provides their own back() member function.
However, following derived types cannot use the default implementations, as they never satisfy neither bidirectional_range nor common_range:
std::ranges::basic_istream_viewstd::ranges::lazy_split_viewstd::ranges::split_viewstd::ranges::take_while_view
The inherited back() member function is available for std::ranges::empty_view, but a call to it always results in undefined behavior. Always. Undefined. Behavior. π
π Example π
This section is incomplete Reason: no example
so no example bestie, it's giving unfinished homework π
π¦ See also π¦
rbeginβ returns a reverse iterator to the beginning of a container or arraycrbeginβ(function template)(C++14)ranges::rbeginβ returns a reverse iterator to a range(C++20)(customization point object)ranges::crbeginβ returns a reverse iterator to a read-only range(C++20)(customization point object)
β Category β
Todo no example
source/version/date check, bestie: http://cppreference.com Β· 2024.06.10 Β· std::ranges...erface::back(3) β mwah ππ
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms