diff options
-rw-r--r-- | gentoobrowse-api/client/helpers.h | 15 | ||||
-rw-r--r-- | gentoobrowse-api/client/search.cpp | 5 |
2 files changed, 9 insertions, 11 deletions
diff --git a/gentoobrowse-api/client/helpers.h b/gentoobrowse-api/client/helpers.h index 96399d2..4caf7f9 100644 --- a/gentoobrowse-api/client/helpers.h +++ b/gentoobrowse-api/client/helpers.h @@ -7,21 +7,20 @@ #include <map> #include <mutex> -template<typename Key, typename Target, typename Collection, typename Proxy> +template<typename Target, typename Key, typename Collection, typename Proxy, typename CollectionMember> std::map<Key, Target> -asyncMapRelated(const Collection & collection, const Proxy & p, Key Collection::value_type::element_type::*member, +asyncMapRelated(const Collection & collection, const Proxy & p, Key CollectionMember::*member, std::future<Target> (Proxy::element_type::*b)(Key, const ::Ice::Context &)) { - std::map<Key, Target> rtn; std::map<Key, std::future<Target>> jobs; for (const auto & item : collection) { - Key v = item.get()->*member; - if (jobs.find(v) == jobs.end()) { - jobs.insert({v, (p.get()->*b)(v, Ice::noExplicitContext)}); + if (Key v = item.get()->*member; jobs.find(v) == jobs.end()) { + jobs.emplace(v, (p.get()->*b)(v, Ice::noExplicitContext)); } } - for (auto & j : jobs) { - rtn.insert({j.first, j.second.get()}); + std::map<Key, Target> rtn; + for (auto & [cat, future] : jobs) { + rtn.emplace(cat, future.get()); } return rtn; } diff --git a/gentoobrowse-api/client/search.cpp b/gentoobrowse-api/client/search.cpp index 9d1c7b4..5de8d3b 100644 --- a/gentoobrowse-api/client/search.cpp +++ b/gentoobrowse-api/client/search.cpp @@ -10,9 +10,8 @@ public: run(const Gentoo::PortagePrxPtr & p, const std::vector<std::string> & a) const override { auto pkgs = p->getPackagesSearch(boost::algorithm::join(a, " ")); - auto cats = asyncMapRelated(pkgs, p, &Gentoo::Package::categoryid, - (std::future<Gentoo::CategoryPtr>(Gentoo::PortagePrx::*)(Ice::Int, const ::Ice::Context &)) - & Gentoo::PortagePrx::getCategoryAsync); + auto cats = asyncMapRelated<Gentoo::CategoryPtr>( + pkgs, p, &Gentoo::Package::categoryid, &Gentoo::PortagePrx::getCategoryAsync); fprintbf(stdout, "Found %d packages:\n", pkgs.size()); for (const auto & pkg : pkgs) { fprintbf(stdout, "%s / %s\n\t%s\n", cats[pkg->categoryid]->name, pkg->name, pkg->description); |