Commits

Nico Schlömer committed 891e094

more range-based loops

Comments (0)

Files changed (22)

dolfin/adaptivity/Extrapolation.cpp

 
   // Iterate over given local dofs for V on patch cell
   dolfin_assert(W.element());
-  for (std::map<std::size_t, std::size_t>::iterator it = dof2row.begin();
-       it!= dof2row.end(); it++)
+  for (auto it: dof2row)
   {
-    const std::size_t i = it->first;
-    const std::size_t row = it->second;
+    const std::size_t i = it.first;
+    const std::size_t row = it.second;
 
     // Iterate over basis functions for W on center cell
     for (std::size_t j = 0; j < W.element()->space_dimension(); ++j)

dolfin/adaptivity/adapt.cpp

 
   // Use above map to construct refined markers
   std::vector<std::size_t> child_facets;
-  std::vector<std::size_t>::const_iterator it;
-  for (it = markers.begin(); it != markers.end(); ++it)
+  for (auto it: markers)
   {
-    child_facets = children[*it];
+    child_facets = children[it];
     for (std::size_t k = 0; k < child_facets.size(); k++)
       refined_markers.push_back(child_facets[k]);
   }

dolfin/fem/DofMapBuilder.cpp

 
     // Update shared_nodes for node reordering
     dofmap._shared_nodes.clear();
-    for (auto it = shared_node_to_processes0.begin();
-         it != shared_node_to_processes0.end(); ++ it)
+    for (auto it: shared_node_to_processes0)
     {
-      const int new_node = node_old_to_new_local[it->first];
-      dofmap._shared_nodes[new_node] = it->second;
+      const int new_node = node_old_to_new_local[it.first];
+      dofmap._shared_nodes[new_node] = it.second;
     }
 
     // Build dofmap from original node 'dof' map and applying the
   // Map to re-ordered dofs
   const std::vector<int>& local_to_local = parent_dofmap._ufc_local_to_local;
   const std::size_t bs = parent_dofmap.block_size;
-  for (auto cell_map = sub_dofmap._dofmap.begin();
-       cell_map != sub_dofmap._dofmap.end(); ++cell_map)
+  for (auto & cell_map: sub_dofmap._dofmap)
   {
-    for (auto dof = cell_map->begin(); dof != cell_map->end(); ++dof)
+    for (auto & dof: cell_map)
     {
-      const std::div_t  div = std::div((int) *dof, (int) local_to_local.size());
+      const std::div_t  div = std::div((int) dof, (int) local_to_local.size());
       const std::size_t node = div.rem;
       const std::size_t component = div.quot;
 
       const std::size_t current_dof = bs*local_to_local[node] + component;
 
       // Set dof index in transformed dofmap
-      *dof = current_dof;
+      dof = current_dof;
     }
   }
 }
 
    // Mark shared vertices
   std::vector<bool> vertex_shared(mesh.num_vertices(), false);
-  std::unordered_map<unsigned int, std::vector<std::pair<unsigned int,
-      unsigned int>>>::const_iterator shared_vertex;
-  for (shared_vertex = shared_vertices.begin();
-       shared_vertex != shared_vertices.end(); ++shared_vertex)
+  for (auto shared_vertex: shared_vertices)
   {
-    dolfin_assert(shared_vertex->first < vertex_shared.size());
-    vertex_shared[shared_vertex->first] = true;
+    dolfin_assert(shared_vertex.first < vertex_shared.size());
+    vertex_shared[shared_vertex.first] = true;
   }
 
   // Mark slave vertices
   std::vector<bool> slave_vertex(mesh.num_vertices(), false);
-  std::map<unsigned int, std::pair<unsigned int,
-                                   unsigned int>>::const_iterator slave;
-  for (slave = slave_to_master_vertices.begin();
-       slave != slave_to_master_vertices.end(); ++slave)
+  for (auto slave: slave_to_master_vertices)
   {
-    dolfin_assert(slave->first < slave_vertex.size());
-    slave_vertex[slave->first] = true;
+    dolfin_assert(slave.first < slave_vertex.size());
+    slave_vertex[slave.first] = true;
   }
 
   // MPI process number
         modified_vertex_indices_global[vertex->index()] = new_index;
 
         // Add to list to communicate
