summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2020-12-30 16:45:20 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2020-12-30 16:45:20 +0000
commitffc91b4f26647b1066ab5694b356db7088fa48a3 (patch)
treef72dd50827c4469f9a159f4284f502a5afaf9e45
parentPass a cppcheck (diff)
downloadgentoobrowse-api-ffc91b4f26647b1066ab5694b356db7088fa48a3.tar.bz2
gentoobrowse-api-ffc91b4f26647b1066ab5694b356db7088fa48a3.tar.xz
gentoobrowse-api-ffc91b4f26647b1066ab5694b356db7088fa48a3.zip
Fix client compile with clang
-rw-r--r--gentoobrowse-api/client/helpers.h15
-rw-r--r--gentoobrowse-api/client/search.cpp5
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);