Copy assignment problem
lukasberbuer opened this issue · 2 comments
I was trying to put different filter types in a variant (setting variant with copy assignment), but the copy assignment doesn't seem to work in general?
Minimal example:
#include <iostream>
#include <Iir.h>
using FilterType = Iir::Butterworth::HighPass<8>;
void testFilter(FilterType& filter) {
std::cout << "Test response: ";
for (size_t i = 0; i < 5; ++i) {
std::cout << filter.filter(1.0) << ", ";
}
std::cout << std::endl;
}
int main() {
// setup & test 1st time
FilterType filter;
filter.setupN(0.1);
testFilter(filter); // Test response: 0.192873, -0.427308, -0.00869136, 0.266734, 0.2204,
// setup & test 2nd time
filter = FilterType(); // this assignment seems to be the problem
filter.setupN(0.1);
testFilter(filter); // Test response: 1, 1, 1, 1, 1,
}
@lukasberbuer can you check out the branch copyconstructors and test if it works? There is now also a unit test. See comment there where I discuss it with @nickbailey. if you want to dig deeper the issues emerging here:https://github.com/berndporr/iir1/blob/copy-constructors/iir/PoleFilter.h#L121 which is sort of a mess because of https://github.com/berndporr/iir1/blob/copy-constructors/iir/Cascade.h#L49 where the two classes Cascade and CascaseStages transmit array pointers and sizes between each other via the constructors in PoleFilter but can't hand over everything so there is only a partial handover. It works thanks to nickbailey but I feel it would be better to merge the two classes there but I'm sure the orig author had a reason for it!
The changes in the copy-constructors
branch (#41) fixes this issue. Thanks!