+
+ /* Nothing to do if the size isn't changing: */
+ if(rows == m_rows && cols == m_cols) return;
+
+ /* Destroy the current array contents: */
+ this->destroy();
+
+ /* Set the new size if non-zero: */
+ if(rows*cols > 0) {
+ value_type* data = m_alloc.allocate(rows*cols);
+ for(size_t i = 0; i < rows*cols; ++ i)
+ m_alloc.construct(&data[i], value_type());
+
+ /* Success, so save the new array and the dimensions: */
+ m_rows = rows;
+ m_cols = cols;
+ m_data = data;
+ }
+ }
+
+ /** Copy the other array. The previous contents are destroyed before
+ * reallocating the array. If other == *this, nothing happens. Also,
+ * if either other.rows() or other.cols() is 0, the array is cleared.
+ */
+ void copy(const dynamic_2D& other) {
+
+ /* Nothing to do if it's the same array: */
+ if(&other == this) return;
+
+ /* Destroy the current array contents: */
+ this->destroy();
+
+ /* Set the new size if non-zero: */
+ size_t rows = other.rows(), cols = other.cols();
+ if(rows*cols > 0) {
+ value_type* data = m_alloc.allocate(rows*cols);
+ for(size_t i = 0; i < rows*cols; ++ i)
+ m_alloc.construct(&data[i], other[i]);
+
+ /* Success, so save the new array and the dimensions: */
+ m_rows = rows;
+ m_cols = cols;
+ m_data = data;
+ }