From c1d74196da4b2d9b50d1047dd521a29b81c78e7c Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Fri, 6 Mar 2020 12:38:18 +0100 Subject: [PATCH] Add a few helper functions for std::vector. --- include/lol/base/private/{map.h => containers.h} | 14 +++++++++++++- include/lol/base/utils.h | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) rename include/lol/base/private/{map.h => containers.h} (78%) diff --git a/include/lol/base/private/map.h b/include/lol/base/private/containers.h similarity index 78% rename from include/lol/base/private/map.h rename to include/lol/base/private/containers.h index 8a7171b9..adf6bfa7 100644 --- a/include/lol/base/private/map.h +++ b/include/lol/base/private/containers.h @@ -16,7 +16,7 @@ // // The map utilities // ————————————————— -// Contains some utilities to work with std::map objects. +// Contains some utilities to work with std::map and std::vector objects. // #include @@ -51,5 +51,17 @@ static inline std::vector keys(T const &m) return ret; } +template +static inline auto remove_at(std::vector &v, size_t i) +{ + return v.erase(v.begin() + i); +} + +template +static inline auto remove_item(std::vector &v, T const &x) +{ + return v.erase(std::remove(v.begin(), v.end(), x), v.end()); +} + } /* namespace lol */ diff --git a/include/lol/base/utils.h b/include/lol/base/utils.h index 20e35f6e..96c10aa2 100644 --- a/include/lol/base/utils.h +++ b/include/lol/base/utils.h @@ -13,5 +13,5 @@ #pragma once #include "private/string.h" -#include "private/map.h" +#include "private/containers.h"