title: Is this a good use-case of "mutable" in C++?
body: <p>I have the following class:</p>
  
  <pre><code>class MyClass
  {
  private:
      mutable int* m_buffer;
  public:
      MyClass(void)
        : m_buffer(nullptr)
      {
      }
      void init(void)
      {
          m_buffer = new int[10];
      }
      // This is the only public interface to retrieve m_buffer
      const int* evaluate(int param) const
      {
          for(int i = 0; i &lt; 10; ++i)
              m_buffer[i] = param*10;
          return m_buffer;
      }
  };
  </code></pre>
  
  <p>I've read that <code>mutable</code> class members should be used when their state does not affect the class external state. In the above code the member <code>m_buffer</code> is retrieved only through the <code>evaluate()</code> method. This method will change the values of <code>m_buffer</code> but the new values depend only on the <code>param</code> argument. Is the use of the <code>mutable</code> keyword correct in this particular example? </p>
  
  <p>I could avoid using <code>mutable</code> by:</p>
  
  <ul>
  <li>Allocating a new buffer every time I call the function. However, this will make my code slow because the buffer is usually a few gigabytes.</li>
  <li>Allocating the output buffer in advance and pass it as an argument to the <code>evaluate</code> function. However, this will make my API more hard to understand/use.</li>
  <li>Declaring <code>m_buffer</code> as <code>int* const</code>. However, this won't work because, due to a design decision, I can not allocate <code>m_buffer</code> in the constructor's initializer list.</li>
  </ul>