-        std::vector<std::pair<unsigned int, unsigned int>>::const_iterator p;
-        for (p = sharing_procs.begin(); p != sharing_procs.end(); ++p)
+        for (auto p: sharing_procs)
         {
-          dolfin_assert(p->first < new_shared_vertex_indices.size());
+          dolfin_assert(p.first < new_shared_vertex_indices.size());
 
           // Local index on remote process
-          new_shared_vertex_indices[p->first].push_back(p->second);
+          new_shared_vertex_indices[p.first].push_back(p.second);
 
           // Modified global index
-          new_shared_vertex_indices[p->first].push_back(new_index);
+          new_shared_vertex_indices[p.first].push_back(new_index);
         }
 
         new_index++;
   // Request master vertex index from master owner
   std::vector<std::vector<std::size_t>> master_send_buffer(MPI::size(mpi_comm));
   std::vector<std::vector<std::size_t>> local_slave_index(MPI::size(mpi_comm));
-  std::map<unsigned int,
-           std::pair<unsigned int, unsigned int>>::const_iterator master;
-  for (master = slave_to_master_vertices.begin();
-       master != slave_to_master_vertices.end(); ++master)
+  for (auto master: slave_to_master_vertices)
   {
-    const unsigned int local_index = master->first;
-    const unsigned int master_proc = master->second.first;
-    const unsigned int remote_master_local_index = master->second.second;
+    const unsigned int local_index = master.first;
+    const unsigned int master_proc = master.second.first;
+    const unsigned int remote_master_local_index = master.second.second;
     dolfin_assert(master_proc < local_slave_index.size());
     dolfin_assert(master_proc < master_send_buffer.size());
     local_slave_index[master_proc].push_back(local_index);
 
   // Build set of neighbouring processes
   neighbours.clear();
-  for (auto it = shared_node_to_processes.begin();
-       it != shared_node_to_processes.end(); ++it)
+  for (auto it: shared_node_to_processes)
   {
-    neighbours.insert(it->second.begin(), it->second.end());
+    neighbours.insert(it.second.begin(), it.second.end());
   }
 
   // Count number of owned nodes
 
   // Add/remove global dofs to/from relevant sets (last process owns
   // global nodes)
-  for (std::set<std::size_t>::const_iterator node = global_nodes.begin();
-       node != global_nodes.end(); ++node)
+  for (auto node: global_nodes)
   {
-    dolfin_assert(*node < node_ownership.size());
+    dolfin_assert(node < node_ownership.size());
     if (process_number == num_prococesses - 1)
-      node_ownership[*node] = 0;
+      node_ownership[node] = 0;
     else
     {
-      node_ownership[*node] = -1;
+      node_ownership[node] = -1;
       --num_owned_nodes;
     }
   }
   // Count number of locally owned nodes
   std::size_t owned_local_size = 0;
   std::size_t unowned_local_size = 0;
-  for (auto node = node_ownership.begin(); node != node_ownership.end(); ++node)
+  for (auto node: node_ownership)
   {
-    if (*node >= 0)
+    if (node >= 0)
       ++owned_local_size;
-    else if (*node == -1)
+    else if (node == -1)
       ++unowned_local_size;
     else
       error("Invalid node ownership index.");

dolfin/function/FunctionAssigner.cpp

     _assigning_indices[i].reserve(receiving_assigning_map.size());
     _receiving_indices[i].reserve(receiving_assigning_map.size());
 
-    std::map<std::size_t, std::size_t>::const_iterator it;
-    for (it = receiving_assigning_map.begin();
-         it != receiving_assigning_map.end(); ++it)
+    for (auto it: receiving_assigning_map)
     {
-      _receiving_indices[i].push_back(it->first);
-      _assigning_indices[i].push_back(it->second);
+      _receiving_indices[i].push_back(it.first);
+      _assigning_indices[i].push_back(it.second);
     }
 
     // Resize transfer vector

dolfin/function/LagrangeInterpolator.cpp

       std::vector<std::size_t> dofs = coords_to_dofs[x];
 
       // Place result in local_u_vector
-      for (std::vector<std::size_t>::const_iterator d = dofs.begin();
-           d != dofs.end(); d++)
+      for (auto d: dofs)
       {
-        dolfin_assert(*d <  local_u_vector.size());
-        local_u_vector[*d]
-          = vals[j*u0.value_size() + dof_component_map[*d]];
+        dolfin_assert(d <  local_u_vector.size());
+        local_u_vector[d]
+          = vals[j*u0.value_size() + dof_component_map[d]];
       }
     }
   }

