From 7a10029c4f05445eb6f2348d7153bf675c681d24 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 11 Dec 2014 13:55:04 +0000 Subject: [PATCH] Use algorithms in id_map rather than raw loops --- src/id_map.hh | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/src/id_map.hh b/src/id_map.hh index e8fe1ccb..97d6f45e 100644 --- a/src/id_map.hh +++ b/src/id_map.hh @@ -3,6 +3,7 @@ #include "completion.hh" #include "string.hh" +#include "utils.hh" #include @@ -33,22 +34,14 @@ public: iterator find(StringView id) { - for (auto it = begin(); it != end(); ++it) - { - if (it->first == id) - return it; - } - return end(); + return find_if(m_content, + [&](const value_type& v){ return v.first == id; }); } const_iterator find(StringView id) const { - for (auto it = begin(); it != end(); ++it) - { - if (it->first == id) - return it; - } - return end(); + return find_if(m_content, + [&](const value_type& v){ return v.first == id; }); } bool contains(StringView id) const @@ -65,8 +58,9 @@ public: void remove_all(StringView id) { - for (auto it = find(id); it != end(); it = find(id)) - m_content.erase(it); + auto it = std::remove_if(begin(), end(), + [&](value_type& v){ return v.first == id; }); + m_content.erase(it, end()); } template