operator () (const TableIndices<N> &indices) const;
/**
- * Determine an estimate for the
- * memory consumption (in bytes)
- * of this object.
+ * Swap the contents of this table and the other table @p v. One could do
+ * this operation with a temporary variable and copying over the data
+ * elements, but this function is significantly more efficient since it only
+ * swaps the pointers to the data of the two vectors and therefore does not
+ * need to allocate temporary storage and move data around.
+ *
+ * This function is analog to the the @p swap function of all C++ standard
+ * containers. Also, there is a global function <tt>swap(u,v)</tt> that
+ * simply calls <tt>u.swap(v)</tt>, again in analogy to standard functions.
+ */
+ void swap (TableBase<N,T> &v);
+
+ /**
+ * Determine an estimate for the memory consumption (in bytes) of this
+ * object.
*/
std::size_t memory_consumption () const;
/**
- * Write or read the data of this object to or
- * from a stream for the purpose of serialization.
+ * Write or read the data of this object to or from a stream for the purpose
+ * of serialization.
*/
template <class Archive>
void serialize (Archive &ar, const unsigned int version);
+template <int N, typename T>
+inline
+void
+TableBase<N,T>::swap (TableBase<N,T> &v)
+{
+ values.swap(v.values);
+ std::swap (table_size, v.table_size);
+}
+
+
+
template <int N, typename T>
inline
std::size_t
#endif // DOXYGEN
+
+
+
+/**
+ * Global function @p swap which overloads the default implementation
+ * of the C++ standard library which uses a temporary object. The
+ * function simply exchanges the data of the two tables.
+ *
+ * @author Martin Kronbichler, 2013
+ */
+template <int N, typename T>
+inline
+void swap (TableBase<N,T> &u, TableBase<N,T> &v)
+{
+ u.swap (v);
+}
+
DEAL_II_NAMESPACE_CLOSE
#endif
#endif
// swap matrices
- std::swap(const_cast<FullMatrix<double> &>
- (this->prolongation[refinement_case-1][child]), prolongate);
+ prolongate.swap(const_cast<FullMatrix<double> &>
+ (this->prolongation[refinement_case-1][child]));
}
// finally return the matrix
}
// swap matrices
- std::swap(const_cast<FullMatrix<double> &>
- (this->restriction[refinement_case-1][child]), restriction);
-
+ restriction.swap(const_cast<FullMatrix<double> &>
+ (this->restriction[refinement_case-1][child]));
}
return this->restriction[refinement_case-1][child];
restriction(i,j) = (*base_matrices[base])(base_index_i,base_index_j);
}
- std::swap(restriction, const_cast<FullMatrix<double> &>
- (this->restriction[refinement_case-1][child]));
+ restriction.swap(const_cast<FullMatrix<double> &>
+ (this->restriction[refinement_case-1][child]));
}
}
base_index_j = this->system_to_base_table[j].second;
prolongate(i,j) = (*base_matrices[base])(base_index_i,base_index_j);
}
- std::swap(prolongate, const_cast<FullMatrix<double> &>
- (this->prolongation[refinement_case-1][child]));
+ prolongate.swap(const_cast<FullMatrix<double> &>
+ (this->prolongation[refinement_case-1][child]));
}
}