Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use std algorithm.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Mon, 19 Apr 2021 20:16:07 +0000 (22:16 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Mon, 19 Apr 2021 20:50:16 +0000 (22:50 +0200)
examples/cpp/app-bittorrent/s4u-peer.cpp
src/kernel/routing/NetZoneImpl.cpp
src/kernel/routing/TorusZone.cpp

index 9bc67ba..42b9355 100644 (file)
@@ -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<int>(std::count_if(connected_peers.begin(), connected_peers.end(),
+                                        [](const auto& kv) { return kv.second.interested; }));
 }
 
 void Peer::leech()
index 67cf46c..bec7fb8 100644 (file)
@@ -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)
index 5c9a239..9118e36 100644 (file)
@@ -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());
   }
 }