]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Remove ill-defined (and poorly documented) comparison operators for AffineConstraints... 15548/head
authorWolfgang Bangerth <bangerth@colostate.edu>
Fri, 30 Jun 2023 20:12:35 +0000 (14:12 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Fri, 30 Jun 2023 20:18:37 +0000 (14:18 -0600)
include/deal.II/lac/affine_constraints.h
include/deal.II/lac/affine_constraints.templates.h

index dc01b2cc468b437d601342da7f1b9c6bc1a38a52..973324b63ec8ab152d3a34c46d519091d77fa1fa 100644 (file)
@@ -1668,24 +1668,6 @@ public:
     ConstraintLine &
     operator=(const ConstraintLineType &other);
 
-    /**
-     * This operator is a bit weird and unintuitive: it compares the line
-     * numbers of two lines. We need this to sort the lines; in fact we could
-     * do this using a comparison predicate.  However, this way, it is easier,
-     * albeit unintuitive since two lines really have no god-given order
-     * relation.
-     */
-    bool
-    operator<(const ConstraintLine &) const;
-
-    /**
-     * This operator is likewise weird: it checks whether the line indices of
-     * the two operands are equal, irrespective of the fact that the contents
-     * of the line may be different.
-     */
-    bool
-    operator==(const ConstraintLine &) const;
-
     /**
      * Determine an estimate for the memory consumption (in bytes) of this
      * object.
index b36d462e41e310fb5e8be7dc3dfd9adeffd70dd3..da30239ef1c9ec9498d760597e4f6c3609fb755f 100644 (file)
@@ -62,26 +62,6 @@ DEAL_II_NAMESPACE_OPEN
 
 
 
-template <typename number>
-bool
-AffineConstraints<number>::ConstraintLine::operator<(
-  const ConstraintLine &a) const
-{
-  return index < a.index;
-}
-
-
-
-template <typename number>
-bool
-AffineConstraints<number>::ConstraintLine::operator==(
-  const ConstraintLine &a) const
-{
-  return index == a.index;
-}
-
-
-
 template <typename number>
 std::size_t
 AffineConstraints<number>::ConstraintLine::memory_consumption() const
@@ -218,13 +198,25 @@ namespace internal
       Utilities::MPI::this_mpi_process(mpi_communicator);
 
     // helper function
-    const auto sort_and_make_unique =
-      [](std::vector<ConstraintType> &constraints) {
-        std::sort(constraints.begin(), constraints.end());
-
-        constraints.erase(std::unique(constraints.begin(), constraints.end()),
-                          constraints.end());
-      };
+    const auto sort_and_make_unique = [](std::vector<ConstraintType>
+                                           &constraints) {
+      std::sort(
+        constraints.begin(),
+        constraints.end(),
+        [](const typename dealii::AffineConstraints<number>::ConstraintLine &l1,
+           const typename dealii::AffineConstraints<number>::ConstraintLine
+             &l2) { return l1.index < l2.index; });
+
+      constraints.erase(
+        std::unique(
+          constraints.begin(),
+          constraints.end(),
+          [](const typename dealii::AffineConstraints<number>::ConstraintLine
+               &l1,
+             const typename dealii::AffineConstraints<number>::ConstraintLine
+               &l2) { return l1.index == l2.index; }),
+        constraints.end());
+    };
 
     // 0) collect constrained indices of the current object
     IndexSet constrained_indices(locally_owned_dofs.size());
@@ -639,7 +631,11 @@ AffineConstraints<number>::close()
     return;
 
   // sort the lines
-  std::sort(lines.begin(), lines.end());
+  std::sort(lines.begin(),
+            lines.end(),
+            [](const ConstraintLine &l1, const ConstraintLine &l2) {
+              return l1.index < l2.index;
+            });
 
   // update list of pointers and give the vector a sharp size since we
   // won't modify the size any more after this point.

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.