]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Standardize on the idiom of calling std::erase after std::unique. 15417/head
authorWolfgang Bangerth <bangerth@colostate.edu>
Wed, 21 Jun 2023 15:38:25 +0000 (09:38 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Wed, 21 Jun 2023 15:41:26 +0000 (09:41 -0600)
This idiom is used in many other places. This patch changes a number of locations
where we do the same thing but instead use a different idiom, using a temporary
iterator and/or using resize() instead of erase().

include/deal.II/lac/affine_constraints.templates.h
source/base/parsed_convergence_table.cc
source/lac/sparsity_tools.cc

index f385c042842b2b5f68cb9bbec7c6b0af090e9cd5..1ad35278359e9644b4f99f4467097933ac0214b0 100644 (file)
@@ -1326,9 +1326,7 @@ AffineConstraints<number>::resolve_indices(
 
   // keep only the unique elements
   std::sort(indices.begin(), indices.end());
-  std::vector<types::global_dof_index>::iterator it;
-  it = std::unique(indices.begin(), indices.end());
-  indices.resize(it - indices.begin());
+  indices.erase(std::unique(indices.begin(), indices.end()), indices.end());
 }
 
 
index 5c4f15b8021a38cc34cc0847e3b47bbd6e14e0c1..c27523bbd76e570aa118e5ab72bda00832b3ba41 100644 (file)
@@ -26,8 +26,8 @@ namespace
   get_unique_component_names(const std::vector<std::string> &component_names)
   {
     auto elements = component_names;
-    auto last     = std::unique(elements.begin(), elements.end());
-    elements.resize(last - elements.begin());
+    elements.erase(std::unique(elements.begin(), elements.end()),
+                   elements.end());
     return elements;
   }
 
index 0d0087cb73d7c2b609ef2a091011da3829966a87..013bbfe5af8ae0f6bc6d97b6be94721ced180405 100644 (file)
@@ -641,10 +641,9 @@ namespace SparsityTools
         std::sort(next_round_dofs.begin(), next_round_dofs.end());
 
         // delete multiple entries
-        std::vector<DynamicSparsityPattern::size_type>::iterator end_sorted;
-        end_sorted =
-          std::unique(next_round_dofs.begin(), next_round_dofs.end());
-        next_round_dofs.erase(end_sorted, next_round_dofs.end());
+        next_round_dofs.erase(std::unique(next_round_dofs.begin(),
+                                          next_round_dofs.end()),
+                              next_round_dofs.end());
 
         // eliminate dofs which are already numbered
         for (int s = next_round_dofs.size() - 1; s >= 0; --s)

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.