From: Gabriel Corona Date: Tue, 31 May 2016 09:29:58 +0000 (+0200) Subject: Use boost::range algorithms X-Git-Tag: v3_14~1084^2~3 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/2cee965a59bc4c1b024ddd0e10b64dc065044778 Use boost::range algorithms --- diff --git a/src/mc/LivenessChecker.cpp b/src/mc/LivenessChecker.cpp index 3853e2b4f9..e8eba86159 100644 --- a/src/mc/LivenessChecker.cpp +++ b/src/mc/LivenessChecker.cpp @@ -6,10 +6,11 @@ #include -#include #include #include +#include + #include #include @@ -124,7 +125,7 @@ std::shared_ptr LivenessChecker::insertAcceptancePair(simgrid::mc:: pair->num, pair->automaton_state, pair->atomic_propositions, pair->graph_state); - auto res = std::equal_range(acceptancePairs_.begin(), acceptancePairs_.end(), + auto res = boost::range::equal_range(acceptancePairs, new_pair.get(), simgrid::mc::DerefAndCompareByNbProcessesAndUsedHeap()); if (pair->search_cycle) for (auto i = res.first; i != res.second; ++i) { @@ -245,7 +246,7 @@ int LivenessChecker::insertVisitedPair(std::shared_ptr visited_pair pair->num, pair->automaton_state, pair->atomic_propositions, pair->graph_state); - auto range = std::equal_range(visitedPairs_.begin(), visitedPairs_.end(), + auto range = boost::range::equal_range(visitedPairs_, visited_pair.get(), simgrid::mc::DerefAndCompareByNbProcessesAndUsedHeap()); for (auto i = range.first; i != range.second; ++i) { @@ -277,8 +278,7 @@ void LivenessChecker::purgeVisitedPairs() { if (_sg_mc_visited != 0 && visitedPairs_.size() > (std::size_t) _sg_mc_visited) { // Remove the oldest entry with a linear search: - visitedPairs_.erase(std::min_element( - visitedPairs_.begin(), visitedPairs_.end(), + visitedPairs_.erase(boost::min_element(visitedPairs_, [](std::shared_ptr const a, std::shared_ptr const& b) { return a->num < b->num; } )); } diff --git a/src/mc/VisitedState.cpp b/src/mc/VisitedState.cpp index 6d0e87e7cc..3aa0e5f9ee 100644 --- a/src/mc/VisitedState.cpp +++ b/src/mc/VisitedState.cpp @@ -8,7 +8,8 @@ #include #include -#include + +#include #include #include @@ -62,7 +63,7 @@ void VisitedStates::prune() { while (states_.size() > (std::size_t) _sg_mc_visited) { XBT_DEBUG("Try to remove visited state (maximum number of stored states reached)"); - auto min_element = std::min_element(states_.begin(), states_.end(), + auto min_element = boost::range::min_element(states_, [](std::unique_ptr& a, std::unique_ptr& b) { return a->num < b->num; }); @@ -85,7 +86,7 @@ std::unique_ptr VisitedStates::addVisitedState( XBT_DEBUG("Snapshot %p of visited state %d (exploration stack state %d)", new_state->system_state.get(), new_state->num, graph_state->num); - auto range = std::equal_range(states_.begin(), states_.end(), + auto range = boost::range::equal_range(states_, new_state.get(), simgrid::mc::DerefAndCompareByNbProcessesAndUsedHeap()); if (compare_snpashots) diff --git a/src/mc/mc_base.cpp b/src/mc/mc_base.cpp index 708f3c5d4c..df068fa76f 100644 --- a/src/mc/mc_base.cpp +++ b/src/mc/mc_base.cpp @@ -6,8 +6,6 @@ #include -#include - #include #include diff --git a/src/mc/mc_dwarf.cpp b/src/mc/mc_dwarf.cpp index 30b5f38400..64b71b037a 100644 --- a/src/mc/mc_dwarf.cpp +++ b/src/mc/mc_dwarf.cpp @@ -7,10 +7,11 @@ #include #include -#include #include #include +#include + #include #include #define DW_LANG_Objc DW_LANG_ObjC /* fix spelling error in older dwarf.h */ @@ -934,8 +935,7 @@ static void MC_dwarf_handle_scope_die(simgrid::mc::ObjectInformation* info, Dwar // We sort them in order to have an (somewhat) efficient by name // lookup: - std::sort(frame.variables.begin(), frame.variables.end(), - MC_compare_variable); + boost::range::sort(frame.variables, MC_compare_variable); // Register it: if (klass == simgrid::dwarf::TagClass::Subprogram) @@ -1252,7 +1252,7 @@ static void MC_make_functions_index(simgrid::mc::ObjectInformation* info) info->functions_index.shrink_to_fit(); // Sort the array by low_pc: - std::sort(info->functions_index.begin(), info->functions_index.end(), + boost::range::sort(info->functions_index, [](simgrid::mc::FunctionIndexEntry const& a, simgrid::mc::FunctionIndexEntry const& b) { @@ -1263,8 +1263,7 @@ static void MC_make_functions_index(simgrid::mc::ObjectInformation* info) static void MC_post_process_variables(simgrid::mc::ObjectInformation* info) { // Someone needs this to be sorted but who? - std::sort(info->global_variables.begin(), info->global_variables.end(), - MC_compare_variable); + boost::range::sort(info->global_variables, MC_compare_variable); for(simgrid::mc::Variable& variable : info->global_variables) if (variable.type_id) diff --git a/src/mc/mc_state.cpp b/src/mc/mc_state.cpp index 4f467f266f..8975d96770 100644 --- a/src/mc/mc_state.cpp +++ b/src/mc/mc_state.cpp @@ -6,7 +6,7 @@ #include -#include +#include #include #include @@ -56,8 +56,8 @@ State::State() std::size_t State::interleaveSize() const { - return std::count_if(this->processStates.begin(), this->processStates.end(), - [](simgrid::mc::ProcessState const& state) { return state.isToInterleave(); }); + return boost::range::count_if(this->processStates, + simgrid::mc::ProcessState::isToInterleave), } Transition State::getTransition() const diff --git a/src/simgrid/util.hpp b/src/simgrid/util.hpp index 195070742f..03d81b8002 100644 --- a/src/simgrid/util.hpp +++ b/src/simgrid/util.hpp @@ -7,8 +7,6 @@ #ifndef SIMGRID_UTIL_HTPP #define SIMGRID_UTIL_HTPP -#include - #include namespace simgrid { diff --git a/src/surf/host_clm03.cpp b/src/surf/host_clm03.cpp index 4c9c6b8b32..e76df1daac 100644 --- a/src/surf/host_clm03.cpp +++ b/src/surf/host_clm03.cpp @@ -60,7 +60,7 @@ double HostCLM03Model::next_occuring_event(double now){ typeid(surf_network_model).name(), min_by_net, typeid(surf_storage_model).name(), min_by_sto); - double res = std::max(std::max(min_by_cpu, min_by_net), min_by_sto); + double res = std::max({min_by_cpu, min_by_net, min_by_sto}); if (min_by_cpu >= 0.0 && min_by_cpu < res) res = min_by_cpu; if (min_by_net >= 0.0 && min_by_net < res) diff --git a/src/surf/network_ib.cpp b/src/surf/network_ib.cpp index ff2211bcd6..69baee98cc 100644 --- a/src/surf/network_ib.cpp +++ b/src/surf/network_ib.cpp @@ -4,7 +4,6 @@ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ -#include #include #include "network_ib.hpp" diff --git a/src/surf/vm_hl13.cpp b/src/surf/vm_hl13.cpp index 8d54b3cfa6..e6551279b4 100644 --- a/src/surf/vm_hl13.cpp +++ b/src/surf/vm_hl13.cpp @@ -4,8 +4,6 @@ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ -#include - #include #include "cpu_cas01.hpp"