I have two std::list, which each one has a positional vector m_Pos. I’m newbie to std::list, and I would to calculate the distance between each index in those two lists and store them in an array. This is what I have done, I dont know if it is the correct way or not
The problem is the dir vector which has the distances are not in ordered manner, I want for example to store the distane between positions Acurrent and Aprev, Bcurrent, Bprev, to be stored in order in the dir vector so that I can correlate later between them, so that I say dir[0] is the distance between Acurr, Aprev..etc
if(objs.size() == m_prev_objs.size())
{
std::vector<Vec2f> dir;
std::list< Obj >::iterator prevIter = m_prev_objs.begin();
std::list< Obj >::iterator currIter = objs.begin();
// Vec2f dis = currIter->m_Pos - prevIter->m_Pos;
for (std::list< Obj >::iterator currIter = objs.begin(); currIter != objs.end(); ++currIter )
{
dir.push_back(currIter->m_Pos - prevIter->m_Pos);
}
prevIter++;
}
Consider using standard algorithms, note the action can be lambda if you have access to C++11
http://en.cppreference.com/w/cpp/algorithm/transform
http://en.cppreference.com/w/cpp/iterator/back_inserter