Very simple question: is there a smart way of creating a subvector from regularly spaced elements of another vector with the STL?
In short, is it possible to write the following code with a STL algorithm:
int inc = 2;
std::vector<double> v_origin;
std::vector<double> v_dest;
for (int i = 0; i < v_origin.size(); i+= inc)
v_dest.push_back(v_origin[i]);
Like I would write in Matlab or Python something like:
v_dest = v_origin[0:inc:end];
As a general solution, you could define a stride iterator. If you use Boost.Range, then it already as a
stridedrange adaptor.Example: