From: Jiaqi Zhang Date: Wed, 21 Jul 2021 15:09:48 +0000 (+0000) Subject: add table.clear() X-Git-Tag: v9.4.0-rc1~1125^2~1 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e5663536014962a42a94d3fdb08e2d680aa41443;p=dealii.git add table.clear() --- diff --git a/include/deal.II/base/table.h b/include/deal.II/base/table.h index 0590896869..7eb422369f 100644 --- a/include/deal.II/base/table.h +++ b/include/deal.II/base/table.h @@ -543,6 +543,12 @@ public: reinit(const TableIndices &new_size, const bool omit_default_initialization = false); + /** + * Set all dimensions to zero. + */ + void + clear(); + /** * Size of the table in direction i. */ @@ -2421,6 +2427,16 @@ TableBase::reinit(const TableIndices &new_sizes, +template +inline void +TableBase::clear() +{ + values.resize(0); + table_size = TableIndices(); +} + + + template inline const TableIndices & TableBase::size() const diff --git a/tests/base/table_05.cc b/tests/base/table_05.cc index 9411790dc8..bdb9cc305a 100644 --- a/tests/base/table_05.cc +++ b/tests/base/table_05.cc @@ -31,6 +31,9 @@ test() dealii::Table unrolled; unrolled.reinit(new_size); + unrolled.clear(); + Assert(unrolled.empty() == true, ExcInternalError()); + deallog << "OK" << std::endl; } diff --git a/tests/base/table_07.cc b/tests/base/table_07.cc index a9734402c9..b7856ad535 100644 --- a/tests/base/table_07.cc +++ b/tests/base/table_07.cc @@ -54,5 +54,8 @@ main() dealii::Table<2, T> table2; table2 = std::move(table); // should not create new objects + table.clear(); + Assert(table.empty() == true, ExcInternalError()); + deallog << "OK" << std::endl; }