]> https://gitweb.dealii.org/ - dealii.git/commitdiff
add table.clear()
authorJiaqi Zhang <jiaqi2@clemson.edu>
Wed, 21 Jul 2021 15:09:48 +0000 (15:09 +0000)
committerJiaqi Zhang <jiaqi2@clemson.edu>
Wed, 21 Jul 2021 15:09:48 +0000 (15:09 +0000)
include/deal.II/base/table.h
tests/base/table_05.cc
tests/base/table_07.cc

index 05908968691e99280d8c3a3248bae973fcb2c13e..7eb422369f42f9003d24b85b24347cf70a3f4089 100644 (file)
@@ -543,6 +543,12 @@ public:
   reinit(const TableIndices<N> &new_size,
          const bool             omit_default_initialization = false);
 
+  /**
+   * Set all dimensions to zero.
+   */
+  void
+  clear();
+
   /**
    * Size of the table in direction <tt>i</tt>.
    */
@@ -2421,6 +2427,16 @@ TableBase<N, T>::reinit(const TableIndices<N> &new_sizes,
 
 
 
+template <int N, typename T>
+inline void
+TableBase<N, T>::clear()
+{
+  values.resize(0);
+  table_size = TableIndices<N>();
+}
+
+
+
 template <int N, typename T>
 inline const TableIndices<N> &
 TableBase<N, T>::size() const
index 9411790dc8fa98dbf987383e24f406f876cdf950..bdb9cc305a9bc9c83cc4401307b3ffc13d8da44b 100644 (file)
@@ -31,6 +31,9 @@ test()
   dealii::Table<dim, int> unrolled;
   unrolled.reinit(new_size);
 
+  unrolled.clear();
+  Assert(unrolled.empty() == true, ExcInternalError());
+
   deallog << "OK" << std::endl;
 }
 
index a9734402c95591b2cc5291acaf9be8e211a5d510..b7856ad535e6430841e4057cd4ca96e4ebdc370f 100644 (file)
@@ -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;
 }

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.