From 28dbd0e65dd3f5d66da8a4a0f95ae380677cf7a5 Mon Sep 17 00:00:00 2001 From: Fernando Herrera Date: Tue, 13 Aug 2024 14:14:08 -0600 Subject: [PATCH] Add empty() function to deal.II/lac/vector.h and use it instead of size() == 0 Co-authored-by: Sanjeeb Poudel --- examples/step-28/step-28.cc | 2 +- examples/step-39/step-39.cc | 2 +- include/deal.II/lac/vector.h | 13 +++++++++++++ source/numerics/data_out_stack.cc | 4 ++-- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/examples/step-28/step-28.cc b/examples/step-28/step-28.cc index 4b3452850a..e0e55e9ccd 100644 --- a/examples/step-28/step-28.cc +++ b/examples/step-28/step-28.cc @@ -591,7 +591,7 @@ namespace Step28 system_rhs.reinit(n_dofs); - if (solution.size() == 0) + if (solution.empty()) { solution.reinit(n_dofs); solution_old.reinit(n_dofs); diff --git a/examples/step-39/step-39.cc b/examples/step-39/step-39.cc index 48227bb32b..d7f2b54eef 100644 --- a/examples/step-39/step-39.cc +++ b/examples/step-39/step-39.cc @@ -1010,7 +1010,7 @@ namespace Step39 for (unsigned int s = 0; s < n_steps; ++s) { deallog << "Step " << s << std::endl; - if (estimates.block(0).size() == 0) + if (estimates.block(0).empty()) triangulation.refine_global(1); else { diff --git a/include/deal.II/lac/vector.h b/include/deal.II/lac/vector.h index b385674b87..fbd184ab71 100644 --- a/include/deal.II/lac/vector.h +++ b/include/deal.II/lac/vector.h @@ -287,6 +287,13 @@ public: */ virtual ~Vector() override = default; + + /** + * This function is equivalent to writing size() == 0. + */ + bool + empty() const; + /** * This function does nothing but exists for compatibility with the parallel * vector classes. @@ -1392,6 +1399,12 @@ Vector::operator!=(const Vector &v) const } +template +inline bool +Vector::empty() const +{ + return this->size() == 0; +} template inline void diff --git a/source/numerics/data_out_stack.cc b/source/numerics/data_out_stack.cc index e64b1f5f3d..ed293102c4 100644 --- a/source/numerics/data_out_stack.cc +++ b/source/numerics/data_out_stack.cc @@ -60,11 +60,11 @@ DataOutStack::new_parameter_value(const double p, for (typename std::vector::const_iterator i = dof_data.begin(); i != dof_data.end(); ++i) - Assert(i->data.size() == 0, ExcDataNotCleared()); + Assert(i->data.empty(), ExcDataNotCleared()); for (typename std::vector::const_iterator i = cell_data.begin(); i != cell_data.end(); ++i) - Assert(i->data.size() == 0, ExcDataNotCleared()); + Assert(i->data.empty(), ExcDataNotCleared()); } -- 2.39.5