From c373f69cf8894d0d0bc2d1a28d6877eb7a51574c Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Mon, 19 Apr 2021 22:16:07 +0200 Subject: [PATCH] Use std algorithm. --- examples/cpp/app-bittorrent/s4u-peer.cpp | 7 ++----- src/kernel/routing/NetZoneImpl.cpp | 3 +-- src/kernel/routing/TorusZone.cpp | 4 +--- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/examples/cpp/app-bittorrent/s4u-peer.cpp b/examples/cpp/app-bittorrent/s4u-peer.cpp index 9bc67ba502..42b93556c8 100644 --- a/examples/cpp/app-bittorrent/s4u-peer.cpp +++ b/examples/cpp/app-bittorrent/s4u-peer.cpp @@ -234,11 +234,8 @@ unsigned int Peer::countPieces(unsigned int bitfield) const int Peer::nbInterestedPeers() const { - int nb = 0; - for (auto const& kv : connected_peers) - if (kv.second.interested) - nb++; - return nb; + return static_cast(std::count_if(connected_peers.begin(), connected_peers.end(), + [](const auto& kv) { return kv.second.interested; })); } void Peer::leech() diff --git a/src/kernel/routing/NetZoneImpl.cpp b/src/kernel/routing/NetZoneImpl.cpp index 67cf46ccc6..bec7fb8aa7 100644 --- a/src/kernel/routing/NetZoneImpl.cpp +++ b/src/kernel/routing/NetZoneImpl.cpp @@ -448,8 +448,7 @@ void NetZoneImpl::get_global_route(NetPoint* src, NetPoint* dst, /* If source gateway is not our source, we have to recursively find our way up to this point */ if (src != route.gw_src) get_global_route(src, route.gw_src, links, latency); - for (auto const& link : route.link_list) - links.push_back(link); + links.insert(links.end(), begin(route.link_list), end(route.link_list)); /* If dest gateway is not our destination, we have to recursively find our way from this point */ if (route.gw_dst != dst) diff --git a/src/kernel/routing/TorusZone.cpp b/src/kernel/routing/TorusZone.cpp index 5c9a239052..9118e3635f 100644 --- a/src/kernel/routing/TorusZone.cpp +++ b/src/kernel/routing/TorusZone.cpp @@ -64,9 +64,7 @@ void TorusZone::parse_specific_arguments(ClusterCreationArgs* cluster) * Parse attribute dimensions="dim1,dim2,dim3,...,dimN" and save them into a vector. * Additionally, we need to know how many ranks we have in total */ - for (auto const& group : dimensions) - dimensions_.push_back(surf_parse_get_int(group)); - + std::transform(begin(dimensions), end(dimensions), std::back_inserter(dimensions_), surf_parse_get_int); set_num_links_per_node(dimensions_.size()); } } -- 2.20.1