]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Use range-based for loop in source/base
authorDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Wed, 9 Jan 2019 09:30:59 +0000 (10:30 +0100)
committerDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Fri, 18 Jan 2019 22:22:56 +0000 (23:22 +0100)
15 files changed:
source/base/exceptions.cc
source/base/flow_function.cc
source/base/function_parser.cc
source/base/index_set.cc
source/base/mpi.cc
source/base/parameter_acceptor.cc
source/base/parameter_handler.cc
source/base/parsed_function.cc
source/base/partitioner.cc
source/base/patterns.cc
source/base/polynomials_integrated_legendre_sz.cc
source/base/polynomials_piecewise.cc
source/base/quadrature.cc
source/base/subscriptor.cc
source/base/table_handler.cc

index 08d63382537b75cf4cc08f9bbf268d98f4fcdc74..412b3b008cc9ca3b7bdc0a2e30d77832270a416d 100644 (file)
@@ -87,10 +87,7 @@ ExceptionBase::ExceptionBase()
   , what_str("")
 {
 #ifdef DEAL_II_HAVE_GLIBC_STACKTRACE
-  for (unsigned int i = 0;
-       i < sizeof(raw_stacktrace) / sizeof(raw_stacktrace[0]);
-       ++i)
-    raw_stacktrace[i] = nullptr;
+  std::fill(std::begin(raw_stacktrace), std::end(raw_stacktrace), nullptr);
 #endif
 }
 
@@ -109,10 +106,7 @@ ExceptionBase::ExceptionBase(const ExceptionBase &exc)
                  // by what()
 {
 #ifdef DEAL_II_HAVE_GLIBC_STACKTRACE
-  for (unsigned int i = 0;
-       i < sizeof(raw_stacktrace) / sizeof(raw_stacktrace[0]);
-       ++i)
-    raw_stacktrace[i] = nullptr;
+  std::fill(std::begin(raw_stacktrace), std::end(raw_stacktrace), nullptr);
 #endif
 }
 
index 8dae6dc072a8039c632e50998775a9f136bd0a0d..61cfca143fe2c3eacdd0c560b314ba75e8f30cd9 100644 (file)
@@ -281,9 +281,8 @@ namespace Functions
     for (unsigned int d = 0; d < dim + 1; ++d)
       Assert(values[d].size() == n, ExcDimensionMismatch(values[d].size(), n));
 
-    for (unsigned int d = 0; d < values.size(); ++d)
-      for (unsigned int k = 0; k < values[d].size(); ++k)
-        values[d][k] = 0.;
+    for (auto &point_values : values)
+      std::fill(point_values.begin(), point_values.end(), 0.);
   }
 
   //----------------------------------------------------------------------//
@@ -437,14 +436,13 @@ namespace Functions
       {
         vector_values(points, values);
         for (unsigned int d = 0; d < dim; ++d)
-          for (unsigned int k = 0; k < values[d].size(); ++k)
-            values[d][k] *= -reaction;
+          for (double &point_value : values[d])
+            point_value *= -reaction;
       }
     else
       {
         for (unsigned int d = 0; d < dim; ++d)
-          for (unsigned int k = 0; k < values[d].size(); ++k)
-            values[d][k] = 0.;
+          std::fill(values[d].begin(), values[d].end(), 0.);
       }
 
 
@@ -658,9 +656,8 @@ namespace Functions
     for (unsigned int d = 0; d < 2 + 1; ++d)
       Assert(values[d].size() == n, ExcDimensionMismatch(values[d].size(), n));
 
-    for (unsigned int d = 0; d < values.size(); ++d)
-      for (unsigned int k = 0; k < values[d].size(); ++k)
-        values[d][k] = 0.;
+    for (auto &point_values : values)
+      std::fill(point_values.begin(), point_values.end(), 0.);
   }
 
 
@@ -771,9 +768,8 @@ namespace Functions
       }
     else
       {
-        for (unsigned int d = 0; d < values.size(); ++d)
-          for (unsigned int k = 0; k < values[d].size(); ++k)
-            values[d][k] = 0.;
+        for (auto &point_values : values)
+          std::fill(point_values.begin(), point_values.end(), 0.);
       }
   }
 
index a4446325bf5687b599f10127fccf8cbb92ab1715..174333745a2b9d1a296c67055e1e6370d4539413 100644 (file)
@@ -367,11 +367,9 @@ FunctionParser<dim>::init_muparser() const
                                           "erfc",
                                           "rand",
                                           "rand_seed"};
