title: How do I iterate through a sequence of shared_ptr objects?
body: <p>This is more a styling than performance question. I have just converted (most of) my pointers to shared_ptr objects, and have reluctantly come to accept weak_ptrs as alternatives to raw pointers. My question is, what is the preferred method of iterating through a sequence (let's say a vector) of shared pointer objects? Here is what I've been doing:</p>
  
  <pre><code>std::vector&lt;std::shared_ptr&lt;A&gt;&gt; my_sequence;
  // Do something to fill my_sequence;
  
  for (std::shared_ptr&lt;A&gt; const&amp; ptr : my_sequence)
  {
    ptr-&gt;AMethod();
  }
  </code></pre>
  
  <p>This goes against the *don't use shared_ptr references* rule though, so what's a good alternative, and why?</p>
  
  <p>Questions I would be asking are; Is the technique robust, ie. For AMethod() super tiny, and my_sequence super large, will this method start to impede performance unecessarily due to shared_ptr copies? Is it readable? Is it simple?</p>