title: is it okay to sacrifice const-correctness for speed?
body: <p>I have a factory class that will be used to create a whole lot of instances of a certain class. The creation process is pretty obfuscated and might require a quite a while. So I was thinking it would be smart to store the instances of the class which have already been created inside the factory, I can recall them at a later time.</p>
  
  <p>The creation depends on a single parameter (the name) so things can be stored in a <code>std::map</code> which I call <code>old_instances</code>.</p>
  
  <pre><code>A A_factory::make_A(std::string const&amp; name)
  {
      if ( old_instances.find(name) != old_instances.end() )
      {
          return old_instances.find(name) -&gt; second;
      }
      else
      {
          // obfuscated creation process that creates instance 'new_A'
          // ...
  
          old_instances.insert(std::pair&lt;std::string, A&gt;(name, new_A)); // &lt;- problem
          return new_A;
      }
  }
  </code></pre>
  
  <p>The problem here is that this whole routine could be a <code>const</code> member of the factory. But because the <code>old_instances</code> is adapted. </p>
  
  <p>I kinda feel awkward sacrificing the <code>const</code>-ness of a function for something this trivial.
  Are these kind of sacrifices logical?</p>
  
  <p>please do not shoot me if this question is too dependent on taste.</p>