std::flat_map<Key,T,Compare,KeyContainer,MappedContainer>::rend, std::flat_map<Key,T,Compare,KeyContainer,MappedContainer>::crend - cppreference.com (original) (raw)

reverse_iterator rend() noexcept; (1) (since C++23) (constexpr since C++26)
const_reverse_iterator rend() const noexcept; (2) (since C++23) (constexpr since C++26)
const_reverse_iterator crend() const noexcept; (3) (since C++23) (constexpr since C++26)

Returns a reverse iterator past the last element of the reversed *this. It corresponds to the element preceding the first element of the non-reversed *this.

This returned iterator only acts as a sentinel. It is not guaranteed to be dereferenceable.

range-rbegin-rend.svg

[edit] Return value

Reverse iterator to the element following the last element.

[edit] Complexity

Constant.

[edit] Example

#include #include #include #include #include   using namespace std::chrono;   int main() { const std::flat_map<year_month_day, int> messages { {February/17/2023, 10}, {February/17/2023, 20}, {February/16/2022, 30}, {October/22/2022, 40}, {June/14/2022, 50}, {November/23/2021, 60}, {December/10/2022, 55}, {December/12/2021, 45}, {April/1/2020, 42}, {April/1/2020, 24} };   std::cout << "Messages received (date order is reversed):\n"; for (auto it = messages.crbegin(); it != messages.crend(); ++it) std::cout << it->first << " : " << it->second << '\n'; }

Possible output:

Messages received (date order is reversed): 2023-02-17 : 10 2022-12-10 : 55 2022-10-22 : 40 2022-06-14 : 50 2022-02-16 : 30 2021-12-12 : 45 2021-11-23 : 60 2020-04-01 : 42

[edit] See also

| | returns a reverse iterator to the beginning (public member function) [edit] | | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | | returns a reverse end iterator for a container or array (function template) [edit] |