Advanced find() for associative containers
I've written an improved version of find() for associative containers (in the form of a free function), and I need your help answering these two questions: 1. Will it be a useful addition to boost? 2. Where exactly should it fit in the boost? Public interface consists of a single free function template: template <typename C> auto find(C& c, const typename C::key_type& key); If element is found, return value evaluates to true and contains iterator to found element. If element is not found, return value evaluates to false and contains hint iterator for insert/emplace. Allowing one to do this: if (auto i = find(container, key)) { i->value_member(); container.erase(i); } And this: if (auto i = !find(container, key)) { container.insert(i, expensive_value_construction()); } The code is here: https://github.com/Boris-Rasin/find I've tested it with the following containers: std::map std::multimap std::unordered_map std::set std::multiset std::unordered_set boost::container::map boost::container::set boost::container::flat_map boost::container::flat_set boost::multi_index::ordered_unique boost::multi_index::ordered_non_unique boost::multi_index::hashed_unique boost::multi_index::hashed_non_unique boost::multi_index::ranked_unique boost::multi_index::ranked_non_unique Thanks for your comments and help.
On Thu, Mar 16, 2017 at 6:18 PM, Boris Rasin via Boost
I've written an improved version of find() for associative containers (in the form of a free function), and I need your help answering these two questions:
1. Will it be a useful addition to boost? 2. Where exactly should it fit in the boost?
Nice! I've got something similar: https://github.com/OlafvdSpek/xbt/blob/master/misc/xbt/find_ptr.h Most variants return a pointer rather than a (conditional) iterator. Gr, Olaf
participants (2)
-
Boris Rasin
-
Olaf van der Spek