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 8260217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T03:03:08+00:00 2026-06-08T03:03:08+00:00

I need a container that allows me to fast erasing ONE element while I

  • 0

I need a container that allows me to fast erasing ONE element while I am looping over it. I don’t need direct access because I always access it within a loop.

Is List faster than Vector for this case?

Pseudocode:

vector<Item*> myContainer;

for(..loop over it...) {

  if (someCondition)
    myContainer.erase(currentElement)
}

After having deleted an element I need to keep looping over the rest of elements

  • 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-08T03:03:09+00:00Added an answer on June 8, 2026 at 3:03 am

    Yes, in theory lists offer faster removal than vectors, but in practice, nobody uses lists. Why not? Because vectors generate much less heap activity, and they offer much better cache locality.

    Are you sure you absolutely need to loop over the vector and erase elements one by one? That would result in quadratic complexity for vectors, but the erase-remove-idiom does it in linear time:

    #include <algorithm>
    
    myContainer.erase(
        std::remove_if(
            myContainer.begin(),
            myContainer.end(),
            [](Item* p) {
                return p->someCondition;
            }
        ),
        myContainer.end()
    );
    

    (If the vector owns the Items, you should probably replace it with a vector<unique_ptr<Item>>.)

    As an alternative, if you really must remove the elements one by one, and you don’t care about the relative order of the Items, there is a neat little trick to remove one element of a vector in constant time.

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

Sidebar

Related Questions

I'm currently working with a big container that i need to iterater over an
I am in need of a container that can handle duplicate keys like the
I have a container that contains an image that I need to drag from
I have a container MovieClip that serves as a content area that I need
Ive got this problem: Line 20 (LOOT_FromContainer(container) I need that to use as Invoke
Problem: I need to get a random element for a container and also delete
I need to make an image viewer that allows large images to be loaded
I need to be able to get the tiles that are contained in the
I need to filter out strings that contain anything other than letters, numbers, dots,
I need to call a USSD number that contains * and # in iphone

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.