title: What STL container to perform removal of elements in between?
body: <p>I need to pick a container to hold pointers to a type I defined (<code>Particle</code>). I'm using a pre-allocated Particle <code>Object Pool</code> ( which contain objects pre-allocated on an std::vector ).</p>
  
  <p>My Particle emitters ask the Particle Pool for particles when they need to emit, ( in order to avoid in-game Particle allocation ). When a Particle expires, it is returned to the Particle Object Pool.</p>
  
  <p>As you can see, as I iterate through my Particle Reference Container (need to pick one) in order to update it, I will have to check which particles have expired (<code>lifetime &lt;= 0.0</code>) and return them back to the Particles Pool, the expired particles could be at any position in the container.</p>
  
  <p>I've been thinking about using <code>std::list</code>, here's why:</p>
  
  <p>A list (AFAIK) provides constant time insertion at the beginning , and constant time removal at any point ( assuming you have iterated to that point ).</p>
  
  <p>Any suggestions or improvements to my system in order to better accomodate your container suggestions are welcome.</p>
  
  <p><strong>EDIT</strong>:</p>
  
  <p>To explain myself a bit better:</p>
  
  <p>The life time of the particles in an emitter is <strong>not</strong> exactly the same, it depends on a range, for example, 5.0 seconds +- (0.0 to 0.5). This is in order to give the particles a randomness element, and looks quite better than all in fixed time.</p>
  
  <p>Algorithm Pseudo code:</p>
  
  <pre><code>    // Assume typedef std::container_type&lt;Particle *&gt; ParticleContainer
  
  void update(float delta)
  {   
      ParticleContainer::iterator particle = m_particles.begin();   
  
      for(; particle != m_particles.end(); ++particle)
      {
          updateParticle(*particle, delta);         //Update the particle
  
          if ( (*particle)-&gt;lifeTime &lt;= 0.0 )
          {
              ParticlePool.markAsFree(*particle);   //Mark Particle as free in the object Pool
              m_particles.remove(*particle);        //Remove the Particle from my own ParticleContainer
          }   
      }
  }
  </code></pre>