From e0c4ee8a641677e9054fb2f23be6a8fcba8c28ea Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Thu, 14 Dec 2023 20:28:46 -0700 Subject: [PATCH] Use std::optional instead of a hand-rolled version of it. --- include/deal.II/fe/fe_values_base.h | 11 +++++------ source/fe/fe_values_base.cc | 27 ++++++++++++++------------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/include/deal.II/fe/fe_values_base.h b/include/deal.II/fe/fe_values_base.h index aab684d342..3d56f8b895 100644 --- a/include/deal.II/fe/fe_values_base.h +++ b/include/deal.II/fe/fe_values_base.h @@ -46,6 +46,7 @@ #include #include +#include #include DEAL_II_NAMESPACE_OPEN @@ -1627,10 +1628,9 @@ protected: Vector &out) const; private: - bool initialized; - typename Triangulation::cell_iterator cell; - const DoFHandler *dof_handler; - bool level_dof_access; + std::optional::cell_iterator> cell; + const DoFHandler *dof_handler; + bool level_dof_access; }; /** @@ -1789,8 +1789,7 @@ template inline FEValuesBase::CellIteratorContainer:: CellIteratorContainer( const TriaIterator> &cell) - : initialized(true) - , cell(cell) + : cell(cell) , dof_handler(&cell->get_dof_handler()) , level_dof_access(lda) {} diff --git a/source/fe/fe_values_base.cc b/source/fe/fe_values_base.cc index 5ef400f6c3..6120a4f9b0 100644 --- a/source/fe/fe_values_base.cc +++ b/source/fe/fe_values_base.cc @@ -109,8 +109,7 @@ namespace internal template FEValuesBase::CellIteratorContainer::CellIteratorContainer() - : initialized(false) - , cell(typename Triangulation::cell_iterator(nullptr, -1, -1)) + : cell() , dof_handler(nullptr) , level_dof_access(false) {} @@ -120,8 +119,7 @@ FEValuesBase::CellIteratorContainer::CellIteratorContainer() template FEValuesBase::CellIteratorContainer::CellIteratorContainer( const typename Triangulation::cell_iterator &cell) - : initialized(true) - , cell(cell) + : cell(cell) , dof_handler(nullptr) , level_dof_access(false) {} @@ -132,7 +130,7 @@ template bool FEValuesBase::CellIteratorContainer::is_initialized() const { - return initialized; + return cell.has_value(); } @@ -143,7 +141,7 @@ operator typename Triangulation::cell_iterator() const { Assert(is_initialized(), ExcNotReinited()); - return cell; + return cell.value(); } @@ -172,15 +170,15 @@ FEValuesBase::CellIteratorContainer::get_interpolated_dof_values( Assert(dof_handler != nullptr, ExcNeedsDoFHandler()); if (level_dof_access) - DoFCellAccessor(&cell->get_triangulation(), - cell->level(), - cell->index(), + DoFCellAccessor(&cell.value()->get_triangulation(), + cell.value()->level(), + cell.value()->index(), dof_handler) .get_interpolated_dof_values(in, out); else - DoFCellAccessor(&cell->get_triangulation(), - cell->level(), - cell->index(), + DoFCellAccessor(&cell.value()->get_triangulation(), + cell.value()->level(), + cell.value()->index(), dof_handler) .get_interpolated_dof_values(in, out); } @@ -198,7 +196,10 @@ FEValuesBase::CellIteratorContainer::get_interpolated_dof_values( Assert(level_dof_access == false, ExcNotImplemented()); const DoFCellAccessor 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 dof_indices( cell_dofs.get_fe().n_dofs_per_cell()); -- 2.39.5