]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Use range-based for loops in examples and expand_instantiations 7570/head
authorDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Sat, 5 Jan 2019 20:44:37 +0000 (21:44 +0100)
committerDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Tue, 8 Jan 2019 20:19:09 +0000 (21:19 +0100)
cmake/scripts/expand_instantiations.cc
examples/step-30/step-30.cc

index 5621bac65d27be4712b7f092b19bd1537e36e71c..069ebaa4ab52bbee6a8894b7476181a33551abe2 100644 (file)
@@ -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<std::string>
 delete_empty_entries(const std::list<std::string> &list)
 {
   std::list<std::string> return_list;
-  for (std::list<std::string>::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<std::pair<std::string, std::string>> substitutions;
 
-      for (std::list<std::string>::const_iterator s =
-             substitutions_list.begin();
-           s != substitutions_list.end();
-           ++s)
+      for (const auto &substitution : substitutions_list)
         {
           const std::list<std::string> 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<std::string> names =
             split_string_list(names_and_type.front(), ',');
 
-          for (std::list<std::string>::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 {...}
index 666b2485a8e5d5cbfa38c0a982464637778080d9..10700b9fcc6dde210083e8b55cc2d4e14c4f04f0 100644 (file)
@@ -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.);
   }
 
 

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.