Skip to content

Commit

Permalink
Extrae template obtener_ultimo()
Browse files Browse the repository at this point in the history
  • Loading branch information
autosquash committed Feb 25, 2024
1 parent ffe5c99 commit fb8e4a8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/templates/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <cassert>
#include <map>
#include <vector>

template <typename Key, typename Value>
bool has_key(const std::map<Key, Value> &mapeo, Key clave_a_buscar) {
Expand Down Expand Up @@ -34,3 +35,8 @@ template <typename Iterable, typename Condicion>
void ordenar_por_criterio(Iterable iterable, Condicion condicion) {
std::sort(iterable.begin(), iterable.end(), condicion);
}

/* Devuelve una referencia al ultimo elemento de un vector */
template <typename T> T &obtener_ultimo(std::vector<T> &elementos) {
return elementos.at(elementos.size() - 1);
}
3 changes: 1 addition & 2 deletions src/vista/tarjetas_pedidos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@ namespace {
) {
static const auto separacion_vertical =
medidas::SEPARACION_VERTICAL_ENTRE_PEDIDOS;
const auto num_etiquetas = tarjeta->etiquetas.size();
const auto &ultima_etiqueta = tarjeta->etiquetas.at(num_etiquetas - 1);
const auto &ultima_etiqueta = obtener_ultimo(tarjeta->etiquetas);
const auto g_bounds = ultima_etiqueta->get_global_bounds();
return get_bottom(g_bounds) + separacion_vertical;
}
Expand Down

0 comments on commit fb8e4a8

Please sign in to comment.