I want to iterate over a simple double array using iterators. I wonder how I can do that actually.
What I would like to have is something like this:
void foo(double* array, size_t size)
{
std::vector<double> real(size);
std::vector<double> imag(size);
auto arrBegin = std::begin(array); // this of course doesn't work
auto arrEnd = std::end(array); // this of course doesn't work
bool toggle = false;
std::partition_copy(arrBegin, arrEnd, std::begin(real), std::begin(imag),
[&toggle] (int) {return toggle != toggle});
//Do other stuff
}
As some of you might guess, the array is an interleaved complex number, that I would like to split up into arrays of real and imaginary part.
Is there a way to do that using an array that I receive as a pointer if I know the size of the array, or do I need to use a separate class like std::vector for the array in order to work with iterators?
I would appreciate to use std::partition_copy(), but I am open to other ideas.
Note: I cannot use std::array because the array size is not known during compile time. std::vector would be possible, but I actually want to see whether it's possible to do it without std::vector as I receive the array from an API and want to use it as it is.
std::array.size_tinstead. On a 64-bit system it's most likely an alias of an unsigned 64-bit integer type just likeuint64_t, but it conveys more semantical information to the reader of the code.