From: Arnaud Giersch Date: Tue, 26 Apr 2022 22:02:38 +0000 (+0200) Subject: Use structured binding declarations (sonar, c++17). X-Git-Tag: v3.32~289 X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/321102577020b194dfb7ba89e48687952816849e Use structured binding declarations (sonar, c++17). --- diff --git a/examples/cpp/app-bittorrent/s4u-peer.cpp b/examples/cpp/app-bittorrent/s4u-peer.cpp index 83c22de863..bcbde2c05c 100644 --- a/examples/cpp/app-bittorrent/s4u-peer.cpp +++ b/examples/cpp/app-bittorrent/s4u-peer.cpp @@ -131,8 +131,7 @@ bool Peer::getPeersFromTracker() void Peer::sendHandshakeToAllPeers() { - for (auto const& kv : connected_peers) { - const Connection& remote_peer = kv.second; + for (auto const& [_, remote_peer] : connected_peers) { auto* handshake = new Message(MessageType::HANDSHAKE, id, mailbox_); remote_peer.mailbox_->put_init(handshake, message_size(MessageType::HANDSHAKE))->detach(); XBT_DEBUG("Sending a HANDSHAKE to %d", remote_peer.id); @@ -165,8 +164,7 @@ void Peer::sendPiece(sg4::Mailbox* mailbox, unsigned int piece, int block_index, void Peer::sendHaveToAllPeers(unsigned int piece) { XBT_DEBUG("Sending HAVE message to all my peers"); - for (auto const& kv : connected_peers) { - const Connection& remote_peer = kv.second; + for (auto const& [_, remote_peer] : connected_peers) { remote_peer.mailbox_->put_init(new Message(MessageType::HAVE, id, mailbox_, piece), message_size(MessageType::HAVE)) ->detach(); } @@ -558,8 +556,7 @@ void Peer::updateChokedPeers() /**If we are currently seeding, we unchoke the peer which has been unchoked the last time.*/ if (hasFinished()) { double unchoke_time = sg4::Engine::get_clock() + 1; - for (auto& kv : connected_peers) { - Connection& remote_peer = kv.second; + for (auto& [_, remote_peer] : connected_peers) { if (remote_peer.last_unchoke < unchoke_time && remote_peer.interested && remote_peer.choked_upload) { unchoke_time = remote_peer.last_unchoke; chosen_peer = &remote_peer; @@ -583,8 +580,7 @@ void Peer::updateChokedPeers() } else { // Use the "fastest download" policy. double fastest_speed = 0.0; - for (auto& kv : connected_peers) { - Connection& remote_peer = kv.second; + for (auto& [_, remote_peer] : connected_peers) { if (remote_peer.peer_speed > fastest_speed && remote_peer.choked_upload && remote_peer.interested) { fastest_speed = remote_peer.peer_speed; chosen_peer = &remote_peer; @@ -620,8 +616,7 @@ void Peer::updateChokedPeers() /** @brief Update "interested" state of peers: send "not interested" to peers that don't have any more pieces we want.*/ void Peer::updateInterestedAfterReceive() { - for (auto& kv : connected_peers) { - Connection& remote_peer = kv.second; + for (auto& [_, remote_peer] : connected_peers) { if (remote_peer.am_interested) { bool interested = false; // Check if the peer still has a piece we want. diff --git a/examples/cpp/dht-kademlia/answer.cpp b/examples/cpp/dht-kademlia/answer.cpp index 03298516e9..8e98e767ff 100644 --- a/examples/cpp/dht-kademlia/answer.cpp +++ b/examples/cpp/dht-kademlia/answer.cpp @@ -15,8 +15,8 @@ void Answer::print() const { XBT_INFO("Searching %08x, size %zu", destination_id_, nodes_.size()); unsigned int i = 0; - for (auto const& contact : nodes_) - XBT_INFO("Node %08x: %08x is at distance %u", i++, contact.first, contact.second); + for (auto const& [contact, distance] : nodes_) + XBT_INFO("Node %08x: %08x is at distance %u", i++, contact, distance); } /** @brief Merge two answers together, only keeping the best nodes diff --git a/examples/cpp/dht-kademlia/node.cpp b/examples/cpp/dht-kademlia/node.cpp index 49374f88e8..4437cc2ede 100644 --- a/examples/cpp/dht-kademlia/node.cpp +++ b/examples/cpp/dht-kademlia/node.cpp @@ -52,8 +52,8 @@ bool Node::join(unsigned int known_id) // retrieve the node list and ping them. const Answer* node_list = msg->answer_.get(); if (node_list) { - for (auto const& contact : node_list->getNodes()) - routingTableUpdate(contact.first); + for (auto const& [contact, _] : node_list->getNodes()) + routingTableUpdate(contact); } else { handleFindNode(msg); } @@ -105,11 +105,11 @@ unsigned int Node::sendFindNodeToBest(const Answer* node_list) const unsigned int i = 0; unsigned int j = 0; unsigned int destination = node_list->getDestinationId(); - for (auto const& node_to_query : node_list->getNodes()) { + for (auto const& [node_to_query, _] : node_list->getNodes()) { /* We need to have at most "KADEMLIA_ALPHA" requests each time, according to the protocol */ /* Gets the node we want to send the query to */ - if (node_to_query.first != id_) { /* No need to query ourselves */ - sendFindNode(node_to_query.first, destination); + if (node_to_query != id_) { /* No need to query ourselves */ + sendFindNode(node_to_query, destination); j++; } i++; @@ -213,8 +213,8 @@ bool Node::findNode(unsigned int id_to_find, bool count_in_stats) if (msg->answer_ && msg->answer_->getDestinationId() == id_to_find) { routingTableUpdate(msg->sender_id_); // Handle the answer - for (auto const& contact : node_list->getNodes()) - routingTableUpdate(contact.first); + for (auto const& [contact, _] : node_list->getNodes()) + routingTableUpdate(contact); answers++; nodes_added = node_list->merge(msg->answer_.get()); diff --git a/examples/cpp/io-disk-raw/s4u-io-disk-raw.cpp b/examples/cpp/io-disk-raw/s4u-io-disk-raw.cpp index f5ce9dda57..59a69e2d0c 100644 --- a/examples/cpp/io-disk-raw/s4u-io-disk-raw.cpp +++ b/examples/cpp/io-disk-raw/s4u-io-disk-raw.cpp @@ -61,8 +61,8 @@ int main(int argc, char** argv) /* - Display Host properties */ for (auto h : e.get_all_hosts()) { XBT_INFO("*** %s properties ****", h->get_cname()); - for (auto const& kv : *h->get_properties()) - XBT_INFO(" %s -> %s", kv.first.c_str(), kv.second.c_str()); + for (auto const& [key, value] : *h->get_properties()) + XBT_INFO(" %s -> %s", key.c_str(), value.c_str()); } sg4::Actor::create("", e.host_by_name("bob"), host); diff --git a/examples/cpp/network-factors/s4u-network-factors.cpp b/examples/cpp/network-factors/s4u-network-factors.cpp index 97efd8d4d9..4eca7b86a2 100644 --- a/examples/cpp/network-factors/s4u-network-factors.cpp +++ b/examples/cpp/network-factors/s4u-network-factors.cpp @@ -92,11 +92,11 @@ static void load_platform() static double get_factor_from_map(const std::map& factors, double size) { double factor = 1.0; - for (auto const& fact : factors) { - if (size < fact.first) { + for (auto const& [factor_size, factor_value] : factors) { + if (size < factor_size) { break; } else { - factor = fact.second; + factor = factor_value; } } return factor; diff --git a/examples/cpp/platform-properties/s4u-platform-properties.cpp b/examples/cpp/platform-properties/s4u-platform-properties.cpp index 14e166f63f..05de2f310e 100644 --- a/examples/cpp/platform-properties/s4u-platform-properties.cpp +++ b/examples/cpp/platform-properties/s4u-platform-properties.cpp @@ -23,8 +23,8 @@ static void test_host(const std::string& hostname) XBT_INFO("== Print the properties of the host '%s'", hostname.c_str()); // Sort the properties before displaying them, so that the tests are perfectly reproducible std::vector keys; - for (auto const& kv : *hostprops) - keys.push_back(kv.first); + for (auto const& [key, _] : *hostprops) + keys.push_back(key); std::sort(keys.begin(), keys.end()); for (const std::string& key : keys) XBT_INFO(" Host property: '%s' -> '%s'", key.c_str(), hostprops->at(key).c_str()); @@ -56,8 +56,8 @@ static void test_host(const std::string& hostname) XBT_INFO("== Print the properties of the zone '%s' that contains '%s'", thezone->get_cname(), hostname.c_str()); const std::unordered_map* zoneprops = thezone->get_properties(); keys.clear(); - for (auto const& kv : *zoneprops) - keys.push_back(kv.first); + for (auto const& [key, _] : *zoneprops) + keys.push_back(key); std::sort(keys.begin(), keys.end()); for (const std::string& key : keys) XBT_INFO(" Zone property: '%s' -> '%s'", key.c_str(), zoneprops->at(key).c_str()); @@ -95,15 +95,14 @@ static void bob() /* Get the property list of current bob actor */ const std::unordered_map* props = sg4::Actor::self()->get_properties(); const char* noexist = "UnknownProcessProp"; - XBT_ATTRIB_UNUSED const char* value; XBT_INFO("== Print the properties of the actor"); - for (const auto& kv : *props) - XBT_INFO(" Actor property: %s -> %s", kv.first.c_str(), kv.second.c_str()); + for (const auto& [key, value] : *props) + XBT_INFO(" Actor property: %s -> %s", key.c_str(), value.c_str()); XBT_INFO("== Try to get an actor property that does not exist"); - value = sg4::Actor::self()->get_property(noexist); + const char* value = sg4::Actor::self()->get_property(noexist); xbt_assert(not value, "The property is defined (it should not)"); } diff --git a/src/dag/loaders.cpp b/src/dag/loaders.cpp index 5a313317b0..29999ff202 100644 --- a/src/dag/loaders.cpp +++ b/src/dag/loaders.cpp @@ -110,10 +110,8 @@ std::vector create_DAG_from_DAX(const std::string& filename) * Files not produced in the system are said to be produced by root task (top of DAG). * Files not consumed in the system are said to be consumed by end task (bottom of DAG). */ - CommPtr file; - - for (auto const& elm : files) { - file = elm.second; + for (auto const& [_, elm] : files) { + CommPtr file = elm; CommPtr newfile; if (file->dependencies_solved()) { for (auto const& it : file->get_successors()) { diff --git a/src/instr/instr_paje_containers.cpp b/src/instr/instr_paje_containers.cpp index 3d680b27b1..8fcdfa0938 100644 --- a/src/instr/instr_paje_containers.cpp +++ b/src/instr/instr_paje_containers.cpp @@ -74,8 +74,8 @@ Container::~Container() { XBT_DEBUG("destroy container %s", get_cname()); // Begin with destroying my own children - for (auto child : children_) - delete child.second; + for (auto [_, child] : children_) + delete child; // remove me from the all_containers_ data structure all_containers_.erase(name_); diff --git a/src/instr/instr_paje_types.cpp b/src/instr/instr_paje_types.cpp index 7defa58b75..8817b211ff 100644 --- a/src/instr/instr_paje_types.cpp +++ b/src/instr/instr_paje_types.cpp @@ -109,12 +109,12 @@ void LinkType::end_event(Container* endContainer, const std::string& value, cons Type* Type::by_name(const std::string& name) { Type* ret = nullptr; - for (auto const& elm : children_) { - if (elm.second->name_ == name) { + for (auto const& [_, child] : children_) { + if (child->name_ == name) { if (ret != nullptr) { throw TracingError(XBT_THROW_POINT, "there are two children types with the same name?"); } else { - ret = elm.second.get(); + ret = child.get(); } } } diff --git a/src/instr/instr_platform.cpp b/src/instr/instr_platform.cpp index deaa01a13d..4d741c9250 100644 --- a/src/instr/instr_platform.cpp +++ b/src/instr/instr_platform.cpp @@ -131,8 +131,7 @@ static void recursiveGraphExtraction(const simgrid::s4u::NetZone* netzone, const std::map> edges; netzone->get_impl()->get_graph(graph, &nodes, &edges); - for (auto const& elm : edges) { - const xbt_edge* edge = elm.second; + for (auto const& [_, edge] : edges) { linkContainers(simgrid::instr::Container::by_name(static_cast(edge->src->data)), simgrid::instr::Container::by_name(static_cast(edge->dst->data)), filter); } @@ -151,8 +150,8 @@ static void recursiveNewVariableType(const std::string& new_typename, const std: if (root->get_name() == "LINK") root->by_name_or_create(std::string("b") + new_typename, color); - for (auto const& elm : root->get_children()) { - recursiveNewVariableType(new_typename, color, elm.second.get()); + for (auto const& [_, child] : root->get_children()) { + recursiveNewVariableType(new_typename, color, child.get()); } } @@ -167,8 +166,8 @@ static void recursiveNewUserVariableType(const std::string& parent_type, const s if (root->get_name() == parent_type) { root->by_name_or_create(new_typename, color); } - for (auto const& elm : root->get_children()) - recursiveNewUserVariableType(parent_type, new_typename, color, elm.second.get()); + for (auto const& [_, child] : root->get_children()) + recursiveNewUserVariableType(parent_type, new_typename, color, child.get()); } void instr_new_user_variable_type(const std::string& parent_type, const std::string& new_typename, @@ -183,8 +182,8 @@ static void recursiveNewUserStateType(const std::string& parent_type, const std: if (root->get_name() == parent_type) root->by_name_or_create(new_typename); - for (auto const& elm : root->get_children()) - recursiveNewUserStateType(parent_type, new_typename, elm.second.get()); + for (auto const& [_, child] : root->get_children()) + recursiveNewUserStateType(parent_type, new_typename, child.get()); } void instr_new_user_state_type(const std::string& parent_type, const std::string& new_typename) @@ -198,8 +197,8 @@ static void recursiveNewValueForUserStateType(const std::string& type_name, cons if (root->get_name() == type_name) static_cast(root)->add_entity_value(val, color); - for (auto const& elm : root->get_children()) - recursiveNewValueForUserStateType(type_name, val, color, elm.second.get()); + for (auto const& [_, child] : root->get_children()) + recursiveNewValueForUserStateType(type_name, val, color, child.get()); } void instr_new_value_for_user_state_type(const std::string& type_name, const char* value, const std::string& color) @@ -236,12 +235,12 @@ void platform_graph_export_graphviz(const std::string& output_filename) fs << " node [shape=box, style=filled]" << std::endl; fs << " node [width=.3, height=.3, style=filled, color=skyblue]" << std::endl << std::endl; - for (auto const& elm : nodes) - fs << " \"" << elm.first << "\";" << std::endl; + for (auto const& [node, _] : nodes) + fs << " \"" << node << "\";" << std::endl; - for (auto const& elm : edges) { - const char* src_s = static_cast(elm.second->src->data); - const char* dst_s = static_cast(elm.second->dst->data); + for (auto const& [_, edge] : edges) { + const char* src_s = static_cast(edge->src->data); + const char* dst_s = static_cast(edge->dst->data); if (g->directed) fs << " \"" << src_s << "\" -> \"" << dst_s << "\";" << std::endl; else diff --git a/src/kernel/EngineImpl.cpp b/src/kernel/EngineImpl.cpp index 3d4b00e20b..0aba684cbf 100644 --- a/src/kernel/EngineImpl.cpp +++ b/src/kernel/EngineImpl.cpp @@ -61,8 +61,8 @@ static inline std::string contexts_list() { std::string res; std::string sep = ""; - for (auto const& factory : context_factories) { - res += sep + factory.first; + for (auto const& [factory_name, _] : context_factories) { + res += sep + factory_name; sep = ", "; } return res; @@ -167,11 +167,11 @@ EngineImpl::~EngineImpl() { /* Also delete the other data */ delete netzone_root_; - for (auto const& kv : netpoints_) - delete kv.second; + for (auto const& [_, netpoint] : netpoints_) + delete netpoint; - for (auto const& kv : mailboxes_) - delete kv.second; + for (auto const& [_, mailbox] : mailboxes_) + delete mailbox; /* Kill all actors (but maestro) */ maestro_->kill_all(); @@ -251,9 +251,9 @@ void EngineImpl::context_mod_init() const return; } /* use the factory specified by --cfg=contexts/factory:value */ - for (auto const& factory : context_factories) - if (context_factory_name == factory.first) { - instance_->set_context_factory(factory.second()); + for (auto const& [factory_name, factory] : context_factories) + if (context_factory_name == factory_name) { + instance_->set_context_factory(factory()); break; } @@ -479,9 +479,7 @@ void EngineImpl::display_all_actor_status() const XBT_INFO("%zu actors are still running, waiting for something.", actor_list_.size()); /* List the actors and their state */ XBT_INFO("Legend of the following listing: \"Actor (@): \""); - for (auto const& kv : actor_list_) { - const actor::ActorImpl* actor = kv.second; - + for (auto const& [_, actor] : actor_list_) { if (actor->waiting_synchro_) { const char* synchro_description = "unknown"; @@ -730,9 +728,9 @@ void EngineImpl::run(double max_date) } display_all_actor_status(); simgrid::s4u::Engine::on_deadlock(); - for (auto const& kv : actor_list_) { - XBT_DEBUG("Kill %s", kv.second->get_cname()); - maestro_->kill(kv.second); + for (auto const& [_, actor] : actor_list_) { + XBT_DEBUG("Kill %s", actor->get_cname()); + maestro_->kill(actor); } } } while ((vetoed_activities == nullptr || vetoed_activities->empty()) && diff --git a/src/kernel/actor/ActorImpl.cpp b/src/kernel/actor/ActorImpl.cpp index a9e747f939..e679e0f027 100644 --- a/src/kernel/actor/ActorImpl.cpp +++ b/src/kernel/actor/ActorImpl.cpp @@ -239,9 +239,9 @@ void ActorImpl::kill(ActorImpl* actor) const void ActorImpl::kill_all() const { - for (auto const& kv : EngineImpl::get_instance()->get_actor_list()) - if (kv.second != this) - this->kill(kv.second); + for (auto const& [_, actor] : EngineImpl::get_instance()->get_actor_list()) + if (actor != this) + this->kill(actor); } void ActorImpl::set_kill_time(double kill_time) diff --git a/src/kernel/lmm/bmf.cpp b/src/kernel/lmm/bmf.cpp index 5f5d37c9e7..4dfe5784ff 100644 --- a/src/kernel/lmm/bmf.cpp +++ b/src/kernel/lmm/bmf.cpp @@ -102,8 +102,8 @@ template std::string BmfSolver::debug_vector(const C& container) co std::string BmfSolver::debug_alloc(const allocation_map_t& alloc) const { std::stringstream debug; - for (const auto& e : alloc) { - debug << "{" + std::to_string(e.first) + ": [" + debug_vector(e.second) + "]}, "; + for (const auto& [resource, players] : alloc) { + debug << "{" + std::to_string(resource) + ": [" + debug_vector(players) + "]}, "; } return debug.str(); } @@ -132,9 +132,9 @@ double BmfSolver::get_maxmin_share(int resource, const std::vector& bounded std::vector BmfSolver::alloc_map_to_vector(const allocation_map_t& alloc) const { std::vector alloc_by_player(A_.cols(), -1); - for (const auto& it : alloc) { - for (auto p : it.second) { - alloc_by_player[p] = it.first; + for (const auto& [resource, players] : alloc) { + for (auto p : players) { + alloc_by_player[p] = resource; } } return alloc_by_player; @@ -143,9 +143,9 @@ std::vector BmfSolver::alloc_map_to_vector(const allocation_map_t& alloc) c std::vector BmfSolver::get_bounded_players(const allocation_map_t& alloc) const { std::vector bounded_players; - for (const auto& e : alloc) { - if (e.first == NO_RESOURCE) { - bounded_players.insert(bounded_players.end(), e.second.begin(), e.second.end()); + for (const auto& [resource, players] : alloc) { + if (resource == NO_RESOURCE) { + bounded_players.insert(bounded_players.end(), players.begin(), players.end()); } } return bounded_players; @@ -159,38 +159,37 @@ Eigen::VectorXd BmfSolver::equilibrium(const allocation_map_t& alloc) const int row = 0; auto bounded_players = get_bounded_players(alloc); - for (const auto& e : alloc) { + for (const auto& [resource, players] : alloc) { // add one row for the resource with A[r,] - int cur_resource = e.first; /* bounded players, nothing to do */ - if (cur_resource == NO_RESOURCE) + if (resource == NO_RESOURCE) continue; /* not shared resource, each player can receive the full capacity of the resource */ - if (not C_shared_[cur_resource]) { - for (int i : e.second) { - C_p[row] = get_resource_capacity(cur_resource, bounded_players); - A_p(row, i) = A_(cur_resource, i); + if (not C_shared_[resource]) { + for (int i : players) { + C_p[row] = get_resource_capacity(resource, bounded_players); + A_p(row, i) = A_(resource, i); row++; } continue; } /* shared resource: fairly share it between players */ - A_p.row(row) = A_.row(cur_resource); - C_p[row] = get_resource_capacity(cur_resource, bounded_players); + A_p.row(row) = A_.row(resource); + C_p[row] = get_resource_capacity(resource, bounded_players); row++; - if (e.second.size() > 1) { + if (players.size() > 1) { // if 2 players have chosen the same resource // they must have a fair sharing of this resource, adjust A_p and C_p accordingly - auto it = e.second.begin(); + auto it = players.begin(); int i = *it; // first player /* for each other player sharing this resource */ - for (++it; it != e.second.end(); ++it) { + for (++it; it != players.end(); ++it) { /* player i and k on this resource j: so maxA_ji*rho_i - maxA_jk*rho_k = 0 */ int k = *it; C_p[row] = 0; - A_p(row, i) = maxA_(cur_resource, i); - A_p(row, k) = -maxA_(cur_resource, k); + A_p(row, i) = maxA_(resource, i); + A_p(row, k) = -maxA_(resource, k); row++; } } diff --git a/src/kernel/resource/profile/Profile.cpp b/src/kernel/resource/profile/Profile.cpp index dfb68d1758..bc45ead1f3 100644 --- a/src/kernel/resource/profile/Profile.cpp +++ b/src/kernel/resource/profile/Profile.cpp @@ -81,8 +81,8 @@ Profile::Profile(const std::string& name, const std::functionlink_list_, e_route->link_list_, lat); } - auto elm = route_cache_.try_emplace(src_id); - std::vector& pred_arr = elm.first->second; + auto [elm, inserted] = route_cache_.try_emplace(src_id); + std::vector& pred_arr = elm->second; - if (elm.second) { /* new element was inserted (not cached mode, or cache miss) */ + if (inserted) { /* new element was inserted (not cached mode, or cache miss) */ unsigned long nr_nodes = xbt_dynar_length(nodes); std::vector cost_arr(nr_nodes); /* link cost from src to other hosts */ pred_arr.resize(nr_nodes); /* predecessors in path from src */ diff --git a/src/kernel/routing/NetZoneImpl.cpp b/src/kernel/routing/NetZoneImpl.cpp index 703a97d31c..1de62fd587 100644 --- a/src/kernel/routing/NetZoneImpl.cpp +++ b/src/kernel/routing/NetZoneImpl.cpp @@ -112,17 +112,17 @@ NetZoneImpl::~NetZoneImpl() /* Since hosts_ and links_ are a std::map, the hosts are destroyed in the lexicographic order, which ensures that the * output is reproducible. */ - for (auto& host : hosts_) { - host.second->destroy(); + for (auto& [_, host] : hosts_) { + host->destroy(); } hosts_.clear(); - for (auto& link : links_) { - link.second->destroy(); + for (auto& [_, link] : links_) { + link->destroy(); } links_.clear(); - for (auto const& kv : bypass_routes_) - delete kv.second; + for (auto const& [_, route] : bypass_routes_) + delete route; s4u::Engine::get_instance()->netpoint_unregister(netpoint_); } @@ -153,8 +153,8 @@ size_t NetZoneImpl::get_host_count() const std::vector NetZoneImpl::get_filtered_links(const std::function& filter) const { std::vector filtered_list; - for (auto const& kv : links_) { - s4u::Link* l = kv.second->get_iface(); + for (auto const& [_, link] : links_) { + s4u::Link* l = link->get_iface(); if (filter(l)) filtered_list.push_back(l); } @@ -322,8 +322,7 @@ resource::SplitDuplexLinkImpl* NetZoneImpl::get_split_duplex_link_by_name_or_nul resource::HostImpl* NetZoneImpl::get_host_by_name_or_null(const std::string& name) const { - for (auto const& kv : hosts_) { - auto* host = kv.second; + for (auto const& [_, host] : hosts_) { if (host->get_name() == name) return host; /* keep old behavior where host and VMs were saved together on EngineImpl::hosts_ @@ -345,8 +344,8 @@ resource::HostImpl* NetZoneImpl::get_host_by_name_or_null(const std::string& nam std::vector NetZoneImpl::get_filtered_hosts(const std::function& filter) const { std::vector filtered_list; - for (auto const& kv : hosts_) { - s4u::Host* h = kv.second->get_iface(); + for (auto const& [_, host] : hosts_) { + s4u::Host* h = host->get_iface(); if (filter(h)) filtered_list.push_back(h); /* Engine::get_hosts returns the VMs too */ @@ -659,8 +658,8 @@ void NetZoneImpl::seal() } /* sealing links */ - for (auto const& kv : links_) - kv.second->get_iface()->seal(); + for (auto const& [_, link] : links_) + link->get_iface()->seal(); for (auto* sub_net : get_children()) { sub_net->seal(); diff --git a/src/kernel/routing/StarZone.cpp b/src/kernel/routing/StarZone.cpp index ee9a808398..2de8f5e842 100644 --- a/src/kernel/routing/StarZone.cpp +++ b/src/kernel/routing/StarZone.cpp @@ -170,10 +170,10 @@ void StarZone::do_seal() { /* add default empty links if nothing was configured by user */ for (auto const& node : get_vertices()) { - auto route = routes_.try_emplace(node->id()); - if (route.second) { - route.first->second.links_down_set = true; - route.first->second.links_up_set = true; + auto [route, inserted] = routes_.try_emplace(node->id()); + if (inserted) { + route->second.links_down_set = true; + route->second.links_up_set = true; } } } diff --git a/src/mc/ModelChecker.cpp b/src/mc/ModelChecker.cpp index cf46e68342..733e1f7105 100644 --- a/src/mc/ModelChecker.cpp +++ b/src/mc/ModelChecker.cpp @@ -101,8 +101,8 @@ static constexpr auto ignored_local_variables = { void ModelChecker::setup_ignore() { const RemoteProcess& process = this->get_remote_process(); - for (auto const& var : ignored_local_variables) - process.ignore_local_variable(var.first, var.second); + for (auto const& [var, frame] : ignored_local_variables) + process.ignore_local_variable(var, frame); /* Static variable used for tracing */ process.ignore_global_variable("counter"); diff --git a/src/mc/VisitedState.cpp b/src/mc/VisitedState.cpp index 873154cc3e..16a667614d 100644 --- a/src/mc/VisitedState.cpp +++ b/src/mc/VisitedState.cpp @@ -48,10 +48,10 @@ VisitedStates::addVisitedState(unsigned long state_number, simgrid::mc::State* g XBT_DEBUG("Snapshot %p of visited state %ld (exploration stack state %ld)", new_state->system_state.get(), new_state->num, graph_state->get_num()); - auto range = boost::range::equal_range(states_, new_state.get(), Api::get().compare_pair()); + auto [range_begin, range_end] = boost::range::equal_range(states_, new_state.get(), Api::get().compare_pair()); if (compare_snapshots) - for (auto i = range.first; i != range.second; ++i) { + for (auto i = range_begin; i != range_end; ++i) { auto& visited_state = *i; if (Api::get().snapshot_equal(visited_state->system_state.get(), new_state->system_state.get())) { // The state has been visited: @@ -81,7 +81,7 @@ VisitedStates::addVisitedState(unsigned long state_number, simgrid::mc::State* g } XBT_DEBUG("Insert new visited state %ld (total : %lu)", new_state->num, (unsigned long)states_.size()); - states_.insert(range.first, std::move(new_state)); + states_.insert(range_begin, std::move(new_state)); this->prune(); return nullptr; } diff --git a/src/mc/explo/LivenessChecker.cpp b/src/mc/explo/LivenessChecker.cpp index 6cfd589ea0..699d50616e 100644 --- a/src/mc/explo/LivenessChecker.cpp +++ b/src/mc/explo/LivenessChecker.cpp @@ -64,10 +64,10 @@ std::shared_ptr LivenessChecker::insert_acceptance_pair(simgrid::mc auto new_pair = std::make_shared(pair->num, pair->automaton_state, pair->atomic_propositions, pair->graph_state); - auto res = boost::range::equal_range(acceptance_pairs_, new_pair.get(), Api::get().compare_pair()); + auto [res_begin, res_end] = boost::range::equal_range(acceptance_pairs_, new_pair.get(), Api::get().compare_pair()); if (pair->search_cycle) - for (auto i = res.first; i != res.second; ++i) { + for (auto i = res_begin; i != res_end; ++i) { std::shared_ptr const& pair_test = *i; if (xbt_automaton_state_compare(pair_test->automaton_state, new_pair->automaton_state) != 0 || *(pair_test->atomic_propositions) != *(new_pair->atomic_propositions) || @@ -82,7 +82,7 @@ std::shared_ptr LivenessChecker::insert_acceptance_pair(simgrid::mc return nullptr; } - acceptance_pairs_.insert(res.first, new_pair); + acceptance_pairs_.insert(res_begin, new_pair); return new_pair; } @@ -142,9 +142,10 @@ int LivenessChecker::insert_visited_pair(std::shared_ptr visited_pa visited_pair = std::make_shared(pair->num, pair->automaton_state, pair->atomic_propositions, pair->graph_state); - auto range = boost::range::equal_range(visited_pairs_, visited_pair.get(), Api::get().compare_pair()); + auto [range_begin, range_end] = + boost::range::equal_range(visited_pairs_, visited_pair.get(), Api::get().compare_pair()); - for (auto i = range.first; i != range.second; ++i) { + for (auto i = range_begin; i != range_end; ++i) { const VisitedPair* pair_test = i->get(); if (xbt_automaton_state_compare(pair_test->automaton_state, visited_pair->automaton_state) != 0 || *(pair_test->atomic_propositions) != *(visited_pair->atomic_propositions) || @@ -164,7 +165,7 @@ int LivenessChecker::insert_visited_pair(std::shared_ptr visited_pa return (*i)->other_num; } - visited_pairs_.insert(range.first, std::move(visited_pair)); + visited_pairs_.insert(range_begin, std::move(visited_pair)); this->purge_visited_pairs(); return -1; } diff --git a/src/mc/inspect/ObjectInformation.cpp b/src/mc/inspect/ObjectInformation.cpp index 576eaa2bbb..f7edbc5d72 100644 --- a/src/mc/inspect/ObjectInformation.cpp +++ b/src/mc/inspect/ObjectInformation.cpp @@ -124,8 +124,8 @@ static void remove_local_variable(Frame& scope, const char* var_name, const char void ObjectInformation::remove_local_variable(const char* var_name, const char* subprogram_name) { - for (auto& entry : this->subprograms) - mc::remove_local_variable(entry.second, var_name, subprogram_name, entry.second); + for (auto& [_, entry] : this->subprograms) + mc::remove_local_variable(entry, var_name, subprogram_name, entry); } /** @brief Fills the position of the segments (executable, read-only, read/write) */ diff --git a/src/mc/inspect/mc_dwarf.cpp b/src/mc/inspect/mc_dwarf.cpp index f8481b3b65..b9bee29f66 100644 --- a/src/mc/inspect/mc_dwarf.cpp +++ b/src/mc/inspect/mc_dwarf.cpp @@ -1051,12 +1051,12 @@ static void MC_make_functions_index(simgrid::mc::ObjectInformation* info) { info->functions_index.clear(); - for (auto& e : info->subprograms) { - if (e.second.range.begin() == 0) + for (auto& [_, e] : info->subprograms) { + if (e.range.begin() == 0) continue; simgrid::mc::FunctionIndexEntry entry; - entry.low_pc = (void*)e.second.range.begin(); - entry.function = &e.second; + entry.low_pc = (void*)e.range.begin(); + entry.function = &e; info->functions_index.push_back(entry); } @@ -1126,9 +1126,9 @@ static simgrid::mc::Type* MC_resolve_type(simgrid::mc::ObjectInformation* info, static void MC_post_process_types(simgrid::mc::ObjectInformation* info) { // Lookup "subtype" field: - for (auto& i : info->types) { - i.second.subtype = MC_resolve_type(info, i.second.type_id); - for (simgrid::mc::Member& member : i.second.members) + for (auto& [_, i] : info->types) { + i.subtype = MC_resolve_type(info, i.type_id); + for (simgrid::mc::Member& member : i.members) member.type = MC_resolve_type(info, member.type_id); } } @@ -1145,8 +1145,8 @@ void ObjectInformation::ensure_dwarf_loaded() MC_load_dwarf(this); MC_post_process_variables(this); MC_post_process_types(this); - for (auto& entry : this->subprograms) - mc_post_process_scope(this, &entry.second); + for (auto& [_, entry] : this->subprograms) + mc_post_process_scope(this, &entry); MC_make_functions_index(this); } @@ -1163,8 +1163,8 @@ std::shared_ptr createObjectInformation(std::vectortypes) { - Type* type = &(t.second); + for (auto& [_, t] : info->types) { + Type* type = &t; Type* subtype = type; while (subtype->type == DW_TAG_typedef || subtype->type == DW_TAG_volatile_type || subtype->type == DW_TAG_const_type) diff --git a/src/mc/mc_base.cpp b/src/mc/mc_base.cpp index dbebae25ca..1631cd2ec5 100644 --- a/src/mc/mc_base.cpp +++ b/src/mc/mc_base.cpp @@ -56,8 +56,7 @@ void execute_actors() } #if SIMGRID_HAVE_MC engine->reset_actor_dynar(); - for (auto const& kv : engine->get_actor_list()) { - auto actor = kv.second; + for (auto const& [_, actor] : engine->get_actor_list()) { // Only visible requests remain at this point, and they all have an observer actor->simcall_.mc_max_consider_ = actor->simcall_.observer_->get_max_consider(); diff --git a/src/mc/sosp/Region.cpp b/src/mc/sosp/Region.cpp index 0498493faa..e33d13c485 100644 --- a/src/mc/sosp/Region.cpp +++ b/src/mc/sosp/Region.cpp @@ -45,10 +45,8 @@ void Region::restore() const static XBT_ALWAYS_INLINE void* mc_translate_address_region(uintptr_t addr, const simgrid::mc::Region* region) { - auto split = simgrid::mc::mmu::split(addr - region->start().address()); - auto pageno = split.first; - auto offset = split.second; - void* snapshot_page = region->get_chunks().page(pageno); + auto [pageno, offset] = simgrid::mc::mmu::split(addr - region->start().address()); + void* snapshot_page = region->get_chunks().page(pageno); return (char*)snapshot_page + offset; } diff --git a/src/plugins/vm/dirty_page_tracking.cpp b/src/plugins/vm/dirty_page_tracking.cpp index a613069691..dc0b8d5f7f 100644 --- a/src/plugins/vm/dirty_page_tracking.cpp +++ b/src/plugins/vm/dirty_page_tracking.cpp @@ -49,17 +49,17 @@ simgrid::xbt::Extensionget_remaining(); + for (auto const& [exec, _] : dp_objs_) + dp_objs_[exec] = exec->get_remaining(); } double DirtyPageTrackingExt::computed_flops_lookup() { double total = 0; - for (auto const& elm : dp_objs_) { - total += elm.second - elm.first->get_remaining(); - dp_objs_[elm.first] = elm.first->get_remaining(); + for (auto const& [exec, flops] : dp_objs_) { + total += flops - exec->get_remaining(); + dp_objs_[exec] = exec->get_remaining(); } total += dp_updated_by_deleted_tasks_; diff --git a/src/s4u/s4u_Actor.cpp b/src/s4u/s4u_Actor.cpp index 372470bb86..8c0fc2e679 100644 --- a/src/s4u/s4u_Actor.cpp +++ b/src/s4u/s4u_Actor.cpp @@ -588,8 +588,8 @@ xbt_dict_t sg_actor_get_properties(const_sg_actor_t actor) const std::unordered_map* props = actor->get_properties(); if (props == nullptr) return nullptr; - for (auto const& kv : *props) { - xbt_dict_set(as_dict, kv.first.c_str(), xbt_strdup(kv.second.c_str())); + for (auto const& [key, value] : *props) { + xbt_dict_set(as_dict, key.c_str(), xbt_strdup(value.c_str())); } return as_dict; } diff --git a/src/s4u/s4u_Engine.cpp b/src/s4u/s4u_Engine.cpp index 76166e0f19..4381569600 100644 --- a/src/s4u/s4u_Engine.cpp +++ b/src/s4u/s4u_Engine.cpp @@ -268,12 +268,12 @@ Mailbox* Engine::mailbox_by_name_or_create(const std::string& name) const { /* two actors may have pushed the same mbox_create simcall at the same time */ kernel::activity::MailboxImpl* mbox = kernel::actor::simcall_answered([&name, this] { - auto m = pimpl->mailboxes_.try_emplace(name, nullptr); - if (m.second) { - m.first->second = new kernel::activity::MailboxImpl(name); - XBT_DEBUG("Creating a mailbox at %p with name %s", m.first->second, name.c_str()); + auto [m, inserted] = pimpl->mailboxes_.try_emplace(name, nullptr); + if (inserted) { + m->second = new kernel::activity::MailboxImpl(name); + XBT_DEBUG("Creating a mailbox at %p with name %s", m->second, name.c_str()); } - return m.first->second; + return m->second; }); return mbox->get_iface(); } @@ -317,8 +317,8 @@ size_t Engine::get_actor_count() const std::vector Engine::get_all_actors() const { std::vector actor_list; - for (auto const& kv : pimpl->get_actor_list()) { - actor_list.push_back(kv.second->get_iface()); + for (auto const& [_, actor] : pimpl->get_actor_list()) { + actor_list.push_back(actor->get_iface()); } return actor_list; } @@ -326,9 +326,9 @@ std::vector Engine::get_all_actors() const std::vector Engine::get_filtered_actors(const std::function& filter) const { std::vector actor_list; - for (auto const& kv : pimpl->get_actor_list()) { - if (filter(kv.second->get_iface())) - actor_list.push_back(kv.second->get_iface()); + for (auto const& [_, actor] : pimpl->get_actor_list()) { + if (filter(actor->get_iface())) + actor_list.push_back(actor->get_iface()); } return actor_list; } @@ -409,8 +409,8 @@ kernel::routing::NetPoint* Engine::netpoint_by_name(const std::string& name) con std::vector Engine::get_all_netpoints() const { std::vector res; - for (auto const& kv : pimpl->netpoints_) - res.push_back(kv.second); + for (auto const& [_, netpoint] : pimpl->netpoints_) + res.push_back(netpoint); return res; } diff --git a/src/s4u/s4u_Host.cpp b/src/s4u/s4u_Host.cpp index 9c0ab22d71..742cd13476 100644 --- a/src/s4u/s4u_Host.cpp +++ b/src/s4u/s4u_Host.cpp @@ -570,8 +570,8 @@ xbt_dict_t sg_host_get_properties(const_sg_host_t host) if (props == nullptr) return nullptr; - for (auto const& elm : *props) { - xbt_dict_set(as_dict, elm.first.c_str(), xbt_strdup(elm.second.c_str())); + for (auto const& [key, value] : *props) { + xbt_dict_set(as_dict, key.c_str(), xbt_strdup(value.c_str())); } return as_dict; } @@ -655,8 +655,8 @@ void sg_host_dump(const_sg_host_t host) // XBT_ATTRIB_DEPRECATED_v335 if (not props->empty()) { XBT_INFO(" - properties:"); - for (auto const& elm : *props) { - XBT_INFO(" %s->%s", elm.first.c_str(), elm.second.c_str()); + for (auto const& [key, value] : *props) { + XBT_INFO(" %s->%s", key.c_str(), value.c_str()); } } } diff --git a/src/smpi/include/smpi_file.hpp b/src/smpi/include/smpi_file.hpp index 3d1384b896..7d68971a18 100644 --- a/src/smpi/include/smpi_file.hpp +++ b/src/smpi/include/smpi_file.hpp @@ -165,13 +165,13 @@ int File::op_all(void* buf, int count, const Datatype* datatype, MPI_Status* sta } // what do I need to read ? MPI_Offset totreads = 0; - for (auto const& chunk : chunks) { - if (chunk.second < my_chunk_start) + for (auto const& [chunk_start, chunk_end] : chunks) { + if (chunk_end < my_chunk_start) continue; - else if (chunk.first > my_chunk_end) + else if (chunk_start > my_chunk_end) continue; else - totreads += (std::min(chunk.second, my_chunk_end - 1) - std::max(chunk.first, my_chunk_start)); + totreads += (std::min(chunk_end, my_chunk_end - 1) - std::max(chunk_start, my_chunk_start)); } XBT_CDEBUG(smpi_pmpi, "will have to access %lld from my chunk", totreads); diff --git a/src/smpi/include/smpi_keyvals.hpp b/src/smpi/include/smpi_keyvals.hpp index b594f09a13..66b5e2f66b 100644 --- a/src/smpi/include/smpi_keyvals.hpp +++ b/src/smpi/include/smpi_keyvals.hpp @@ -139,14 +139,13 @@ template int Keyval::attr_put(int keyval, void* attr_value){ return MPI_ERR_ARG; smpi_key_elem& elem = elem_it->second; - int flag=0; - auto p = attributes().emplace(keyval, attr_value); - if (p.second) { + if (auto [attr, inserted] = attributes().try_emplace(keyval, attr_value); inserted) { elem.refcount++; } else { - int ret = call_deleter((T*)this, elem, keyval,p.first->second,&flag); + int flag = 0; + int ret = call_deleter((T*)this, elem, keyval, attr->second, &flag); // overwrite previous value - p.first->second = attr_value; + attr->second = attr_value; if(ret!=MPI_SUCCESS) return ret; } @@ -154,12 +153,12 @@ template int Keyval::attr_put(int keyval, void* attr_value){ } template void Keyval::cleanup_attr(){ - for (auto const& it : attributes()) { - auto elem_it = T::keyvals_.find(it.first); + for (auto const& [key, value] : attributes()) { + auto elem_it = T::keyvals_.find(key); xbt_assert(elem_it != T::keyvals_.end()); smpi_key_elem& elem = elem_it->second; int flag = 0; - call_deleter((T*)this, elem, it.first, it.second, &flag); + call_deleter((T*)this, elem, key, value, &flag); elem.refcount--; if (elem.deleted && elem.refcount == 0) T::keyvals_.erase(elem_it); diff --git a/src/smpi/internals/instr_smpi.cpp b/src/smpi/internals/instr_smpi.cpp index 29beff2dfa..36f00c709c 100644 --- a/src/smpi/internals/instr_smpi.cpp +++ b/src/smpi/internals/instr_smpi.cpp @@ -5,9 +5,6 @@ #include "private.hpp" #include -#include -#include -#include #include #include #include @@ -89,9 +86,9 @@ static const char* instr_find_color(const char* c_state) if (smpi_colors.find(state) != smpi_colors.end()) { // Exact match in the map? return smpi_colors.find(state)->second.c_str(); } - for (const auto& pair : smpi_colors) { // Is an entry of our map a substring of this state name? - if (std::strstr(state.c_str(), pair.first.c_str()) != nullptr) - return pair.second.c_str(); + for (const auto& [smpi_state, color] : smpi_colors) { // Is an entry of our map a substring of this state name? + if (state.find(smpi_state) != std::string::npos) + return color.c_str(); } return "0.5 0.5 0.5"; // Just in case we find nothing in the map ... @@ -170,12 +167,12 @@ void TRACE_smpi_init(aid_t pid, const std::string& calling_func) const simgrid::instr::Container* container = smpi_container(pid); papi_counter_t counters = smpi_process()->papi_counters(); - for (auto const& it : counters) { + for (auto const& [counter, _] : counters) { /** * Check whether this variable already exists or not. Otherwise, it will be created * multiple times but only the last one would be used... */ - container->get_type()->by_name_or_create(it.first, ""); + container->get_type()->by_name_or_create(counter, ""); } #endif } diff --git a/src/smpi/internals/smpi_bench.cpp b/src/smpi/internals/smpi_bench.cpp index 6da2855adf..096049520e 100644 --- a/src/smpi/internals/smpi_bench.cpp +++ b/src/smpi/internals/smpi_bench.cpp @@ -153,8 +153,8 @@ void smpi_bench_end() simgrid::instr::Container::by_name(std::string("rank-") + std::to_string(simgrid::s4u::this_actor::get_pid())); const papi_counter_t& counter_data = smpi_process()->papi_counters(); - for (auto const& pair : counter_data) { - container->get_variable(pair.first)->set_event(simgrid::s4u::Engine::get_clock(), pair.second); + for (auto const& [counter, value] : counter_data) { + container->get_variable(counter)->set_event(simgrid::s4u::Engine::get_clock(), value); } } #endif @@ -312,22 +312,23 @@ void smpi_sample_1(int global, const char *file, const char *tag, int iters, dou smpi_process()->set_sampling(1); } - auto insert = samples.try_emplace(loc, LocalData{ - threshold, // threshold - 0.0, // relstderr - 0.0, // mean - 0.0, // sum - 0.0, // sum_pow2 - iters, // iters - 0, // count - true // benching (if we have no data, we need at least one) - }); - if (insert.second) { + auto [sample, inserted] = samples.try_emplace(loc, + LocalData{ + threshold, // threshold + 0.0, // relstderr + 0.0, // mean + 0.0, // sum + 0.0, // sum_pow2 + iters, // iters + 0, // count + true // benching (if we have no data, we need at least one) + }); + if (inserted) { XBT_DEBUG("XXXXX First time ever on benched nest %s.", loc.c_str()); xbt_assert(threshold > 0 || iters > 0, "You should provide either a positive amount of iterations to bench, or a positive maximal stderr (or both)"); } else { - LocalData& data = insert.first->second; + LocalData& data = sample->second; if (data.iters != iters || data.threshold != threshold) { XBT_ERROR("Asked to bench block %s with different settings %d, %f is not %d, %f. " "How did you manage to give two numbers at the same line??", diff --git a/src/smpi/internals/smpi_deployment.cpp b/src/smpi/internals/smpi_deployment.cpp index 921f3c0a65..18abaa6af5 100644 --- a/src/smpi/internals/smpi_deployment.cpp +++ b/src/smpi/internals/smpi_deployment.cpp @@ -93,9 +93,8 @@ MPI_Comm* smpi_deployment_comm_world(const std::string& instance_id) } void smpi_deployment_cleanup_instances(){ - for (auto const& item : smpi_instances) { - XBT_INFO("Stalling SMPI instance: %s. Do all your MPI ranks call MPI_Finalize()?", item.first.c_str()); - Instance instance = item.second; + for (auto const& [name, instance] : smpi_instances) { + XBT_INFO("Stalling SMPI instance: %s. Do all your MPI ranks call MPI_Finalize()?", name.c_str()); simgrid::smpi::Comm::destroy(instance.comm_world_); } smpi_instances.clear(); diff --git a/src/smpi/internals/smpi_global.cpp b/src/smpi/internals/smpi_global.cpp index 405d985238..a183594a21 100644 --- a/src/smpi/internals/smpi_global.cpp +++ b/src/smpi/internals/smpi_global.cpp @@ -134,14 +134,14 @@ void smpi_comm_set_copy_data_callback(void (*callback) (smx_activity_t, void*, s static void memcpy_private(void* dest, const void* src, const std::vector>& private_blocks) { - for (auto const& block : private_blocks) - memcpy((uint8_t*)dest+block.first, (uint8_t*)src+block.first, block.second-block.first); + for (auto const& [block_begin, block_end] : private_blocks) + memcpy((uint8_t*)dest + block_begin, (uint8_t*)src + block_begin, block_end - block_begin); } static void check_blocks(const std::vector>& private_blocks, size_t buff_size) { - for (auto const& block : private_blocks) - xbt_assert(block.first <= block.second && block.second <= buff_size, "Oops, bug in shared malloc."); + for (auto const& [block_begin, block_end] : private_blocks) + xbt_assert(block_begin <= block_end && block_end <= buff_size, "Oops, bug in shared malloc."); } static void smpi_cleanup_comm_after_copy(simgrid::kernel::activity::CommImpl* comm, void* buff){ diff --git a/src/smpi/internals/smpi_replay.cpp b/src/smpi/internals/smpi_replay.cpp index 491799b03b..a952b43ee5 100644 --- a/src/smpi/internals/smpi_replay.cpp +++ b/src/smpi/internals/smpi_replay.cpp @@ -118,8 +118,7 @@ public: void get_requests(std::vector& vec) const { - for (auto const& pair : store) { - auto& reqs = pair.second; + for (auto const& [_, reqs] : store) { aid_t my_proc_id = simgrid::s4u::this_actor::get_pid(); for (auto& req: reqs){ if (req != MPI_REQUEST_NULL && (req->src() == my_proc_id || req->dst() == my_proc_id)) { @@ -588,8 +587,8 @@ void WaitAllAction::kernel(simgrid::xbt::ReplayAction&) if (req != MPI_REQUEST_NULL) Request::unref(&req); - for (auto const& pair : sender_receiver) { - TRACE_smpi_recv(pair.first, pair.second, 0); + for (auto const& [src, dst] : sender_receiver) { + TRACE_smpi_recv(src, dst, 0); } TRACE_smpi_comm_out(get_pid()); } diff --git a/src/smpi/internals/smpi_shared.cpp b/src/smpi/internals/smpi_shared.cpp index aec5e05d05..086a7f9a42 100644 --- a/src/smpi/internals/smpi_shared.cpp +++ b/src/smpi/internals/smpi_shared.cpp @@ -126,9 +126,8 @@ static void *smpi_shared_malloc_local(size_t size, const char *file, int line) { void* mem; smpi_source_location loc(file, line); - auto res = allocs.try_emplace(loc); - auto data = res.first; - if (res.second) { + auto [data, inserted] = allocs.try_emplace(loc); + if (inserted) { // The new element was inserted. int fd = smpi_temp_shm_get(); data->second.fd = fd; @@ -400,9 +399,9 @@ std::vector> shift_and_frame_private_blocks(const std: size_t offset, size_t buff_size) { std::vector> result; - for (auto const& block : vec) { - auto new_block = std::make_pair(std::min(std::max((size_t)0, block.first - offset), buff_size), - std::min(std::max((size_t)0, block.second - offset), buff_size)); + for (auto const& [block_begin, block_end] : vec) { + auto new_block = std::make_pair(std::clamp(block_begin - offset, (size_t)0, buff_size), + std::clamp(block_end - offset, (size_t)0, buff_size)); if (new_block.second > 0 && new_block.first < buff_size) result.push_back(new_block); } diff --git a/src/smpi/internals/smpi_utils.cpp b/src/smpi/internals/smpi_utils.cpp index 6d3a8356e3..e4cbc80c19 100644 --- a/src/smpi/internals/smpi_utils.cpp +++ b/src/smpi/internals/smpi_utils.cpp @@ -178,25 +178,24 @@ static void print_leaked_handles() // freed at this point bool display_advice = false; std::map> count; - for (const auto& elem : handles) { - std::string key = elem.second->name(); - if ((not xbt_log_no_loc) && (not elem.second->call_location().empty())) - key += " at " + elem.second->call_location(); + for (const auto& [_, elem] : handles) { + std::string key = elem->name(); + if ((not xbt_log_no_loc) && (not elem->call_location().empty())) + key += " at " + elem->call_location(); else display_advice = true; - auto result = count.try_emplace(key, 1); - if (result.second == false) - result.first->second++; + auto& result = count.try_emplace(key, 0).first->second; + result++; } if (display_advice) XBT_WARN("To get more information (location of allocations), compile your code with -trace-call-location flag of " "smpicc/f90"); unsigned int i = 0; - for (const auto& p : count) { - if (p.second == 1) - XBT_INFO("leaked handle of type %s", p.first.c_str()); + for (const auto& [key, value] : count) { + if (value == 1) + XBT_INFO("leaked handle of type %s", key.c_str()); else - XBT_INFO("%d leaked handles of type %s", p.second, p.first.c_str()); + XBT_INFO("%d leaked handles of type %s", value, key.c_str()); i++; if (i == max) break; @@ -228,19 +227,17 @@ static void print_leaked_buffers() size_t max_size; }; std::map> leaks_aggreg; - for (const auto& elem : allocs) { + for (const auto& [_, elem] : allocs) { std::string key = "leaked allocations"; if (not xbt_log_no_loc) - key = elem.second.file + ":" + std::to_string(elem.second.line) + ": " + key; - auto result = leaks_aggreg.try_emplace(key, buff_leak{1, elem.second.size, elem.second.size, elem.second.size}); - if (result.second == false) { - result.first->second.count++; - result.first->second.total_size += elem.second.size; - if (elem.second.size > result.first->second.max_size) - result.first->second.max_size = elem.second.size; - else if (elem.second.size < result.first->second.min_size) - result.first->second.min_size = elem.second.size; - } + key = elem.file + ":" + std::to_string(elem.line) + ": " + key; + auto& result = leaks_aggreg.try_emplace(key, buff_leak{0, 0, elem.size, elem.size}).first->second; + result.count++; + result.total_size += elem.size; + if (elem.size > result.max_size) + result.max_size = elem.size; + else if (elem.size < result.min_size) + result.min_size = elem.size; } // now we can order by total size. std::vector> leaks(leaks_aggreg.begin(), leaks_aggreg.end()); @@ -248,13 +245,13 @@ static void print_leaked_buffers() [](auto const& a, auto const& b) { return a.second.total_size > b.second.total_size; }); unsigned int i = 0; - for (const auto& p : leaks) { - if (p.second.min_size == p.second.max_size) - XBT_INFO("%s of total size %zu, called %d times, each with size %zu", p.first.c_str(), p.second.total_size, - p.second.count, p.second.min_size); + for (const auto& [key, value] : leaks) { + if (value.min_size == value.max_size) + XBT_INFO("%s of total size %zu, called %d times, each with size %zu", key.c_str(), value.total_size, value.count, + value.min_size); else - XBT_INFO("%s of total size %zu, called %d times, with minimum size %zu and maximum size %zu", p.first.c_str(), - p.second.total_size, p.second.count, p.second.min_size, p.second.max_size); + XBT_INFO("%s of total size %zu, called %d times, with minimum size %zu and maximum size %zu", key.c_str(), + value.total_size, value.count, value.min_size, value.max_size); i++; if (i == max) break; diff --git a/src/smpi/mpi/smpi_comm.cpp b/src/smpi/mpi/smpi_comm.cpp index c1800eb985..117f08f7c9 100644 --- a/src/smpi/mpi/smpi_comm.cpp +++ b/src/smpi/mpi/smpi_comm.cpp @@ -79,27 +79,27 @@ int Comm::dup(MPI_Comm* newcomm){ auto* cp = new Group(this->group()); (*newcomm) = new Comm(cp, this->topo()); - for (auto const& it : attributes()) { - auto elem_it = keyvals_.find(it.first); - xbt_assert(elem_it != keyvals_.end(), "Keyval not found for Comm: %d", it.first); + for (auto const& [key, value] : attributes()) { + auto elem_it = keyvals_.find(key); + xbt_assert(elem_it != keyvals_.end(), "Keyval not found for Comm: %d", key); smpi_key_elem& elem = elem_it->second; int ret = MPI_SUCCESS; int flag = 0; void* value_out = nullptr; if (elem.copy_fn.comm_copy_fn == MPI_COMM_DUP_FN) { - value_out = it.second; + value_out = value; flag = 1; } else if (elem.copy_fn.comm_copy_fn != MPI_NULL_COPY_FN) { - ret = elem.copy_fn.comm_copy_fn(this, it.first, elem.extra_state, it.second, &value_out, &flag); + ret = elem.copy_fn.comm_copy_fn(this, key, elem.extra_state, value, &value_out, &flag); } if (elem.copy_fn.comm_copy_fn_fort != MPI_NULL_COPY_FN) { value_out = xbt_new(int, 1); if (*(int*)*elem.copy_fn.comm_copy_fn_fort == 1) { // MPI_COMM_DUP_FN - memcpy(value_out, it.second, sizeof(int)); + memcpy(value_out, value, sizeof(int)); flag = 1; } else { // not null, nor dup - elem.copy_fn.comm_copy_fn_fort(this, it.first, elem.extra_state, it.second, value_out, &flag, &ret); + elem.copy_fn.comm_copy_fn_fort(this, key, elem.extra_state, value, value_out, &flag, &ret); } if (ret != MPI_SUCCESS) xbt_free(value_out); @@ -111,7 +111,7 @@ int Comm::dup(MPI_Comm* newcomm){ } if (flag) { elem.refcount++; - (*newcomm)->attributes().emplace(it.first, value_out); + (*newcomm)->attributes().try_emplace(key, value_out); } } //duplicate info if present @@ -304,10 +304,10 @@ MPI_Comm Comm::split(int color, int key) } std::vector requests(rankmap.size()); int reqs = 0; - for (auto const& rank : rankmap) { - if (rank.second != 0) { + for (auto const& [_, rank] : rankmap) { + if (rank != 0) { group_snd[reqs]=new Group(group_out); - requests[reqs] = Request::isend(&(group_snd[reqs]), 1, MPI_PTR, rank.second, system_tag, this); + requests[reqs] = Request::isend(&(group_snd[reqs]), 1, MPI_PTR, rank, system_tag, this); reqs++; } } diff --git a/src/smpi/mpi/smpi_datatype.cpp b/src/smpi/mpi/smpi_datatype.cpp index d9bf6de67f..3be3ace0be 100644 --- a/src/smpi/mpi/smpi_datatype.cpp +++ b/src/smpi/mpi/smpi_datatype.cpp @@ -166,19 +166,19 @@ int Datatype::copy_attrs(Datatype* datatype){ flags_ &= ~DT_FLAG_PREDEFINED; set_contents(MPI_COMBINER_DUP, 0, nullptr, 0, nullptr, 1, &datatype); - for (auto const& it : datatype->attributes()) { - auto elem_it = keyvals_.find(it.first); - xbt_assert(elem_it != keyvals_.end(), "Keyval not found for Datatype: %d", it.first); + for (auto const& [key, value] : datatype->attributes()) { + auto elem_it = keyvals_.find(key); + xbt_assert(elem_it != keyvals_.end(), "Keyval not found for Datatype: %d", key); smpi_key_elem& elem = elem_it->second; int ret = MPI_SUCCESS; int flag = 0; void* value_out = nullptr; if (elem.copy_fn.type_copy_fn == MPI_TYPE_DUP_FN) { - value_out = it.second; + value_out = value; flag = 1; } else if (elem.copy_fn.type_copy_fn != MPI_NULL_COPY_FN) { - ret = elem.copy_fn.type_copy_fn(datatype, it.first, elem.extra_state, it.second, &value_out, &flag); + ret = elem.copy_fn.type_copy_fn(datatype, key, elem.extra_state, value, &value_out, &flag); } if (ret != MPI_SUCCESS) return ret; @@ -186,10 +186,10 @@ int Datatype::copy_attrs(Datatype* datatype){ if (elem.copy_fn.type_copy_fn_fort != MPI_NULL_COPY_FN) { value_out = xbt_new(int, 1); if (*(int*)*elem.copy_fn.type_copy_fn_fort == 1) { // MPI_TYPE_DUP_FN - memcpy(value_out, it.second, sizeof(int)); + memcpy(value_out, value, sizeof(int)); flag = 1; } else { // not null, nor dup - elem.copy_fn.type_copy_fn_fort(datatype, it.first, elem.extra_state, it.second, value_out, &flag, &ret); + elem.copy_fn.type_copy_fn_fort(datatype, key, elem.extra_state, value, value_out, &flag, &ret); } if (ret != MPI_SUCCESS) { xbt_free(value_out); @@ -198,7 +198,7 @@ int Datatype::copy_attrs(Datatype* datatype){ } if (flag) { elem.refcount++; - attributes().emplace(it.first, value_out); + attributes().try_emplace(key, value_out); } } return MPI_SUCCESS; diff --git a/src/smpi/mpi/smpi_info.cpp b/src/smpi/mpi/smpi_info.cpp index 9dbfa70f2a..b969e2a77a 100644 --- a/src/smpi/mpi/smpi_info.cpp +++ b/src/smpi/mpi/smpi_info.cpp @@ -61,9 +61,9 @@ int Info::get_nkeys(int* nkeys) const int Info::get_nthkey(int n, char* key) const { int num=0; - for (auto const& elm : map_) { + for (auto const& [elm, _] : map_) { if (num == n) { - strncpy(key, elm.first.c_str(), elm.first.length() + 1); + strncpy(key, elm.c_str(), elm.length() + 1); return MPI_SUCCESS; } num++; diff --git a/src/surf/HostImpl.cpp b/src/surf/HostImpl.cpp index ad435f4528..7f1e1022a1 100644 --- a/src/surf/HostImpl.cpp +++ b/src/surf/HostImpl.cpp @@ -53,11 +53,11 @@ HostImpl::~HostImpl() delete arg; actors_at_boot_.clear(); - for (auto const& d : disks_) - d.second->destroy(); + for (auto const& [_, d] : disks_) + d->destroy(); - for (auto const& vm : vms_) - vm.second->vm_destroy(); + for (auto const& [_, vm] : vms_) + vm->vm_destroy(); } /** @brief Fire the required callbacks and destroy the object @@ -86,10 +86,10 @@ void HostImpl::turn_on() const void HostImpl::turn_off(const actor::ActorImpl* issuer) { /* turn_off VMs running on host */ - for (const auto& kv : vms_) { + for (const auto& [_, vm] : vms_) { // call s4u functions to generate the good on_state_change signal, maybe one day this wont be necessary - kv.second->get_iface()->shutdown(); - kv.second->get_iface()->turn_off(); + vm->get_iface()->shutdown(); + vm->get_iface()->turn_off(); } for (auto& actor : actor_list_) { XBT_DEBUG("Killing Actor %s@%s on behalf of %s which turned off that host.", actor.get_cname(), @@ -138,8 +138,8 @@ size_t HostImpl::get_actor_count() const std::vector HostImpl::get_disks() const { std::vector disks; - for (auto const& d : disks_) - disks.push_back(d.second->get_iface()); + for (auto const& [_, d] : disks_) + disks.push_back(d->get_iface()); return disks; } @@ -202,8 +202,8 @@ VirtualMachineImpl* HostImpl::get_vm_by_name_or_null(const std::string& name) co std::vector HostImpl::get_vms() const { std::vector vms; - for (const auto& kv : vms_) { - vms.push_back(kv.second->get_iface()); + for (const auto& [_, vm] : vms_) { + vms.push_back(vm->get_iface()); } return vms; } @@ -235,12 +235,12 @@ void HostImpl::seal() sealed_ = true; /* seal its disks */ - for (auto const& disk : disks_) - disk.second->seal(); + for (auto const& [_, disk] : disks_) + disk->seal(); /* seal its VMs */ - for (auto const& vm : vms_) - vm.second->seal(); + for (auto const& [_, vm] : vms_) + vm->seal(); } } // namespace resource } // namespace kernel diff --git a/src/surf/network_ib.cpp b/src/surf/network_ib.cpp index 6999d57595..9c7a7eda56 100644 --- a/src/surf/network_ib.cpp +++ b/src/surf/network_ib.cpp @@ -61,11 +61,11 @@ void NetworkIBModel::IB_action_state_changed_callback(NetworkAction& action, Act { if (action.get_state() != Action::State::FINISHED) return; - auto* ibModel = static_cast(action.get_model()); - std::pair pair = ibModel->active_comms[&action]; + auto* ibModel = static_cast(action.get_model()); + auto [src, dst] = ibModel->active_comms[&action]; XBT_DEBUG("IB callback - action %p finished", &action); - ibModel->update_IB_factors(&action, pair.first, pair.second, 1); + ibModel->update_IB_factors(&action, src, dst, 1); ibModel->active_comms.erase(&action); } @@ -165,9 +165,9 @@ void NetworkIBModel::update_IB_factors_rec(IBNode* root, std::vector& upda if (not updatedlist[comm->destination->id_]) update_IB_factors_rec(comm->destination, updatedlist); } - for (std::map::value_type const& comm : root->active_comms_down_) { - if (not updatedlist[comm.first->id_]) - update_IB_factors_rec(comm.first, updatedlist); + for (auto const& [comm, _] : root->active_comms_down_) { + if (not updatedlist[comm->id_]) + update_IB_factors_rec(comm, updatedlist); } } } diff --git a/src/surf/network_ns3.cpp b/src/surf/network_ns3.cpp index a02a956300..26bb1901f0 100644 --- a/src/surf/network_ns3.cpp +++ b/src/surf/network_ns3.cpp @@ -412,10 +412,7 @@ void NetworkNS3Model::update_actions_state(double now, double delta) { static std::vector socket_to_destroy; - std::string ns3_socket; - for (const auto& elm : flow_from_sock) { - ns3_socket = elm.first; - SgFlow* sgFlow = elm.second; + for (const auto& [ns3_socket, sgFlow] : flow_from_sock) { NetworkNS3Action* action = sgFlow->action_; XBT_DEBUG("Processing flow %p (socket %s, action %p)", sgFlow, ns3_socket.c_str(), action); // Because NS3 stops as soon as a flow is finished, the other flows that ends at the same time may remains in an @@ -451,7 +448,7 @@ void NetworkNS3Model::update_actions_state(double now, double delta) } while (not socket_to_destroy.empty()) { - ns3_socket = socket_to_destroy.back(); + std::string ns3_socket = socket_to_destroy.back(); socket_to_destroy.pop_back(); SgFlow* flow = flow_from_sock.at(ns3_socket); if (XBT_LOG_ISENABLED(res_ns3, xbt_log_priority_debug)) { diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index e6d95fd01e..f885a28e80 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -249,8 +249,8 @@ static void sg_platf_new_cluster_flat(simgrid::kernel::routing::ClusterCreationA zone->set_parent(parent); /* set properties */ - for (auto const& elm : cluster->properties) - zone->set_property(elm.first, elm.second); + for (auto const& [key, value] : cluster->properties) + zone->set_property(key, value); /* Make the backbone */ const simgrid::s4u::Link* backbone = nullptr; diff --git a/src/surf/xml/surfxml_parseplatf.cpp b/src/surf/xml/surfxml_parseplatf.cpp index a6ea4eb359..a46d4acd80 100644 --- a/src/surf/xml/surfxml_parseplatf.cpp +++ b/src/surf/xml/surfxml_parseplatf.cpp @@ -66,53 +66,53 @@ void parse_platform_file(const std::string& file) const auto engine = simgrid::s4u::Engine::get_instance(); /* connect all profiles relative to hosts */ - for (auto const& elm : trace_connect_list_host_avail) { - surf_parse_assert(traces_set_list.find(elm.first) != traces_set_list.end(), - std::string(": Trace ") + elm.first + " undefined."); - auto profile = traces_set_list.at(elm.first); + for (auto const& [trace, name] : trace_connect_list_host_avail) { + surf_parse_assert(traces_set_list.find(trace) != traces_set_list.end(), + std::string(": Trace ") + trace + " undefined."); + auto profile = traces_set_list.at(trace); - auto host = engine->host_by_name_or_null(elm.second); - surf_parse_assert(host, std::string(": Host ") + elm.second + " undefined."); + auto host = engine->host_by_name_or_null(name); + surf_parse_assert(host, std::string(": Host ") + name + " undefined."); host->set_state_profile(profile); } - for (auto const& elm : trace_connect_list_host_speed) { - surf_parse_assert(traces_set_list.find(elm.first) != traces_set_list.end(), - std::string(": Trace ") + elm.first + " undefined."); - auto profile = traces_set_list.at(elm.first); + for (auto const& [trace, name] : trace_connect_list_host_speed) { + surf_parse_assert(traces_set_list.find(trace) != traces_set_list.end(), + std::string(": Trace ") + trace + " undefined."); + auto profile = traces_set_list.at(trace); - auto host = engine->host_by_name_or_null(elm.second); - surf_parse_assert(host, std::string(": Host ") + elm.second + " undefined."); + auto host = engine->host_by_name_or_null(name); + surf_parse_assert(host, std::string(": Host ") + name + " undefined."); host->set_speed_profile(profile); } - for (auto const& elm : trace_connect_list_link_avail) { - surf_parse_assert(traces_set_list.find(elm.first) != traces_set_list.end(), - std::string(": Trace ") + elm.first + " undefined."); - auto profile = traces_set_list.at(elm.first); + for (auto const& [trace, name] : trace_connect_list_link_avail) { + surf_parse_assert(traces_set_list.find(trace) != traces_set_list.end(), + std::string(": Trace ") + trace + " undefined."); + auto profile = traces_set_list.at(trace); - auto link = engine->link_by_name_or_null(elm.second); - surf_parse_assert(link, std::string(": Link ") + elm.second + " undefined."); + auto link = engine->link_by_name_or_null(name); + surf_parse_assert(link, std::string(": Link ") + name + " undefined."); link->set_state_profile(profile); } - for (auto const& elm : trace_connect_list_link_bw) { - surf_parse_assert(traces_set_list.find(elm.first) != traces_set_list.end(), - std::string(": Trace ") + elm.first + " undefined."); - auto profile = traces_set_list.at(elm.first); + for (auto const& [trace, name] : trace_connect_list_link_bw) { + surf_parse_assert(traces_set_list.find(trace) != traces_set_list.end(), + std::string(": Trace ") + trace + " undefined."); + auto profile = traces_set_list.at(trace); - auto link = engine->link_by_name_or_null(elm.second); - surf_parse_assert(link, std::string(": Link ") + elm.second + " undefined."); + auto link = engine->link_by_name_or_null(name); + surf_parse_assert(link, std::string(": Link ") + name + " undefined."); link->set_bandwidth_profile(profile); } - for (auto const& elm : trace_connect_list_link_lat) { - surf_parse_assert(traces_set_list.find(elm.first) != traces_set_list.end(), - std::string(": Trace ") + elm.first + " undefined."); - auto profile = traces_set_list.at(elm.first); + for (auto const& [trace, name] : trace_connect_list_link_lat) { + surf_parse_assert(traces_set_list.find(trace) != traces_set_list.end(), + std::string(": Trace ") + trace + " undefined."); + auto profile = traces_set_list.at(trace); - auto link = engine->link_by_name_or_null(elm.second); - surf_parse_assert(link, std::string(": Link ") + elm.second + " undefined."); + auto link = engine->link_by_name_or_null(name); + surf_parse_assert(link, std::string(": Link ") + name + " undefined."); link->set_latency_profile(profile); } diff --git a/src/surf/xml/surfxml_sax_cb.cpp b/src/surf/xml/surfxml_sax_cb.cpp index 7b0e782a68..8e1598bf02 100644 --- a/src/surf/xml/surfxml_sax_cb.cpp +++ b/src/surf/xml/surfxml_sax_cb.cpp @@ -731,8 +731,8 @@ void ETag_surfxml_config() auto current_property_set = property_sets.back(); std::vector keys; - for (auto const& kv : current_property_set) { - keys.push_back(kv.first); + for (auto const& [key, _] : current_property_set) { + keys.push_back(key); } std::sort(keys.begin(), keys.end()); for (const std::string& key : keys) { diff --git a/src/xbt/config.cpp b/src/xbt/config.cpp index c2a5fdbb8a..0ae2bf8d5a 100644 --- a/src/xbt/config.cpp +++ b/src/xbt/config.cpp @@ -276,28 +276,25 @@ Config::Config() inline ConfigurationElement* Config::get_dict_element(const std::string& name) { - auto opt = options.find(name); - if (opt != options.end()) { + if (auto opt = options.find(name); opt != options.end()) return opt->second.get(); - } else { - auto als = aliases.find(name); - if (als != aliases.end()) { - ConfigurationElement* res = als->second; - if (warn_for_aliases) - XBT_INFO("Option %s has been renamed to %s. Consider switching.", name.c_str(), res->get_key().c_str()); - return res; - } else { - std::string msg = "Bad config key: " + name + "\n"; - std::string kebab = name; - std::replace(begin(kebab), end(kebab), '_', '-'); // convert from snake_case to kebab-case - if (options.count(kebab) > 0) - msg += "Did you mean '" + kebab + "'?\n"; - msg += "Existing config keys:\n"; - for (auto const& elm : options) - msg += " " + elm.first + ": (" + elm.second->get_type_name() + ")" + elm.second->get_string_value() + "\n"; - throw std::out_of_range(msg); - } + + if (auto als = aliases.find(name); als != aliases.end()) { + ConfigurationElement* res = als->second; + if (warn_for_aliases) + XBT_INFO("Option %s has been renamed to %s. Consider switching.", name.c_str(), res->get_key().c_str()); + return res; } + + std::string msg = "Bad config key: " + name + "\n"; + std::string kebab = name; + std::replace(begin(kebab), end(kebab), '_', '-'); // convert from snake_case to kebab-case + if (options.count(kebab) > 0) + msg += "Did you mean '" + kebab + "'?\n"; + msg += "Existing config keys:\n"; + for (auto const& [opt_name, opt] : options) + msg += " " + opt_name + ": (" + opt->get_type_name() + ")" + opt->get_string_value() + "\n"; + throw std::out_of_range(msg); } inline ConfigurationElement& Config::operator[](const std::string& name) @@ -316,17 +313,16 @@ void Config::alias(const std::string& realname, const std::string& aliasname) /** @brief Displays the declared aliases and their replacement */ void Config::show_aliases() const { - for (auto const& elm : aliases) - XBT_HELP(" %-40s %s", elm.first.c_str(), elm.second->get_key().c_str()); + for (auto const& [name, alias] : aliases) + XBT_HELP(" %-40s %s", name.c_str(), alias->get_key().c_str()); } /** @brief Displays the declared options and their description */ void Config::help() const { - for (auto const& elm : options) { - simgrid::config::ConfigurationElement* variable = elm.second.get(); - XBT_HELP(" %s: %s", elm.first.c_str(), variable->get_description().c_str()); - XBT_HELP(" Type: %s; Current value: %s", variable->get_type_name(), variable->get_string_value().c_str()); + for (auto const& [name, opt] : options) { + XBT_HELP(" %s: %s", name.c_str(), opt->get_description().c_str()); + XBT_HELP(" Type: %s; Current value: %s", opt->get_type_name(), opt->get_string_value().c_str()); } } diff --git a/src/xbt/xbt_parse_units.cpp b/src/xbt/xbt_parse_units.cpp index 60d884371f..8a8929cb57 100644 --- a/src/xbt/xbt_parse_units.cpp +++ b/src/xbt/xbt_parse_units.cpp @@ -27,11 +27,7 @@ public: unit_scale::unit_scale(std::initializer_list> generators) { - for (const auto& gen : generators) { - const std::string& unit = std::get<0>(gen); - double value = std::get<1>(gen); - const int base = std::get<2>(gen); - const bool abbrev = std::get<3>(gen); + for (auto [unit, value, base, abbrev] : generators) { double mult; std::vector prefixes; switch (base) { diff --git a/teshsuite/mc/dwarf/dwarf.cpp b/teshsuite/mc/dwarf/dwarf.cpp index 1e3f57ef6f..0a1e41e0f0 100644 --- a/teshsuite/mc/dwarf/dwarf.cpp +++ b/teshsuite/mc/dwarf/dwarf.cpp @@ -38,9 +38,9 @@ some_struct test_some_struct; static simgrid::mc::Frame* find_function_by_name( simgrid::mc::ObjectInformation* info, const char* name) { - for (auto& entry : info->subprograms) - if(entry.second.name == name) - return &entry.second; + for (auto& [_, entry] : info->subprograms) + if (entry.name == name) + return &entry; return nullptr; } diff --git a/teshsuite/platforms/flatifier.cpp b/teshsuite/platforms/flatifier.cpp index a874331cac..ad9ca31071 100644 --- a/teshsuite/platforms/flatifier.cpp +++ b/teshsuite/platforms/flatifier.cpp @@ -58,8 +58,8 @@ static void dump_hosts() } // Sort the properties before displaying them, so that the tests are perfectly reproducible std::vector keys; - for (auto const& kv : *props) - keys.push_back(kv.first); + for (auto const& [key, _] : *props) + keys.push_back(key); if (not keys.empty()) { std::printf(">\n"); std::sort(keys.begin(), keys.end()); diff --git a/teshsuite/s4u/storage_client_server/storage_client_server.cpp b/teshsuite/s4u/storage_client_server/storage_client_server.cpp index 233a0acdd0..f8ee407a0c 100644 --- a/teshsuite/s4u/storage_client_server/storage_client_server.cpp +++ b/teshsuite/s4u/storage_client_server/storage_client_server.cpp @@ -17,8 +17,8 @@ static void display_disk_properties(const simgrid::s4u::Disk* disk) if (not props->empty()) { XBT_INFO(" Properties of disk: %s", disk->get_cname()); - for (auto const& elm : *props) { - XBT_INFO(" %s->%s", elm.first.c_str(), elm.second.c_str()); + for (auto const& [key, value] : *props) { + XBT_INFO(" %s->%s", key.c_str(), value.c_str()); } } else { XBT_INFO(" No property attached."); @@ -65,8 +65,8 @@ static void display_disk_content(const simgrid::s4u::Disk* disk) XBT_INFO("Print the content of the disk: %s", disk->get_cname()); const auto* content = disk->extension()->get_content(); if (not content->empty()) { - for (auto const& entry : *content) - XBT_INFO(" %s size: %llu bytes", entry.first.c_str(), entry.second); + for (auto const& [name, size] : *content) + XBT_INFO(" %s size: %llu bytes", name.c_str(), size); } else { XBT_INFO(" No content."); }