coefs
copy constructor and assignment operatorThe copy constructor and assignment operator of the coefs
template class in versions of the Gaborator up to and including 2.0 had
ill-defined semantics where the coefs
object did not behave fully like a value
nor fully like a reference, but as a hybrid where copying resulted in a
partially copied data structure containing references to the original.
The copy would generally behave like a reference to the original,
but unlike the case of a true reference, the copy operation had a nontrivial cost
in time and space, potentially causing hard-to-diagnose performance problems
if coefs
objects were accidentally passed by value rather
than by reference.
In version 2.1, the ill-defined copy constructor and assignment operator have been deleted, and instead a move constructor and move assignment operator have been added.
This change will intentionally break any existing code that
accidentally passes coefs
objects by value. It may also
unintentionally break some existing code that copies coefs
objects in harmless ways, such as copying empty ones. For example, in
2.0, code like the following could be used to create a vector
of coefs
objects:
std::vector<gaborator::coefs<float>> channels(n_channels, gaborator::coefs<float>(anl));
In version 2.1, this no longer works, and needs to be rewritten in a way that avoids copying, such as
std::vector<gaborator::coefs<float>> channels; for (int i = 0; i < n_channels; i++) channels.emplace_back(anl);
Alternatively, you can enable a corrected copy constructor and
assignment operator that make a deep copy of the coefs
object by defining GABORATOR_COEFS_DEEP_COPY
as
1
before including gaborator.h
. This lets
code like the above example work without changes, but has the disadvantage
that accidental copying of non-empty coefs
objects will
not be detected, and the performance problems caused by any such
accidental copying will be exacerbated because the coefs
objects are now copied in full, not just partly.