From 65bc1aa7fa251a7381e77452d03880566b6a7e61 Mon Sep 17 00:00:00 2001 From: Alexander Voigt Date: Fri, 6 Mar 2015 14:54:26 +0100 Subject: [PATCH] use for_each instead of a loop to delete models --- src/two_scale_solver.cpp | 12 ++++++++---- src/two_scale_solver.hpp | 1 + 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/two_scale_solver.cpp b/src/two_scale_solver.cpp index 08da2b046..499d20ccc 100644 --- a/src/two_scale_solver.cpp +++ b/src/two_scale_solver.cpp @@ -25,6 +25,7 @@ #include "two_scale_running_precision.hpp" #include "logger.hpp" #include "error.hpp" +#include "functors.hpp" #include #include @@ -56,8 +57,7 @@ RGFlow::RGFlow() RGFlow::~RGFlow() { - for (size_t m = 0; m < models.size(); ++m) - delete models[m]; + delete_models(); } /** @@ -145,6 +145,11 @@ void RGFlow::clear_problems() } } +void RGFlow::delete_models() +{ + for_each(models.begin(), models.end(), Delete_object()); +} + /** * Does the initial guess by calling the guess() method of the initial * guesser (if given). @@ -431,8 +436,7 @@ unsigned int RGFlow::get_max_iterations() const */ void RGFlow::reset() { - for (size_t m = 0; m < models.size(); ++m) - delete models[m]; + delete_models(); models.clear(); iteration = 0; diff --git a/src/two_scale_solver.hpp b/src/two_scale_solver.hpp index 3b99792ac..5e722cd35 100644 --- a/src/two_scale_solver.hpp +++ b/src/two_scale_solver.hpp @@ -124,6 +124,7 @@ class RGFlow { bool accuracy_goal_reached() const; ///< check if accuracy goal is reached void check_setup() const; ///< check the setup void clear_problems(); ///< clear model problems + void delete_models(); ///< delete all models unsigned int get_max_iterations() const; ///< returns max. number of iterations void initial_guess(); ///< initial guess void run_up(); ///< run all models up