Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8541185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:46:25+00:00 2026-06-11T11:46:25+00:00

I have two std::list , which each one has a positional vector m_Pos .

  • 0

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++;

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T11:46:26+00:00Added an answer on June 11, 2026 at 11:46 am

    Consider using standard algorithms, note the action can be lambda if you have access to C++11

     inline Vec2f action(const Objs& o1, const Objs& o2) {
           return o1->m_Pos
                - o2->m_Pos;
     }
    
    
     //elsewhere
     std::vector<Vec2f> dir;
     dir.reserve(objs.size());
    
     std::transform(
          objs.begin(),        
          objs.end(), 
          m_prev_objs.begin(), 
          std::back_inserter(dir),
          action
     );
    

    http://en.cppreference.com/w/cpp/algorithm/transform

    http://en.cppreference.com/w/cpp/iterator/back_inserter

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have two containers storing pointers to the same objects: std::list<Foo*> fooList; std::vector<Foo*>
I have one std::list<> container and these threads: One writer thread which adds elements
Say you have a std::list of some class. There are two ways you can
I have two (unrelated) classes. The first one is Point: typedef std::complex<double> complex_number; class
I have a relatively simple algorithm that walks an std::vector looking for two neighbouring
I have two classes (MVC view model) which inherits from one abstract base class.
Possible Duplicate: Does std::list::remove method call destructor of each removed element? I have a
I have two structs (part of the assignment). A list of one -- Activity,
I have two std::list with objects: source_list and new_list . The goal is to
I have std::list<Info> infoList in my application that is shared between two threads. These

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.