]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Use std::optional instead of a hand-rolled version of it. 16350/head
authorWolfgang Bangerth <bangerth@colostate.edu>
Fri, 15 Dec 2023 03:28:46 +0000 (20:28 -0700)
committerWolfgang Bangerth <bangerth@colostate.edu>
Fri, 15 Dec 2023 03:28:46 +0000 (20:28 -0700)
include/deal.II/fe/fe_values_base.h
source/fe/fe_values_base.cc

index aab684d3422e5e529ccc338588e6e5940b75721b..3d56f8b895e88264aa47b465ce5aeda70dc058c0 100644 (file)
@@ -46,6 +46,7 @@
 
 #include <algorithm>
 #include <memory>
+#include <optional>
 #include <type_traits>
 
 DEAL_II_NAMESPACE_OPEN
@@ -1627,10 +1628,9 @@ protected:
                                 Vector<IndexSet::value_type> &out) const;
 
   private:
-    bool                                                 initialized;
-    typename Triangulation<dim, spacedim>::cell_iterator cell;
-    const DoFHandler<dim, spacedim>                     *dof_handler;
-    bool                                                 level_dof_access;
+    std::optional<typename Triangulation<dim, spacedim>::cell_iterator> cell;
+    const DoFHandler<dim, spacedim> *dof_handler;
+    bool                             level_dof_access;
   };
 
   /**
@@ -1789,8 +1789,7 @@ template <bool lda>
 inline FEValuesBase<dim, spacedim>::CellIteratorContainer::
   CellIteratorContainer(
     const TriaIterator<DoFCellAccessor<dim, spacedim, lda>> &cell)
-  : initialized(true)
-  , cell(cell)
+  : cell(cell)
   , dof_handler(&cell->get_dof_handler())
   , level_dof_access(lda)
 {}
index 5ef400f6c3825e4e56ca1210edfa858dea7c58ef..6120a4f9b0bc3e4b84787211012c03a06839e8f2 100644 (file)
@@ -109,8 +109,7 @@ namespace internal
 
 template <int dim, int spacedim>
 FEValuesBase<dim, spacedim>::CellIteratorContainer::CellIteratorContainer()
-  : initialized(false)
-  , cell(typename Triangulation<dim, spacedim>::cell_iterator(nullptr, -1, -1))
+  : cell()
   , dof_handler(nullptr)
   , level_dof_access(false)
 {}
@@ -120,8 +119,7 @@ FEValuesBase<dim, spacedim>::CellIteratorContainer::CellIteratorContainer()
 template <int dim, int spacedim>
 FEValuesBase<dim, spacedim>::CellIteratorContainer::CellIteratorContainer(
   const typename Triangulation<dim, spacedim>::cell_iterator &cell)
-  : initialized(true)
-  , cell(cell)
+  : cell(cell)
   , dof_handler(nullptr)
   , level_dof_access(false)
 {}
@@ -132,7 +130,7 @@ template <int dim, int spacedim>
 bool
 FEValuesBase<dim, spacedim>::CellIteratorContainer::is_initialized() const
 {
-  return initialized;
+  return cell.has_value();
 }
 
 
@@ -143,7 +141,7 @@ operator typename Triangulation<dim, spacedim>::cell_iterator() const
 {
   Assert(is_initialized(), ExcNotReinited());
 
-  return cell;
+  return cell.value();
 }
 
 
@@ -172,15 +170,15 @@ FEValuesBase<dim, spacedim>::CellIteratorContainer::get_interpolated_dof_values(
   Assert(dof_handler != nullptr, ExcNeedsDoFHandler());
 
   if (level_dof_access)
-    DoFCellAccessor<dim, spacedim, true>(&cell->get_triangulation(),
-                                         cell->level(),
-                                         cell->index(),
+    DoFCellAccessor<dim, spacedim, true>(&cell.value()->get_triangulation(),
+                                         cell.value()->level(),
+                                         cell.value()->index(),
                                          dof_handler)
       .get_interpolated_dof_values(in, out);
   else
-    DoFCellAccessor<dim, spacedim, false>(&cell->get_triangulation(),
-                                          cell->level(),
-                                          cell->index(),
+    DoFCellAccessor<dim, spacedim, false>(&cell.value()->get_triangulation(),
+                                          cell.value()->level(),
+                                          cell.value()->index(),
                                           dof_handler)
       .get_interpolated_dof_values(in, out);
 }
@@ -198,7 +196,10 @@ FEValuesBase<dim, spacedim>::CellIteratorContainer::get_interpolated_dof_values(
   Assert(level_dof_access == false, ExcNotImplemented());
 
   const DoFCellAccessor<dim, spacedim, false> cell_dofs(
-    &cell->get_triangulation(), cell->level(), cell->index(), dof_handler);
+    &cell.value()->get_triangulation(),
+    cell.value()->level(),
+    cell.value()->index(),
+    dof_handler);
 
   std::vector<types::global_dof_index> dof_indices(
     cell_dofs.get_fe().n_dofs_per_cell());

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.