From 63e02a3aec7aa32825163dfbc8bf904681d5dba3 Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Sat, 5 Jan 2019 22:30:53 +0100 Subject: [PATCH] Use range-based for loop in include/base --- include/deal.II/base/event.h | 19 ++++--------------- include/deal.II/base/graph_coloring.h | 4 ++-- include/deal.II/base/hdf5.h | 12 ++++++------ include/deal.II/base/index_set.h | 11 ++++------- include/deal.II/base/parameter_handler.h | 8 ++++---- include/deal.II/base/partitioner.templates.h | 2 +- include/deal.II/base/path_search.h | 12 ++++-------- include/deal.II/base/patterns.h | 6 +++--- include/deal.II/base/subscriptor.h | 6 +++--- include/deal.II/base/table_handler.h | 6 ++---- 10 files changed, 33 insertions(+), 53 deletions(-) diff --git a/include/deal.II/base/event.h b/include/deal.II/base/event.h index d567c163e3..72cb7c937b 100644 --- a/include/deal.II/base/event.h +++ b/include/deal.II/base/event.h @@ -19,6 +19,7 @@ #include +#include #include #include #include @@ -177,11 +178,7 @@ namespace Algorithms { if (all_true) return true; - for (std::vector::const_iterator i = flags.begin(); i != flags.end(); - ++i) - if (*i) - return true; - return false; + return std::find(flags.begin(), flags.end(), true) != flags.end(); } @@ -209,13 +206,7 @@ namespace Algorithms // Test all flags separately // and return false if one is // not set - for (std::vector::const_iterator i = flags.begin(); - i != flags.end(); - ++i) - if (!*i) - return false; - // All flags are set - return true; + return std::find(flags.begin(), flags.end(), false) == flags.end(); } // Finally, compare each flag @@ -256,9 +247,7 @@ namespace Algorithms all_true = false; if (event.all_true) { - for (std::vector::iterator i = flags.begin(); i != flags.end(); - ++i) - *i = false; + std::fill(flags.begin(), flags.end(), false); return *this; } diff --git a/include/deal.II/base/graph_coloring.h b/include/deal.II/base/graph_coloring.h index d396e496c0..62927a301c 100644 --- a/include/deal.II/base/graph_coloring.h +++ b/include/deal.II/base/graph_coloring.h @@ -285,8 +285,8 @@ namespace GraphColoring // linked to current_vertex is already using the color j, this // color cannot be used anymore. bool unused_color(true); - for (unsigned int k = 0; k < graph[current_vertex].size(); ++k) - if (colors_used[j].count(graph[current_vertex][k]) == 1) + for (const auto adjacent_vertex : graph[current_vertex]) + if (colors_used[j].count(adjacent_vertex) == 1) { unused_color = false; break; diff --git a/include/deal.II/base/hdf5.h b/include/deal.II/base/hdf5.h index 292640535d..be38947801 100644 --- a/include/deal.II/base/hdf5.h +++ b/include/deal.II/base/hdf5.h @@ -318,7 +318,7 @@ namespace HDF5 * Constructor. @p string_name is the name of the HDF5 Object. If @p mpi is * True then MPI I/O is used. */ - HDF5Object(const std::string name, const bool mpi); + HDF5Object(const std::string &name, const bool mpi); public: /** @@ -404,11 +404,11 @@ namespace HDF5 * Create dataset. This is an internal constructor. The function * Group::create_dataset() should be used to create a dataset. */ - DataSet(const std::string & name, - const hid_t & parent_group_id, - const std::vector &dimensions, - std::shared_ptr t_type, - const bool mpi); + DataSet(const std::string & name, + const hid_t & parent_group_id, + const std::vector & dimensions, + const std::shared_ptr &t_type, + const bool mpi); public: /** diff --git a/include/deal.II/base/index_set.h b/include/deal.II/base/index_set.h index 1e2a9d3dbc..f2ec3322be 100644 --- a/include/deal.II/base/index_set.h +++ b/include/deal.II/base/index_set.h @@ -1754,10 +1754,8 @@ IndexSet::n_elements() const #ifdef DEBUG size_type s = 0; - for (std::vector::iterator range = ranges.begin(); - range != ranges.end(); - ++range) - s += (range->end - range->begin); + for (const auto &range : ranges) + s += (range.end - range.begin); Assert(s == v, ExcInternalError()); #endif @@ -1916,9 +1914,8 @@ IndexSet::fill_binary_vector(Vector &vector) const // then write ones into the elements whose indices are contained in the // index set - for (std::vector::iterator it = ranges.begin(); it != ranges.end(); - ++it) - for (size_type i = it->begin; i < it->end; ++i) + for (const auto &range : ranges) + for (size_type i = range.begin; i < range.end; ++i) vector[i] = 1; } diff --git a/include/deal.II/base/parameter_handler.h b/include/deal.II/base/parameter_handler.h index 37ecbbf354..a57d3875fc 100644 --- a/include/deal.II/base/parameter_handler.h +++ b/include/deal.II/base/parameter_handler.h @@ -2155,8 +2155,8 @@ ParameterHandler::save(Archive &ar, const unsigned int) const std::vector descriptions; - for (unsigned int j = 0; j < patterns.size(); ++j) - descriptions.push_back(patterns[j]->description()); + for (const auto &pattern : patterns) + descriptions.push_back(pattern->description()); ar &descriptions; } @@ -2176,8 +2176,8 @@ ParameterHandler::load(Archive &ar, const unsigned int) ar & descriptions; patterns.clear(); - for (unsigned int j = 0; j < descriptions.size(); ++j) - patterns.push_back(Patterns::pattern_factory(descriptions[j])); + for (const auto &description : descriptions) + patterns.push_back(Patterns::pattern_factory(description)); } diff --git a/include/deal.II/base/partitioner.templates.h b/include/deal.II/base/partitioner.templates.h index ddf531bd22..7ccedad737 100644 --- a/include/deal.II/base/partitioner.templates.h +++ b/include/deal.II/base/partitioner.templates.h @@ -238,7 +238,7 @@ namespace Utilities unsigned int offset = n_ghost_indices_in_larger_set - n_ghost_indices(); // must copy ghost data into extended ghost array - for (const auto ghost_range : ghost_indices_subset_data) + for (const auto &ghost_range : ghost_indices_subset_data) { if (offset > ghost_range.first) { diff --git a/include/deal.II/base/path_search.h b/include/deal.II/base/path_search.h index c0451162cd..32aec5acc6 100644 --- a/include/deal.II/base/path_search.h +++ b/include/deal.II/base/path_search.h @@ -265,20 +265,16 @@ PathSearch::show(StreamType &out) const { out << "DEAL_II_" << cls << "PATH=\""; bool first = true; - for (std::vector::iterator p = my_path_list.begin(); - p != my_path_list.end(); - ++p) + for (const auto &p : my_path_list) { if (!first) out << ':'; - out << *p; + out << p; first = false; } out << '"' << std::endl << " Suffixes"; - for (std::vector::iterator s = my_suffix_list.begin(); - s != my_suffix_list.end(); - ++s) - out << " \"" << *s << '"'; + for (const auto &s : my_suffix_list) + out << " \"" << s << '"'; out << std::endl; } diff --git a/include/deal.II/base/patterns.h b/include/deal.II/base/patterns.h index 9a4bcccd89..2789bf8434 100644 --- a/include/deal.II/base/patterns.h +++ b/include/deal.II/base/patterns.h @@ -1436,7 +1436,7 @@ namespace Patterns static_assert(sizeof...(ps) > 0, "The number of PatternTypes must be greater than zero!"); auto pattern_pointers = {(static_cast(&ps))...}; - for (auto p : pattern_pointers) + for (const auto p : pattern_pointers) patterns.push_back(p->clone()); } @@ -1787,8 +1787,8 @@ namespace Patterns std::vector vec(t.size()); unsigned int i = 0; - for (const auto &ti : t) - vec[i++] = Convert::to_string(ti, base_p); + for (const auto entry : t) + vec[i++] = Convert::to_string(entry, base_p); std::string s; if (vec.size() > 0) diff --git a/include/deal.II/base/subscriptor.h b/include/deal.II/base/subscriptor.h index c41b315ba3..f59d182839 100644 --- a/include/deal.II/base/subscriptor.h +++ b/include/deal.II/base/subscriptor.h @@ -304,9 +304,9 @@ Subscriptor::list_subscribers(StreamType &stream) const { std::lock_guard lock(mutex); - for (map_iterator it = counter_map.begin(); it != counter_map.end(); ++it) - stream << it->second << '/' << counter << " subscriptions from \"" - << it->first << '\"' << std::endl; + for (const auto &it : counter_map) + stream << it.second << '/' << counter << " subscriptions from \"" + << it.first << '\"' << std::endl; } DEAL_II_NAMESPACE_CLOSE diff --git a/include/deal.II/base/table_handler.h b/include/deal.II/base/table_handler.h index 42e16a1149..ba9d074242 100644 --- a/include/deal.II/base/table_handler.h +++ b/include/deal.II/base/table_handler.h @@ -912,12 +912,10 @@ TableHandler::add_value(const std::string &key, const T value) // follow the algorithm given in the introduction to this class // of padding columns as necessary unsigned int max_col_length = 0; - for (std::map::iterator p = columns.begin(); - p != columns.end(); - ++p) + for (const auto &column : columns) max_col_length = std::max(max_col_length, - static_cast(p->second.entries.size())); + static_cast(column.second.entries.size())); while (columns[key].entries.size() + 1 < max_col_length) { -- 2.39.5