title: Why isn't std::list.size() constant-time?
body: <p>This code ran for 0.012 seconds:</p>
  
  <pre><code> std::list&lt;int&gt; list;
   list.resize(100);
   int size;
   for(int i = 0 ; i &lt; 10000; i++)
       size = list.size();
  </code></pre>
  
  <p>This one for 9.378 seconds:</p>
  
  <pre><code> std::list&lt;int&gt; list;
   list.resize(100000);
   int size;
   for(int i = 0 ; i &lt; 10000; i++)
       size = list.size();
  </code></pre>
  
  <p>In my opinion it would be possible to implement std::list in such way, that size would be stored in a private variable but according to this it is computed again each time I call size. Can anyone explain why?</p>