Skip to content

Make DenseVector assignment operator work

Tobias Leibner requested to merge (removed):fix_densevector_assignment into master

Currently, assigning two DenseVectors does not work properly. Doing something like

template <class V>
void assign(DenseVector<V>& v, const DenseVector<V>& w)
{
  v = w;
}

FieldVector<double, 3> v(0), w(1);
assign(v, w);

will compile and execute fine, but after the assign v will still be filled with zeros, as the default copy assignment operator of DenseVector is used (which does not copy anything as DenseVector does not contain data). This bit me when trying to write code that works for both FieldVector and DynamicVector and is hard to detect as there are no errors or warnings. If the DenseVector should not be assigned, there should at least be an error during compilation (e.g. by deleting the copy assignment operator).

This MR adds a test similar to the code above and fixes the test by adding a working operator= to DenseVector.

Merge request reports

Loading