-          for (unsigned int f = 0;
-               f < sizeof(function_names) / sizeof(function_names[0]);
-               ++f)
+          for (const auto &function_name_c_string : function_names)
             {
-              const std::string  function_name        = function_names[f];
+              const std::string  function_name        = function_name_c_string;
               const unsigned int function_name_length = function_name.size();
 
               std::string::size_type pos = 0;
index 3702923175070af2ef96701dfe29721ee0a2b4a3..3e7f0914cf35542914fea0eb0c7c8642a1f732a7 100644 (file)
@@ -509,10 +509,9 @@ IndexSet::fill_index_vector(std::vector<size_type> &indices) const
   indices.clear();
   indices.reserve(n_elements());
 
-  for (std::vector<Range>::iterator it = ranges.begin(); it != ranges.end();
-       ++it)
-    for (size_type i = it->begin; i < it->end; ++i)
-      indices.push_back(i);
+  for (const auto &range : ranges)
+    for (size_type entry = range.begin; entry < range.end; ++entry)
+      indices.push_back(entry);
 
   Assert(indices.size() == n_elements(), ExcInternalError());
 }
index 89b0f2a174bc5f9c4d209ea6fe5304b150eee93e..d3b17463527a107539cfe763f54c8001d2bbc527 100644 (file)
@@ -189,11 +189,11 @@ namespace Utilities
       const unsigned int myid    = Utilities::MPI::this_mpi_process(mpi_comm);
       const unsigned int n_procs = Utilities::MPI::n_mpi_processes(mpi_comm);
 