dolfin/generation/CSGCGALMeshGenerator2D.cpp

     std::list<std::vector<Point> > v;
     cgal_geometry.get_vertices(v, threshold);
 
-    for (std::list<std::vector<Point> >::const_iterator pit = v.begin();
-         pit != v.end(); ++pit)
+    for (auto pit: v)
     {
-      std::vector<Point>::const_iterator it = pit->begin();
+      std::vector<Point>::const_iterator it = pit.begin();
       Vertex_handle first = cdt.insert(Point_2(it->x(), it->y()));
       Vertex_handle prev = first;
       ++it;
 
-      for (; it != pit->end(); ++it)
+      for (; it != pit.end(); ++it)
       {
         Vertex_handle current = cdt.insert(Point_2(it->x(), it->y()));
         cdt.insert_constraint(prev, current);
     std::list<std::vector<Point> > holes;
     cgal_geometry.get_holes(holes, threshold);
 
-    for (std::list<std::vector<Point> >::const_iterator hit = holes.begin();
-         hit != holes.end(); ++hit)
+    for (auto hit: holes)
     {
 
-      std::vector<Point>::const_iterator pit = hit->begin();
+      std::vector<Point>::const_iterator pit = hit.begin();
       Vertex_handle first = cdt.insert(Point_2(pit->x(), pit->y()));
       Vertex_handle prev = first;
       ++pit;
 
-      for(; pit != hit->end(); ++pit)
+      for(; pit != hit.end(); ++pit)
       {
         Vertex_handle current = cdt.insert(Point_2(pit->x(), pit->y()));
         cdt.insert_constraint(prev, current);
     // Iterate over array entries
     x.resize(size);
     Array<std::size_t> indices(size);
-    for (pugi::xml_node_iterator it = array.begin(); it != array.end(); ++it)
+    for (auto it: array)
     {
-      const std::size_t index = it->attribute("index").as_uint();
-      const double value = it->attribute("value").as_double();
+      const std::size_t index = it.attribute("index").as_uint();
+      const double value = it.attribute("value").as_double();
       dolfin_assert(index < size);
       indices[index] = index;
       x[index] = value;

dolfin/io/XMLFunctionData.cpp

     indices.resize(num_dofs);
 
     // Iterate over each cell entry
-    for (pugi::xml_node_iterator it = xml_function_data_node.begin();
-         it != xml_function_data_node.end(); ++it)
+    for (auto it: xml_function_data_node)
     {
-      const std::string name = it->name();
+      const std::string name = it.name();
       dolfin_assert(name == "dof");
 
-      const std::size_t global_index = it->attribute("index").as_uint();
-      const double value = it->attribute("value").as_double();
-      const std::size_t cell_index = it->attribute("cell_index").as_uint();
+      const std::size_t global_index = it.attribute("index").as_uint();
+      const double value = it.attribute("value").as_double();
+      const std::size_t cell_index = it.attribute("cell_index").as_uint();
       const std::size_t local_dof_index
-        = it->attribute("cell_dof_index").as_uint();
+        = it.attribute("cell_dof_index").as_uint();
 
       global_to_cell_dof[global_index].first = cell_index;
       global_to_cell_dof[global_index].second = local_dof_index;

dolfin/io/XMLMeshFunction.h

       // Iterate over entries (choose data type)
       if (type == "uint")
       {
-        for (pugi::xml_node_iterator it = xml_meshfunction.begin();
-             it != xml_meshfunction.end(); ++it)
+        for (auto it: xml_meshfunction)
         {
-          const std::size_t index = it->attribute("index").as_uint();
+          const std::size_t index = it.attribute("index").as_uint();
           dolfin_assert(index < size);
-          mesh_function[index] = it->attribute("value").as_uint();
+          mesh_function[index] = it.attribute("value").as_uint();
         }
       }
       else if (type == "int")
       {
-        for (pugi::xml_node_iterator it = xml_meshfunction.begin();
-             it != xml_meshfunction.end(); ++it)
+        for (auto it: xml_meshfunction)
         {
-          const std::size_t index = it->attribute("index").as_uint();
+          const std::size_t index = it.attribute("index").as_uint();
           dolfin_assert(index < size);
-          mesh_function[index] = it->attribute("value").as_int();
+          mesh_function[index] = it.attribute("value").as_int();
         }
       }
       else if (type == "double")
       {
-        for (pugi::xml_node_iterator it = xml_meshfunction.begin();
-             it != xml_meshfunction.end(); ++it)
+        for (auto it: xml_meshfunction)
         {
-          const std::size_t index = it->attribute("index").as_uint();
+          const std::size_t index = it.attribute("index").as_uint();
           dolfin_assert(index < size);
-          mesh_function[index] = it->attribute("value").as_double();
+          mesh_function[index] = it.attribute("value").as_double();
         }
       }
       else if (type == "bool")
       {
-        for (pugi::xml_node_iterator it = xml_meshfunction.begin();
-             it != xml_meshfunction.end(); ++it)
+        for (auto it: xml_meshfunction)
         {
-          const std::size_t index = it->attribute("index").as_uint();
+          const std::size_t index = it.attribute("index").as_uint();
           dolfin_assert(index < size);
-          mesh_function[index] = it->attribute("value").as_bool();
+          mesh_function[index] = it.attribute("value").as_bool();
         }
       }
       else

dolfin/io/XMLMeshValueCollection.h

     // Choose data type
     if (type == "uint")
     {
-      pugi::xml_node_iterator it;
-      for (it = mvc_node.begin(); it != mvc_node.end(); ++it)
+      for (auto it: mvc_node)
       {
-        const std::size_t cell_index = it->attribute("cell_index").as_uint();
+        const std::size_t cell_index = it.attribute("cell_index").as_uint();
         const std::size_t local_entity
-          = it->attribute("local_entity").as_uint();
-        const std::size_t value = it->attribute("value").as_uint();
+          = it.attribute("local_entity").as_uint();
+        const std::size_t value = it.attribute("value").as_uint();
         mesh_value_collection.set_value(cell_index, local_entity, value);
       }
     }
     else if (type == "int")
     {
-      pugi::xml_node_iterator it;
-      for (it = mvc_node.begin(); it != mvc_node.end(); ++it)
+      for (auto it: mvc_node)
       {
-        const std::size_t cell_index = it->attribute("cell_index").as_uint();
+        const std::size_t cell_index = it.attribute("cell_index").as_uint();
         const std::size_t local_entity
-          = it->attribute("local_entity").as_uint();
-        const int value = it->attribute("value").as_int();
+          = it.attribute("local_entity").as_uint();
+        const int value = it.attribute("value").as_int();
         mesh_value_collection.set_value(cell_index, local_entity, value);
       }
     }
     else if (type == "double")
     {
-      pugi::xml_node_iterator it;
-      for (it = mvc_node.begin(); it != mvc_node.end(); ++it)
+      for (auto it: mvc_node)
       {
-        const std::size_t cell_index = it->attribute("cell_index").as_uint();
+        const std::size_t cell_index = it.attribute("cell_index").as_uint();
         const std::size_t local_entity
-          = it->attribute("local_entity").as_uint();
-        const double value = it->attribute("value").as_double();
+          = it.attribute("local_entity").as_uint();
+        const double value = it.attribute("value").as_double();
         mesh_value_collection.set_value(cell_index, local_entity, value);
       }
     }
     else if (type == "bool")
     {
-      pugi::xml_node_iterator it;
-      for (it = mvc_node.begin(); it != mvc_node.end(); ++it)
+      for (auto it: mvc_node)
       {
-        const std::size_t cell_index = it->attribute("cell_index").as_uint();
+        const std::size_t cell_index = it.attribute("cell_index").as_uint();
         const std::size_t local_entity
-          = it->attribute("local_entity").as_uint();
-        const bool value = it->attribute("value").as_bool();
+          = it.attribute("local_entity").as_uint();
+        const bool value = it.attribute("value").as_bool();
         mesh_value_collection.set_value(cell_index, local_entity, value);
       }
     }
     // Add data
     const std::map<std::pair<std::size_t, std::size_t>, T>&
       values = mesh_value_collection.values();
-    typename std::map<std::pair<std::size_t,
-      std::size_t>, T>::const_iterator it;
-    for (it = values.begin(); it != values.end(); ++it)
+    for (auto it: values)
     {
       pugi::xml_node entity_node = mf_node.append_child("value");
       entity_node.append_attribute("cell_index")
-        = (unsigned int) it->first.first;
+        = (unsigned int) it.first.first;
       entity_node.append_attribute("local_entity")
-        = (unsigned int) it->first.second;
+        = (unsigned int) it.first.second;
       entity_node.append_attribute("value")
-        = boost::lexical_cast<std::string>(it->second).c_str();
+        = boost::lexical_cast<std::string>(it.second).c_str();
     }
   }
   //---------------------------------------------------------------------------

dolfin/io/XMLParameters.cpp

                                         const pugi::xml_node xml_node)
 {
   // Iterate over parameters
-  for (pugi::xml_node_iterator it = xml_node.begin(); it != xml_node.end(); ++it)
+  for (auto it: xml_node)
   {
     // Get name (parameters or parameter)
-    const std::string node_name = it->name();
+    const std::string node_name = it.name();
     if (node_name == "parameters")
     {
       // Get name of parameters set
-      const std::string name = it->attribute("name").value();
+      const std::string name = it.attribute("name").value();
 
       // Create parameter set if necessary
       if (!p.has_parameter_set(name))
       }
 
       // Set parameter value
-      read_parameter_nest(p(name), *it);
+      read_parameter_nest(p(name), it);
     }
     else if (node_name == "parameter")
     {
-      const std::string key = it->attribute("key").value();
-      const std::string type = it->attribute("type").value();
-      const pugi::xml_attribute value = it->attribute("value");
+      const std::string key = it.attribute("key").value();
+      const std::string type = it.attribute("type").value();
+      const pugi::xml_attribute value = it.attribute("value");
       if (type == "double")
         XMLParameters::add_parameter(p, key, value.as_double());
       else if (type == "int")

dolfin/io/XMLVector.cpp

   // Iterate over array entries
   x.resize(size);
   indices.resize(size);
-  for (pugi::xml_node_iterator it = array.begin(); it != array.end(); ++it)
+  for (auto it: array)
   {
-    const std::size_t index = it->attribute("index").as_uint();
-    const double value = it->attribute("value").as_double();
+    const std::size_t index = it.attribute("index").as_uint();
+    const double value = it.attribute("value").as_double();
     dolfin_assert(index < size);
     indices[index] = index;
     x[index] = value;

dolfin/log/Logger.cpp

 {
   // Generate timing table
   Table table("Summary of timings");
-  for (const_map_iterator it = _timings.begin(); it != _timings.end(); ++it)
+  for (auto it: _timings)
   {
-    const std::string task    = it->first;
-    const std::size_t num_timings    = it->second.first;
-    const double total_time   = it->second.second;
+    const std::string task    = it.first;
+    const std::size_t num_timings    = it.second.first;
+    const double total_time   = it.second.second;
     const double average_time = total_time / static_cast<double>(num_timings);
 
     table(task, "Average time") = average_time;

dolfin/mesh/BoundaryComputation.cpp

   MeshFunction<std::size_t>& vertex_map = boundary.entity_map(0);
   if (num_boundary_vertices > 0)
     vertex_map.init(boundary, 0, num_boundary_vertices);
-  std::map<std::size_t, std::size_t>::const_iterator it;
-  for (it = boundary_vertices.begin(); it != boundary_vertices.end(); ++it)
-    vertex_map[it->second] = it->first;
+  for (auto it: boundary_vertices)
+    vertex_map[it.second] = it.first;
 
   // Get vertex ownership distribution, and find index to start global
   // numbering from

dolfin/mesh/MeshConnectivity.h

 
       // Initialize connections
       _connections.reserve(size);
-      typename std::vector<T>::const_iterator e;
-      for (e = connections.begin(); e != connections.end(); ++e)
-        _connections.insert(_connections.end(), e->begin(), e->end());
+      for (auto e: connections)
+        _connections.insert(_connections.end(), e.begin(), e.end());
     }
 
     /// Set global number of connections for all local entities

dolfin/mesh/MeshData.cpp

     s << "  -----------------" << std::endl;
     for (std::size_t d = 0; d < _arrays.size(); ++d)
     {
-      for (a_const_iterator it = _arrays[d].begin(); it
-             != _arrays[d].end(); ++it)
+      for (auto it: _arrays[d])
       {
-        s << "  " << it->first << " ( dim = " << d
-          << ", size = " << it->second.size() << ")" << std::endl;
+        s << "  " << it.first << " ( dim = " << d
+          << ", size = " << it.second.size() << ")" << std::endl;
       }
     }
     s << std::endl;

dolfin/mesh/MeshPartitioning.h

       for (std::size_t i = 0; i < ldata.size(); ++i)
         map_of_ldata[ldata[i].first.first].insert(i);
 
-      for (entity_host = entity_hosts.begin(); entity_host != entity_hosts.end();
-           ++entity_host)
+      for (auto entity_host: entity_hosts)
       {
-        const std::size_t host_global_cell_index = entity_host->first;
+        const std::size_t host_global_cell_index = entity_host.first;
         const std::set<std::pair<std::size_t, std::size_t> >& processes_data
-          = entity_host->second;
+          = entity_host.second;
 
         // Loop over local data
         std::map<std::size_t, std::set<std::size_t> >::const_iterator ldata_it
           = map_of_ldata.find(host_global_cell_index);
         if (ldata_it != map_of_ldata.end())
         {
-          for (std::set<std::size_t>::const_iterator it = ldata_it->second.begin();
-               it != ldata_it->second.end(); it++)
+          for (auto it: ldata_it->second)
           {
-            const std::size_t local_entity_index = ldata[*it].first.second;
-            const T domain_value = ldata[*it].second;
+            const std::size_t local_entity_index = ldata[it].first.second;
+            const T domain_value = ldata[it].second;
 
-            std::set<std::pair<std::size_t, std::size_t> >::const_iterator process_data;
-            for (process_data = processes_data.begin();
-                 process_data != processes_data.end(); ++process_data)
+            for (auto process_data: processes_data)
             {
-              const std::size_t proc = process_data->first;
-              const std::size_t local_cell_entity = process_data->second;
+              const std::size_t proc = process_data.first;
+              const std::size_t local_cell_entity = process_data.second;
               send_data0[proc].push_back(local_cell_entity);
               send_data0[proc].push_back(local_entity_index);
               send_data1[proc].push_back(domain_value);

dolfin/mesh/PeriodicBoundaryComputation.cpp

   // Mark master and slaves, and pack off-process masters to send
   std::vector<std::vector<std::size_t> >
     master_dofs_send(MPI::size(mesh->mpi_comm()));
-  std::map<unsigned int,
-           std::pair<unsigned int, unsigned int> >::const_iterator slave;
-  for (slave = slaves.begin(); slave != slaves.end(); ++slave)
+  for (auto slave: slaves)
   {
     // Set slave
-    mf[slave->first] = 2;
+    mf[slave.first] = 2;
 
     // Pack master entity to send to all sharing proceses
-    dolfin_assert(slave->second.first < master_dofs_send.size());
-    master_dofs_send[slave->second.first].push_back(slave->second.second);
+    dolfin_assert(slave.second.first < master_dofs_send.size());
+    master_dofs_send[slave.second.first].push_back(slave.second.second);
   }
 
   // Send/receive master entities
   std::unordered_map<unsigned int,
 std::vector<std::pair<unsigned int, unsigned int> > >
     shared_entities_map = DistributedMeshTools::compute_shared_entities(*mesh, dim);
-  std::unordered_map<unsigned int, std::vector<std::pair<unsigned int, unsigned int> > >::const_iterator e;
   std::vector<std::vector<std::pair<unsigned int, unsigned int> > >
     shared_entities(mesh->num_entities(dim));
-  for (e = shared_entities_map.begin(); e != shared_entities_map.end(); ++e)
+  for (auto e: shared_entities_map)
   {
-    dolfin_assert(e->first < shared_entities.size());
-    shared_entities[e->first] = e->second;
+    dolfin_assert(e.first < shared_entities.size());
+    shared_entities[e.first] = e.second;
   }
 
   // Mark and pack master to send to all sharing proceses

dolfin/mesh/TetrahedronCell.cpp

   }
 
   // Add cells
-  std::vector<std::vector<std::size_t> >::const_iterator _cell;
-  for (_cell = cells.begin(); _cell != cells.end(); ++_cell)
-    editor.add_cell(current_cell++, *_cell);
+  for (auto _cell: cells)
+    editor.add_cell(current_cell++, _cell);
 }
 //-----------------------------------------------------------------------------
 void TetrahedronCell::refine_cellIrregular(Cell& cell, MeshEditor& editor,

dolfin/nls/PETScSNESSolver.cpp

 std::vector<std::pair<std::string, std::string> > PETScSNESSolver::methods()
 {
   std::vector<std::pair<std::string, std::string> > available_methods;
-  std::map<std::string, std::pair<std::string,
-                                  const SNESType> >::const_iterator it;
-  for (it = _methods.begin(); it != _methods.end(); ++it)
-    available_methods.push_back(std::make_pair(it->first, it->second.first));
+  for (auto it: _methods)
+    available_methods.push_back(std::make_pair(it.first, it.second.first));
   return available_methods;
 }
 //-----------------------------------------------------------------------------

dolfin/refinement/RegularCutRefinement.cpp

       cells[3][0] = e0; cells[3][1] = e1; cells[3][2] = e2;
 
       // Add cells
-      std::vector<std::vector<std::size_t> >::const_iterator _cell;
-      for (_cell = cells.begin(); _cell != cells.end(); ++_cell)
-        editor.add_cell(current_cell++, *_cell);
+      for (auto _cell: cells)
+        editor.add_cell(current_cell++, _cell);
     }
     else if (marker == backtrack_bisection || marker == backtrack_bisection_refine)
     {

dolfin/refinement/RivaraRefinement.cpp

 RivaraRefinement::DMesh::~DMesh()
 {
   // Delete allocated DVertices
-  for (std::list<DVertex* >::iterator it = vertices.begin();
-      it != vertices.end(); ++it)
-  {
-    delete *it;
-  }
+  for (auto & it: vertices)
+    delete it;
   // Delete allocated DCells
-  for (std::list<DCell* >::iterator it = cells.begin();
-      it != cells.end(); ++it)
-  {
-    delete *it;
-  }
+  for (auto & it: cells)
+    delete it;
 }
 //-----------------------------------------------------------------------------
 void RivaraRefinement::DMesh::import_mesh(const Mesh& mesh)
 
   // Add vertices
   std::size_t current_vertex = 0;
-  for (std::list<DVertex*>::iterator it = vertices.begin();
-        it != vertices.end(); ++it)
+  for (auto & it: vertices)
   {
-    DVertex* dv = *it;
+    DVertex* dv = it;
     editor.add_vertex(current_vertex, dv->p);
     current_vertex++;
   }
 
   std::vector<std::size_t> cell_vertices(cell_type->num_entities(0));
   std::size_t current_cell = 0;
-  for (std::list<DCell*>::iterator it = cells.begin();
-        it != cells.end(); ++it)
+  for (auto & it: cells)
   {
-    const DCell* dc = *it;
+    const DCell* dc = it;
 
     for (std::size_t j = 0; j < dc->vertices.size(); j++)
     {
 void RivaraRefinement::DMesh::number()
 {
   std::size_t i = 0;
-  for (std::list<DCell*>::iterator it = cells.begin();
-      it != cells.end(); ++it)
+  for (auto & it: cells)
   {
-    DCell* dc = *it;
+    DCell* dc = it;
     dc->id = i;
     i++;
   }
                                                            DVertex* v1,
                                                            DVertex* v2)
 {
-  for (std::list<DCell*>::iterator it = v1->cells.begin();
-      it != v1->cells.end(); ++it)
+  for (auto & it: v1->cells)
   {
-    DCell* c = *it;
+    DCell* c = it;
     if (c != dcell)
     {
       std::size_t matches = 0;
 void RivaraRefinement::DMesh::bisect_marked(std::vector<bool> marked_ids)
 {
   std::list<DCell*> marked_cells;
-  for (std::list<DCell*>::iterator it = cells.begin();
-      it != cells.end(); ++it)
+  for (auto & it: cells)
   {
-    DCell* c = *it;
+    DCell* c = it;
     if (marked_ids[c->id])
       marked_cells.push_back(c);
   }
-  for (std::list<DCell*>::iterator it = marked_cells.begin();
-      it != marked_cells.end(); ++it)
+  for (auto & it: marked_cells)
   {
-    DCell* c = *it;
+    DCell* c = it;
     if(!c->deleted)
       bisect(c, 0, 0, 0);
   }