Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use std::any_of(...).
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Tue, 27 Jun 2023 12:04:37 +0000 (14:04 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Tue, 27 Jun 2023 15:01:01 +0000 (17:01 +0200)
src/mc/api/strategy/Strategy.hpp
src/mc/transition/TransitionAny.hpp

index 5e7b492..82bc998 100644 (file)
@@ -44,9 +44,9 @@ public:
   /** Ensure at least one transition is marked as todo among the enabled ones not done.
    *  If required, it marks as todo the best transition according to the strategy. */
   void consider_best() {
-    for (auto& [_, actor] :actors_to_run_)
-          if (actor.is_todo())
-             return;
+    if (std::any_of(begin(actors_to_run_), end(actors_to_run_),
+                    [](const auto& actor) { return actor.second.is_todo(); }))
+      return;
     aid_t best_aid = best_transition(false).first;
     if (best_aid != -1)
        actors_to_run_.at(best_aid).mark_todo();
index b064811..494006b 100644 (file)
@@ -26,12 +26,10 @@ public:
   Transition* get_current_transition() const { return transitions_.at(times_considered_); }
   bool result() const
   {
-    for (Transition* transition : transitions_) {
-      CommTestTransition* tested_transition = static_cast<CommTestTransition*>(transition);
-      if (tested_transition->get_sender() != -1 and tested_transition->get_receiver() != -1)
-        return true;
-    }
-    return false;
+    return std::any_of(begin(transitions_), end(transitions_), [](const Transition* transition) {
+      const auto* tested_transition = static_cast<const CommTestTransition*>(transition);
+      return (tested_transition->get_sender() != -1 && tested_transition->get_receiver() != -1);
+    });
   }
 };