-      for (unsigned int i = 0; i < destinations.size(); ++i)
+      for (const unsigned int destination : destinations)
         {
-          Assert(destinations[i] < n_procs,
-                 ExcIndexRange(destinations[i], 0, n_procs));
-          Assert(destinations[i] != myid,
+          (void)destination;
+          Assert(destination < n_procs, ExcIndexRange(destination, 0, n_procs));
+          Assert(destination != myid,
                  ExcMessage(
                    "There is no point in communicating with ourselves."));
         }
@@ -302,11 +302,11 @@ namespace Utilities
     {
       const unsigned int n_procs = Utilities::MPI::n_mpi_processes(mpi_comm);
 
-      for (unsigned int i = 0; i < destinations.size(); ++i)
+      for (const unsigned int destination : destinations)
         {
-          Assert(destinations[i] < n_procs,
-                 ExcIndexRange(destinations[i], 0, n_procs));
-          Assert(destinations[i] != Utilities::MPI::this_mpi_process(mpi_comm),
+          (void)destination;
+          Assert(destination < n_procs, ExcIndexRange(destination, 0, n_procs));
+          Assert(destination != Utilities::MPI::this_mpi_process(mpi_comm),
                  ExcMessage(
                    "There is no point in communicating with ourselves."));
         }
index cbe3d5d5cc7a5f3622e7bc5f26f40fbd163edf32..b239541c403feb5e42a35183962fd20686339690 100644 (file)
@@ -173,26 +173,26 @@ ParameterAcceptor::parse_parameters(ParameterHandler &)
 void
 ParameterAcceptor::parse_all_parameters(ParameterHandler &prm)
 {
-  for (unsigned int i = 0; i < class_list.size(); ++i)
-    if (class_list[i] != nullptr)
+  for (const auto &instance : class_list)
+    if (instance != nullptr)
       {
-        class_list[i]->enter_my_subsection(prm);
-        class_list[i]->parse_parameters(prm);
-        class_list[i]->parse_parameters_call_back();
-        class_list[i]->leave_my_subsection(prm);
+        instance->enter_my_subsection(prm);
+        instance->parse_parameters(prm);
+        instance->parse_parameters_call_back();
+        instance->leave_my_subsection(prm);
       }
 }
 
 void
 ParameterAcceptor::declare_all_parameters(ParameterHandler &prm)
 {
-  for (unsigned int i = 0; i < class_list.size(); ++i)
-    if (class_list[i] != nullptr)
+  for (const auto &instance : class_list)
+    if (instance != nullptr)
       {
-        class_list[i]->enter_my_subsection(prm);
-        class_list[i]->declare_parameters(prm);
-        class_list[i]->declare_parameters_call_back();
-        class_list[i]->leave_my_subsection(prm);
+        instance->enter_my_subsection(prm);
+        instance->declare_parameters(prm);
+        instance->declare_parameters_call_back();
+        instance->leave_my_subsection(prm);
       }
 }
 
index 839288acc091bc3ab2f82424b44e73099f63394a..68e828c745a5a1ebb2323a4016ef5b5dbddc49ad 100644 (file)
@@ -58,17 +58,15 @@ namespace
     // see if the name is special and if so mangle the whole thing
     const bool mangle_whole_string = (s == "value");
 
-    // for all parts of the string, see
-    // if it is an allowed character or
-    // not
-    for (unsigned int i = 0; i < s.size(); ++i)
+    // for all parts of the string, see if it is an allowed character or not
+    for (const char c : s)
       {
         static const std::string allowed_characters(
           "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
 
         if ((!mangle_whole_string) &&
-            (allowed_characters.find(s[i]) != std::string::npos))
-          u.push_back(s[i]);
+            (allowed_characters.find(c) != std::string::npos))
+          u.push_back(c);
         else
           {
             u.push_back('_');
@@ -88,8 +86,8 @@ namespace
                                          'd',
                                          'e',
                                          'f'};
-            u.push_back(hex[static_cast<unsigned char>(s[i]) / 16]);
-            u.push_back(hex[static_cast<unsigned char>(s[i]) % 16]);
+            u.push_back(hex[static_cast<unsigned char>(c) / 16]);
+            u.push_back(hex[static_cast<unsigned char>(c) % 16]);
           }
       }
 
@@ -986,7 +984,7 @@ ParameterHandler::set(const std::string &entry_string,
         {
           std::vector<int> action_indices = Utilities::string_to_int(
             Utilities::split_string_list(action_indices_as_string.get()));
-          for (unsigned int index : action_indices)
+          for (const unsigned int index : action_indices)
             if (actions.size() >= index + 1)
               actions[index](new_value);
         }
@@ -1195,9 +1193,9 @@ ParameterHandler::recursively_print_parameters(
                         p->second.get<std::string>("documentation"),
                         78 - overall_indent_level * 2 - 2);
 
-                    for (unsigned int i = 0; i < doc_lines.size(); ++i)
+                    for (const auto &doc_line : doc_lines)
                       out << std::setw(overall_indent_level * 2) << ""
-                          << "# " << doc_lines[i] << '\n';
+                          << "# " << doc_line << '\n';
                   }
 
 
@@ -1269,11 +1267,9 @@ ParameterHandler::recursively_print_parameters(
                     {
                       // create label: labels are not to be escaped but mangled
                       std::string label = "parameters:";
-                      for (unsigned int i = 0;
-                           i < target_subsection_path.size();
-                           ++i)
+                      for (const auto &path : target_subsection_path)
                         {
-                          label.append(mangle(target_subsection_path[i]));
+                          label.append(mangle(path));
                           label.append("/");
                         }
                       label.append(p->first);
@@ -1290,9 +1286,8 @@ ParameterHandler::recursively_print_parameters(
                     out << "\\index[prmindex]{" << escape(demangle(p->first))
                         << "}\n";
                     out << "\\index[prmindexfull]{";
-                    for (unsigned int i = 0; i < target_subsection_path.size();
-                         ++i)
-                      out << escape(target_subsection_path[i]) << "!";
+                    for (const auto &path : target_subsection_path)
+                      out << escape(path) << "!";
                     out << escape(demangle(p->first)) << "}\n";
 
                     // finally print value and default
@@ -1332,11 +1327,9 @@ ParameterHandler::recursively_print_parameters(
                     {
                       // create label: labels are not to be escaped but mangled
                       std::string label = "parameters:";
-                      for (unsigned int i = 0;
-                           i < target_subsection_path.size();
-                           ++i)
+                      for (const auto &path : target_subsection_path)
                         {
-                          label.append(mangle(target_subsection_path[i]));
+                          label.append(mangle(path));
                           label.append("/");
                         }
                       label.append(p->first);
@@ -1353,9 +1346,8 @@ ParameterHandler::recursively_print_parameters(
                     out << "\\index[prmindex]{" << escape(demangle(p->first))
                         << "}\n";
                     out << "\\index[prmindexfull]{";
-                    for (unsigned int i = 0; i < target_subsection_path.size();
-                         ++i)
-                      out << escape(target_subsection_path[i]) << "!";
+                    for (const auto &path : target_subsection_path)
+                      out << escape(path) << "!";
                     out << escape(demangle(p->first)) << "}\n";
 
                     // finally print alias and indicate if it is deprecated
@@ -1415,9 +1407,9 @@ ParameterHandler::recursively_print_parameters(
                 if (description_str.size() > 1)
                   {
                     out << '\n';
-                    for (unsigned int i = 0; i < description_str.size(); ++i)
+                    for (const auto &description : description_str)
                       out << std::setw(overall_indent_level * 2 + 6) << ""
-                          << description_str[i] << '\n';
+                          << description << '\n';
                   }
                 else if (description_str.empty() == false)
                   out << "  " << description_str[0] << '\n';
@@ -1488,14 +1480,14 @@ ParameterHandler::recursively_print_parameters(
 
                 // find the path to the current section so that we can
                 // print it in the \subsection{...} heading
-                for (unsigned int i = 0; i < target_subsection_path.size(); ++i)
-                  out << escape(target_subsection_path[i]) << "/";
+                for (const auto &path : target_subsection_path)
+                  out << escape(path) << "/";
                 out << escape(demangle(p->first));
 
                 out << "}" << '\n';
                 out << "\\label{parameters:";
-                for (unsigned int i = 0; i < target_subsection_path.size(); ++i)
-                  out << mangle(target_subsection_path[i]) << "/";
+                for (const auto &path : target_subsection_path)
+                  out << mangle(path) << "/";
                 out << p->first << "}";
                 out << '\n';
 
@@ -1619,11 +1611,10 @@ ParameterHandler::print_parameters_section(
         {
           // if there are top level elements to print, do it
           if (include_top_level_elements && (subsection_path.size() > 0))
-            for (unsigned int i = 0; i < subsection_path.size(); ++i)
+            for (const auto &path : subsection_path)
               {
                 out << std::setw(overall_indent_level * 2) << ""
-                    << "subsection " << demangle(subsection_path[i])
-                    << std::endl;
+                    << "subsection " << demangle(path) << std::endl;
                 overall_indent_level += 1;
               }
 
@@ -1682,9 +1673,9 @@ ParameterHandler::print_parameters_section(
                         p->second.get<std::string>("documentation"),
                         78 - overall_indent_level * 2 - 2);
 
-                    for (unsigned int i = 0; i < doc_lines.size(); ++i)
+                    for (const auto &doc_line : doc_lines)
                       out << std::setw(overall_indent_level * 2) << ""
-                          << "# " << doc_lines[i] << std::endl;
+                          << "# " << doc_line << std::endl;
                   }
 
 
@@ -1753,16 +1744,16 @@ ParameterHandler::print_parameters_section(
                     out << "\\item {\\it Parameter name:} {\\tt "
                         << escape(demangle(p->first)) << "}\n"
                         << "\\phantomsection\\label{parameters:";
-                    for (unsigned int i = 0; i < subsection_path.size(); ++i)
-                      out << mangle(subsection_path[i]) << "/";
+                    for (const auto &path : subsection_path)
+                      out << mangle(path) << "/";
                     out << p->first;
                     out << "}\n\n" << std::endl;
 
                     out << "\\index[prmindex]{" << escape(demangle(p->first))
                         << "}\n";
                     out << "\\index[prmindexfull]{";
-                    for (unsigned int i = 0; i < subsection_path.size(); ++i)
-                      out << escape(subsection_path[i]) << "!";
+                    for (const auto &path : subsection_path)
+                      out << escape(path) << "!";
                     out << escape(demangle(p->first)) << "}\n";
 
                     // finally print value and default
@@ -1797,16 +1788,16 @@ ParameterHandler::print_parameters_section(
                     out << "\\item {\\it Parameter name:} {\\tt "
                         << escape(demangle(p->first)) << "}\n"
                         << "\\phantomsection\\label{parameters:";
-                    for (unsigned int i = 0; i < subsection_path.size(); ++i)
-                      out << mangle(subsection_path[i]) << "/";
+                    for (const auto &path : subsection_path)
+                      out << mangle(path) << "/";
                     out << p->first;
                     out << "}\n\n" << std::endl;
 
                     out << "\\index[prmindex]{" << escape(demangle(p->first))
                         << "}\n";
                     out << "\\index[prmindexfull]{";
-                    for (unsigned int i = 0; i < subsection_path.size(); ++i)
-                      out << escape(subsection_path[i]) << "!";
+                    for (const auto &path : subsection_path)
+                      out << escape(path) << "!";
                     out << escape(demangle(p->first)) << "}\n";
 
                     // finally print alias and indicate if it is deprecated
@@ -1830,11 +1821,10 @@ ParameterHandler::print_parameters_section(
         {
           // if there are top level elements to print, do it
           if (include_top_level_elements && (subsection_path.size() > 0))
-            for (unsigned int i = 0; i < subsection_path.size(); ++i)
+            for (const auto &path : subsection_path)
               {
                 out << std::setw(overall_indent_level * 2) << ""
-                    << "subsection " << demangle(subsection_path[i])
-                    << std::endl;
+                    << "subsection " << demangle(path) << std::endl;
                 overall_indent_level += 1;
               };
 
@@ -1876,9 +1866,9 @@ ParameterHandler::print_parameters_section(
                 if (description_str.size() > 1)
                   {
                     out << std::endl;
-                    for (unsigned int i = 0; i < description_str.size(); ++i)
+                    for (const auto &description : description_str)
                       out << std::setw(overall_indent_level * 2 + 6) << ""
-                          << description_str[i] << std::endl;
+                          << description << std::endl;
                   }
                 else if (description_str.empty() == false)
                   out << "  " << description_str[0] << std::endl;
@@ -1949,14 +1939,14 @@ ParameterHandler::print_parameters_section(
 
                     // find the path to the current section so that we can
                     // print it in the \subsection{...} heading
-                    for (unsigned int i = 0; i < subsection_path.size(); ++i)
-                      out << escape(subsection_path[i]) << "/";
+                    for (const auto &path : subsection_path)
+                      out << escape(path) << "/";
                     out << escape(demangle(p->first));
 
                     out << "}" << std::endl;
                     out << "\\label{parameters:";
-                    for (unsigned int i = 0; i < subsection_path.size(); ++i)
-                      out << mangle(subsection_path[i]) << "/";
+                    for (const auto &path : subsection_path)
+                      out << mangle(path) << "/";
                     out << p->first << "}";
                     out << std::endl;
 
@@ -2212,7 +2202,7 @@ ParameterHandler::scan_line(std::string        line,
                   std::vector<int> action_indices =
                     Utilities::string_to_int(Utilities::split_string_list(
                       action_indices_as_string.get()));
-                  for (unsigned int index : action_indices)
+                  for (const unsigned int index : action_indices)
                     if (actions.size() >= index + 1)
                       actions[index](entry_value);
                 }
@@ -2352,24 +2342,24 @@ MultipleParameterLoop::init_branches()
   init_branches_current_section();
 
   // split up different values
-  for (unsigned int i = 0; i < multiple_choices.size(); ++i)
-    multiple_choices[i].split_different_values();
+  for (auto &multiple_choice : multiple_choices)
+    multiple_choice.split_different_values();
 
   // finally calculate number of branches
   n_branches = 1;
-  for (unsigned int i = 0; i < multiple_choices.size(); ++i)
-    if (multiple_choices[i].type == Entry::variant)
-      n_branches *= multiple_choices[i].different_values.size();
+  for (const auto &multiple_choice : multiple_choices)
+    if (multiple_choice.type == Entry::variant)
+      n_branches *= multiple_choice.different_values.size();
 
   // check whether array entries have the correct
   // number of entries
-  for (unsigned int i = 0; i < multiple_choices.size(); ++i)
-    if (multiple_choices[i].type == Entry::array)
-      if (multiple_choices[i].different_values.size() != n_branches)
+  for (const auto &multiple_choice : multiple_choices)
+    if (multiple_choice.type == Entry::array)
+      if (multiple_choice.different_values.size() != n_branches)
         std::cerr << "    The entry value" << std::endl
-                  << "        " << multiple_choices[i].entry_value << std::endl
+                  << "        " << multiple_choice.entry_value << std::endl
                   << "    for the entry named" << std::endl
-                  << "        " << multiple_choices[i].entry_name << std::endl
+                  << "        " << multiple_choice.entry_name << std::endl
                   << "    does not have the right number of entries for the "
                   << std::endl
                   << "        " << n_branches
@@ -2479,8 +2469,8 @@ std::size_t
 MultipleParameterLoop::memory_consumption() const
 {
   std::size_t mem = ParameterHandler::memory_consumption();
-  for (unsigned int i = 0; i < multiple_choices.size(); ++i)
-    mem += multiple_choices[i].memory_consumption();
+  for (const auto &multiple_choice : multiple_choices)
+    mem += multiple_choice.memory_consumption();
 
   return mem;
 }
index cd48668092b49fda0446c5a54858f89d32d0f9a3..edb49ed331a7b9e551856a4ade8ff4f7fa08b02c 100644 (file)
@@ -121,10 +121,10 @@ namespace Functions
     std::vector<std::string> const_list =
       Utilities::split_string_list(constants_list, ',');
     std::map<std::string, double> constants;
-    for (unsigned int i = 0; i < const_list.size(); ++i)
+    for (const auto &constant : const_list)
       {
         std::vector<std::string> this_c =
-          Utilities::split_string_list(const_list[i], '=');
+          Utilities::split_string_list(constant, '=');
         AssertThrow(this_c.size() == 2, ExcMessage("Invalid format"));
         double tmp;
         AssertThrow(std::sscanf(this_c[1].c_str(), "%lf", &tmp),
index 40a1e9cd6c015bf3583d1c1d9856fbdf0355c9a4..66498e48409adb1e11e098447775570c0b75ca75 100644 (file)
@@ -413,10 +413,10 @@ namespace Utilities
 #  ifdef DEBUG
           const types::global_dof_index n_local_dofs =
             local_range_data.second - local_range_data.first;
-          for (unsigned int i = 0; i < import_indices_data.size(); ++i)
+          for (const auto &range : import_indices_data)
             {
-              AssertIndexRange(import_indices_data[i].first, n_local_dofs);
-              AssertIndexRange(import_indices_data[i].second - 1, n_local_dofs);
+              AssertIndexRange(range.first, n_local_dofs);
+              AssertIndexRange(range.second - 1, n_local_dofs);
             }
 #  endif
         }
@@ -449,21 +449,19 @@ namespace Utilities
           // first translate tight ghost indices into indices within the large
           // set:
           std::vector<unsigned int> expanded_numbering;
-          for (IndexSet::ElementIterator it = ghost_indices_data.begin();
-               it != ghost_indices_data.end();
-               ++it)
+          for (dealii::IndexSet::size_type index : ghost_indices_data)
             {
-              Assert(larger_ghost_index_set.is_element(*it),
+              Assert(larger_ghost_index_set.is_element(index),
                      ExcMessage("The given larger ghost index set must contain"
                                 "all indices in the actual index set."));
               Assert(
-                larger_ghost_index_set.index_within_set(*it) <
+                larger_ghost_index_set.index_within_set(index) <
                   static_cast<types::global_dof_index>(
                     std::numeric_limits<unsigned int>::max()),
                 ExcMessage(
                   "Index overflow: This class supports at most 2^32-1 ghost elements"));
               expanded_numbering.push_back(
-                larger_ghost_index_set.index_within_set(*it));
+                larger_ghost_index_set.index_within_set(index));
             }
 
           // now rework expanded_numbering into ranges and store in:
index 9cc846e8238b62093583da837f9dcf4eaa31e7ab..20aebe332923bb8e6c9df27e6750c4b70406280d 100644 (file)
@@ -59,7 +59,7 @@ namespace Patterns
             {
               std::string u;
               u.reserve(input.size());
-              for (auto c : input)
+              for (const auto c : input)
                 {
                   switch (c)
                     {
@@ -866,7 +866,7 @@ namespace Patterns
         (split_list.size() > max_elements))
       return false;
 
-    for (auto &key_value_pair : split_list)
+    for (const auto &key_value_pair : split_list)
       {
         std::vector<std::string> pair =
           Utilities::split_string_list(key_value_pair, key_value_separator);
index 0733a93df2e2bfd94fa7bf2ef9f6c91ba708b819..07d5dc260e1fc8fa154a1d80d8d6ecc57d6352b6 100644 (file)
@@ -62,9 +62,9 @@ IntegratedLegendreSZ::get_coefficients(const unsigned int k)
   coefficients[k]     = b * coefficients_km1[k - 1];
   coefficients[k - 1] = b * coefficients_km1[k - 2];
 
-  for (unsigned int i = 0; i < coefficients.size(); i++)
+  for (double &coefficient : coefficients)
     {
-      coefficients[i] *= a;
+      coefficient *= a;
     }
 
   return coefficients;
index f81b90f1307323c7e544d4fcc517d8b118c7a149..122f9d2b2f5bd84c891c3edd17b3f3131b61c1fe 100644 (file)
@@ -124,8 +124,8 @@ namespace Polynomials
   {
     std::vector<Polynomial<double>> p_base =
       LagrangeEquidistant::generate_complete_basis(base_degree);
-    for (unsigned int i = 0; i < p_base.size(); ++i)
-      p_base[i].scale(n_subdivisions);
+    for (auto &polynomial : p_base)
+      polynomial.scale(n_subdivisions);
 
     std::vector<PiecewisePolynomial<double>> p;
     p.reserve(n_subdivisions * base_degree + 1);
index 64ab001f3556db0e5407bbc7fa8c42038088dbfb..4b86fb0ca9f409ae01b7385b7bed9ea8fbcf6269 100644 (file)
@@ -868,20 +868,20 @@ QProjector<3>::project_to_all_faces(const SubQuadrature &quadrature)
   // mutations of a face (mutation==0
   // corresponds to a face with standard
   // orientation, no flip and no rotation)
-  for (unsigned int mutation = 0; mutation < 8; ++mutation)
+  for (const auto &mutation : q)
     {
       // project to each face and append
       // results
       for (unsigned int face = 0; face < n_faces; ++face)
         {
-          project_to_face(q[mutation], face, help);
+          project_to_face(mutation, face, help);
           std::copy(help.begin(), help.end(), std::back_inserter(q_points));
         }
 
       // next copy over weights
       for (unsigned int face = 0; face < n_faces; ++face)
-        std::copy(q[mutation].get_weights().begin(),
-                  q[mutation].get_weights().end(),
+        std::copy(mutation.get_weights().begin(),
+                  mutation.get_weights().end(),
                   std::back_inserter(weights));
     }
 
@@ -1012,7 +1012,7 @@ QProjector<3>::project_to_all_subfaces(const SubQuadrature &quadrature)
   // mutations of a face (mutation==0
   // corresponds to a face with standard
   // orientation, no flip and no rotation)
-  for (unsigned int mutation = 0; mutation < 8; ++mutation)
+  for (const auto &mutation : q)
     {
       // project to each face and copy
       // results
@@ -1025,7 +1025,7 @@ QProjector<3>::project_to_all_subfaces(const SubQuadrature &quadrature)
                            RefinementCase<dim - 1>(ref_case));
                ++subface)
             {
-              project_to_subface(q[mutation],
+              project_to_subface(mutation,
                                  face,
                                  subface,
                                  help,
@@ -1042,8 +1042,8 @@ QProjector<3>::project_to_all_subfaces(const SubQuadrature &quadrature)
                subface < GeometryInfo<dim - 1>::n_children(
                            RefinementCase<dim - 1>(ref_case));
                ++subface)
-            std::copy(q[mutation].get_weights().begin(),
-                      q[mutation].get_weights().end(),
+            std::copy(mutation.get_weights().begin(),
+                      mutation.get_weights().end(),
                       std::back_inserter(weights));
     }
 
index 886483bb34c6ddc2e9864bef2d0ff63bc6027260..aeac2c0807dd2ae42c07dcc966b8e3ea15eb85b2 100644 (file)
@@ -52,7 +52,7 @@ Subscriptor::Subscriptor(Subscriptor &&subscriptor) noexcept
   : counter(0)
   , object_info(subscriptor.object_info)
 {
-  for (auto validity_ptr : subscriptor.validity_pointers)
+  for (const auto validity_ptr : subscriptor.validity_pointers)
     *validity_ptr = false;
 }
 
@@ -60,7 +60,7 @@ Subscriptor::Subscriptor(Subscriptor &&subscriptor) noexcept
 
 Subscriptor::~Subscriptor()
 {
-  for (auto validity_ptr : validity_pointers)
+  for (const auto validity_ptr : validity_pointers)
     *validity_ptr = false;
   object_info = nullptr;
 }
@@ -94,12 +94,11 @@ Subscriptor::check_no_subscribers() const noexcept
       if (std::uncaught_exception() == false)
         {
           std::string infostring;
-          for (map_iterator it = counter_map.begin(); it != counter_map.end();
-               ++it)
+          for (const auto &map_entry : counter_map)
             {
-              if (it->second > 0)
-                infostring +=
-                  std::string("\n  from Subscriber ") + std::string(it->first);
+              if (map_entry.second > 0)
+                infostring += std::string("\n  from Subscriber ") +
+                              std::string(map_entry.first);
             }
 
           if (infostring == "")
@@ -145,7 +144,7 @@ Subscriptor::operator=(const Subscriptor &s)
 Subscriptor &
 Subscriptor::operator=(Subscriptor &&s) noexcept
 {
-  for (auto validity_ptr : s.validity_pointers)
+  for (const auto validity_ptr : s.validity_pointers)
     *validity_ptr = false;
   object_info = s.object_info;
   return *this;
index cb0b26d9e358627b77f38254906728e5a350f80c..6ae95c51ce2d7d1cbe7e019fc53774e5b53776ac 100644 (file)
@@ -180,14 +180,12 @@ TableHandler::Column::invalidate_cache()
 {
   max_length = 0;
 
-  for (std::vector<dealii::internal::TableEntry>::iterator it = entries.begin();
-       it != entries.end();
-       ++it)
+  for (const auto &entry : entries)
     {
-      it->cache_string(this->scientific, this->precision);
+      entry.cache_string(this->scientific, this->precision);
       max_length =
         std::max(max_length,
-                 static_cast<unsigned int>(it->get_cached_string().length()));
+                 static_cast<unsigned int>(entry.get_cached_string().length()));
     }
 }
 
@@ -220,25 +218,21 @@ TableHandler::start_new_row()
 {
   // figure out the longest current column
   unsigned int max_col_length = 0;
-  for (std::map<std::string, Column>::iterator p = columns.begin();
-       p != columns.end();
-       ++p)
+  for (const auto &column : columns)
     max_col_length =
       std::max(max_col_length,
-               static_cast<unsigned int>(p->second.entries.size()));
+               static_cast<unsigned int>(column.second.entries.size()));
 
 
   // then pad all columns to that length with empty strings
-  for (std::map<std::string, Column>::iterator col = columns.begin();
-       col != columns.end();
-       ++col)
-    while (col->second.entries.size() < max_col_length)
+  for (auto &column : columns)
+    while (column.second.entries.size() < max_col_length)
       {
-        col->second.entries.emplace_back("");
-        internal::TableEntry &entry = col->second.entries.back();
-        entry.cache_string(col->second.scientific, col->second.precision);
-        col->second.max_length =
-          std::max(col->second.max_length,
+        column.second.entries.emplace_back("");
+        internal::TableEntry &entry = column.second.entries.back();
+        entry.cache_string(column.second.scientific, column.second.precision);
+        column.second.max_length =
+          std::max(column.second.max_length,
                    static_cast<unsigned int>(
                      entry.get_cached_string().length()));
       }
@@ -266,25 +260,20 @@ TableHandler::add_column_to_supercolumn(const std::string &key,
       supercolumns.insert(new_column);
       // replace key in column_order
       // by superkey
-      for (unsigned int j = 0; j < column_order.size(); ++j)
-        if (column_order[j] == key)
+      for (auto &column : column_order)
+        if (column == key)
           {
-            column_order[j] = superkey;
+            column = superkey;
             break;
           }
     }
   else
     {
       // remove key from column_order
-      // for erase we need an iterator
-      for (std::vector<std::string>::iterator order_iter = column_order.begin();
-           order_iter != column_order.end();
-           ++order_iter)
-        if (*order_iter == key)
-          {
-            column_order.erase(order_iter);
-            break;
-          }
+      const auto order_iter =
+        std::find(column_order.begin(), column_order.end(), key);
+      if (order_iter != column_order.end())
+        column_order.erase(order_iter);
     }
 
   if (supercolumns.count(superkey))
@@ -305,9 +294,12 @@ TableHandler::add_column_to_supercolumn(const std::string &key,
 void
 TableHandler::set_column_order(const std::vector<std::string> &new_order)
 {
-  for (unsigned int j = 0; j < new_order.size(); ++j)
-    Assert(supercolumns.count(new_order[j]) || columns.count(new_order[j]),
-           ExcColumnOrSuperColumnNotExistent(new_order[j]));
+  for (const auto &new_column : new_order)
+    {
+      (void)new_column;
+      Assert(supercolumns.count(new_column) || columns.count(new_column),
+             ExcColumnOrSuperColumnNotExistent(new_column));
+    }
 
   column_order = new_order;
 }
@@ -402,10 +394,8 @@ TableHandler::write_text(std::ostream &out, const TextOutputFormat format) const
            ++p)
         max_rows = std::max<unsigned int>(max_rows, p->second.entries.size());
 
-      for (std::map<std::string, Column>::iterator p = columns.begin();
-           p != columns.end();
-           ++p)
-        p->second.pad_column_below(max_rows);
+      for (auto &column : columns)
+        column.second.pad_column_below(max_rows);
     }
 
   std::vector<std::string> sel_columns;
@@ -507,10 +497,9 @@ TableHandler::write_text(std::ostream &out, const TextOutputFormat format) const
         {
           // This format output supercolumn headers and aligns them centered
           // over all the columns that belong to it.
-          for (unsigned int j = 0; j < column_order.size(); ++j)
+          for (const auto &key : column_order)
             {
-              const std::string &key   = column_order[j];
-              unsigned int       width = 0;
+              unsigned int width = 0;
               {
                 // compute the width of this column or supercolumn
                 const std::map<std::string,
@@ -632,19 +621,16 @@ TableHandler::write_tex(std::ostream &out, const bool with_header) const
            ++p)
         max_rows = std::max<unsigned int>(max_rows, p->second.entries.size());
 
-      for (std::map<std::string, Column>::iterator p = columns.begin();
-           p != columns.end();
-           ++p)
-        p->second.pad_column_below(max_rows);
+      for (auto &column : columns)
+        column.second.pad_column_below(max_rows);
     }
 
   std::vector<std::string> sel_columns;
   get_selected_columns(sel_columns);
 
   // write the column formats
-  for (unsigned int j = 0; j < column_order.size(); ++j)
+  for (const auto &key : column_order)
     {
-      std::string key = column_order[j];
       // avoid `supercolumns[key]'
       const std::map<std::string, std::vector<std::string>>::const_iterator
         super_iter = supercolumns.find(key);
@@ -783,9 +769,8 @@ TableHandler::get_selected_columns(std::vector<std::string> &sel_columns) const
 {
   sel_columns.clear();
 
-  for (unsigned int j = 0; j < column_order.size(); ++j)
+  for (const auto &key : column_order)
     {
-      std::string key = column_order[j];
       const std::map<std::string, std::vector<std::string>>::const_iterator
         super_iter = supercolumns.find(key);
 
@@ -816,18 +801,14 @@ TableHandler::clear_current_row()
   // Figure out what is the correct (max) length of the columns
   // so that we "shave" one off.
   std::vector<internal::TableEntry>::size_type n = 0;
-  for (std::map<std::string, Column>::iterator p = columns.begin();
-       p != columns.end();
-       ++p)
-    n = std::max(n, p->second.entries.size());
+  for (const auto &column : columns)
+    n = std::max(n, column.second.entries.size());
 
   // shave the top most element
   if (n != 0)
-    for (std::map<std::string, Column>::iterator p = columns.begin();
-         p != columns.end();
-         ++p)
-      if (p->second.entries.size() == n)
-        p->second.entries.pop_back();
+    for (auto &column : columns)
+      if (column.second.entries.size() == n)
+        column.second.entries.pop_back();
 }
 
 

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.