From ce6b4c2cc4b7728a5b5e6952072ad571f58fff74 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 19 Jan 2012 20:52:08 +0000 Subject: [PATCH] idvaluemap: complete_id_if method for conditional id completion --- src/idvaluemap.hh | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/idvaluemap.hh b/src/idvaluemap.hh index 7f7dc7de7..387e6fb02 100644 --- a/src/idvaluemap.hh +++ b/src/idvaluemap.hh @@ -63,14 +63,19 @@ public: } } - template - CandidateList complete_id(const std::string& prefix, - size_t cursor_pos) + template + CandidateList complete_id_if(const std::string& prefix, + size_t cursor_pos, + _Condition condition) { std::string real_prefix = prefix.substr(0, cursor_pos); CandidateList result; for (auto& value : m_content) { + if (not condition(value)) + continue; + std::string id_str = id_to_string(value.first); if (id_str.substr(0, real_prefix.length()) == real_prefix) result.push_back(std::move(id_str)); @@ -78,6 +83,14 @@ public: return result; } + template + CandidateList complete_id(const std::string& prefix, + size_t cursor_pos) + { + return complete_id_if( + prefix, cursor_pos, [](const value_type&) { return true; }); + } + iterator begin() { return m_content.begin(); } iterator end() { return m_content.end(); } const_iterator begin() const { return m_content.begin(); }