From: Daniel Arndt Date: Sat, 5 Jan 2019 20:44:37 +0000 (+0100) Subject: Use range-based for loops in examples and expand_instantiations X-Git-Tag: v9.1.0-rc1~458^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c0e58f6f026e9371befc721681d989fb0bdd7f38;p=dealii.git Use range-based for loops in examples and expand_instantiations --- diff --git a/cmake/scripts/expand_instantiations.cc b/cmake/scripts/expand_instantiations.cc index 5621bac65d..069ebaa4ab 100644 --- a/cmake/scripts/expand_instantiations.cc +++ b/cmake/scripts/expand_instantiations.cc @@ -166,12 +166,12 @@ read_whole_file(std::istream &in) whole_file += remove_comments(line); whole_file += '\n'; } - // substitute tabs by spaces, multiple spaces by single ones - for (unsigned int i = 0; i < whole_file.size(); ++i) - if (whole_file[i] == '\t') - whole_file[i] = ' '; - while (whole_file.find(" ") != std::string::npos) - whole_file.replace(whole_file.find(" "), 2, " "); + // substitute tabs by spaces + std::replace(whole_file.begin(), whole_file.end(), '\t', ' '); + // substitute multiple spaces by single ones + std::size_t position = 0; + while ((position = whole_file.find(" ", position)) != std::string::npos) + whole_file.replace(position, 2, 1, ' '); return whole_file; } @@ -219,10 +219,9 @@ std::list delete_empty_entries(const std::list &list) { std::list return_list; - for (std::list::const_iterator i = list.begin(); i != list.end(); - ++i) - if (*i != "") - return_list.push_back(*i); + for (const auto &entry : list) + if (!entry.empty()) + return_list.push_back(entry); return return_list; } @@ -469,27 +468,22 @@ process_instantiations() // process the header std::list> substitutions; - for (std::list::const_iterator s = - substitutions_list.begin(); - s != substitutions_list.end(); - ++s) + for (const auto &substitution : substitutions_list) { const std::list names_and_type = - split_string_list(*s, ':'); + split_string_list(substitution, ':'); if (names_and_type.size() != 2) { - std::cerr << "Invalid instantiation header: '" << *s << "'" - << std::endl; + std::cerr << "Invalid instantiation header: '" << substitution + << "'" << std::endl; std::exit(1); } const std::list names = split_string_list(names_and_type.front(), ','); - for (std::list::const_iterator x = names.begin(); - x != names.end(); - ++x) - substitutions.emplace_back(*x, names_and_type.back()); + for (const auto &name : names) + substitutions.emplace_back(name, names_and_type.back()); } // now read the part in {...} diff --git a/examples/step-30/step-30.cc b/examples/step-30/step-30.cc index 666b2485a8..10700b9fcc 100644 --- a/examples/step-30/step-30.cc +++ b/examples/step-30/step-30.cc @@ -96,8 +96,7 @@ namespace Step30 Assert(values.size() == points.size(), ExcDimensionMismatch(values.size(), points.size())); - for (unsigned int i = 0; i < values.size(); ++i) - values[i] = 0; + std::fill(values.begin(), values.end(), 0.); }