Use algorithms in id_map rather than raw loops

This commit is contained in:
Maxime Coste 2014-12-11 13:55:04 +00:00
parent c148966ebb
commit 7a10029c4f

View File

@ -3,6 +3,7 @@
#include "completion.hh" #include "completion.hh"
#include "string.hh" #include "string.hh"
#include "utils.hh"
#include <vector> #include <vector>
@ -33,22 +34,14 @@ public:
iterator find(StringView id) iterator find(StringView id)
{ {
for (auto it = begin(); it != end(); ++it) return find_if(m_content,
{ [&](const value_type& v){ return v.first == id; });
if (it->first == id)
return it;
}
return end();
} }
const_iterator find(StringView id) const const_iterator find(StringView id) const
{ {
for (auto it = begin(); it != end(); ++it) return find_if(m_content,
{ [&](const value_type& v){ return v.first == id; });
if (it->first == id)
return it;
}
return end();
} }
bool contains(StringView id) const bool contains(StringView id) const
@ -65,8 +58,9 @@ public:
void remove_all(StringView id) void remove_all(StringView id)
{ {
for (auto it = find(id); it != end(); it = find(id)) auto it = std::remove_if(begin(), end(),
m_content.erase(it); [&](value_type& v){ return v.first == id; });
m_content.erase(it, end());
} }
template<typename Condition> template<typename Condition>