std::map<Key,T,Compare,Allocator>::rend, std::map<Key,T,Compare,Allocator>::crend
De cppreference.com
reverse_iterator rend(); |
(hasta C++11) | |
reverse_iterator rend() noexcept; |
(desde C++11) | |
const_reverse_iterator rend() const; |
(hasta C++11) | |
const_reverse_iterator rend() const noexcept; |
(desde C++11) | |
const_reverse_iterator crend() const noexcept; |
(desde C++11) | |
Devuelve un iterador inverso al elemento que sigue al último elemento del map
inverso. Corresponde al elemento que precede al primer elemento del map
sin invertir. Este elemento actúa como un marcador de posición; intentar accederlo resulta en comportamiento indefinido.
Contenido |
[editar] Parámetros
(Ninguno)
[editar] Valor de retorno
Iterador inverso al elemento que sigue al último elemento.
[editar] Complejidad
Constante.
[editar] Ejemplo
Ejecuta este código
#include <iostream> #include <iomanip> #include <chrono> #include <map> #include <string_view> using namespace std::chrono; // chrono operator<< listo hasta C++20 std::ostream& operator<<(std::ostream& os, const year_month_day& ymd) { return os << std::setfill('0') << static_cast<int>(ymd.year()) << '/' << std::setw(2) << static_cast<unsigned>(ymd.month()) << '/' << std::setw(2) << static_cast<unsigned>(ymd.day()); } int main() { const std::map<year_month_day, int> mensajes { { 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 << "Mensajes recibidos, fecha en orden inverso:\n"; for (auto it = mensajes.crbegin(); it != mensajes.crend(); ++it) { std::cout << it->first << " : " << it->second << '\n'; } }
Posible salida:
Mensajes recibidos, fecha en orden inverso: 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
[editar] Véase también
(C++11) |
Devuelve un iterador inverso al principio. (función miembro pública) |