If you're confronted with a C API that promises more than it shows with respect to const
-correctness, it is time to const_cast
:
vector<double> autocorr(const vector<double>& data)
{
vector<double> ret(data.size(), 0);
// prepare other variables
fftw_plan a = fftw_plan_dft_r2c_1d(size, const_cast<double*>(&data.front()), tmp, FFTW_ESTIMATE);
// do the rest of the work
return ret;
}
Also note this sentence in the documentation:
in and out point to the input and output arrays of the transform, which may be the same (yielding an in-place transform). These arrays are overwritten during planning, unless FFTW_ESTIMATE is used in the flags.
Since you're using the FFTW_ESTIMATE
flag, you should be fine in this case.
The reason FFTW developers decided not to duplicate this function for the sake of const
is that in C, const
isn't at all a big deal, and FFTW is a C library.