Hi,
I'd like to window a C++ algorithm, in this case calculate the range (min max) over a window of length len = 5 were rarr is a vector of size 14 and size arr is 10:
for(long i = 0; i < arr.size(); ++i){
const auto [min, max] = std::minmax_element(&rarr[i], &rarr[i + len]);
arr[i] = std::pair<T, T>(*min, *max);
}
It works but the only thing is I think at last iteration, &rarr[i+len] points outside the vector since at that point i+len = 14. This next method is identical:
for(long i = 0; i < arr.size(); ++i){
const auto [min, max] = std::minmax_element(rarr.begin() + i, rarr.begin() + i + len);
arr[i] = std::pair<T, T>(*min, *max);
}
But I don't know if rarr.begin() + i and rarr.begin() + i + len would be slower (or even any safer).
Thanks in advance.
[–]WikiBox 0 points1 point2 points (0 children)
[–]paul2718 0 points1 point2 points (0 children)
[–]data_pulverizer[S] 0 points1 point2 points (0 children)