title: Lazy evaluation and problems with const correctness
body: <p>I have made an openGL camera class that uses lazy evaluation to provide the final projection or model-view-projection matrices through getter functions.  The user provides the various camera parameters throughout the life of the instance (FOV, position, etc. ), but rather than have the projection matrix and/or MVP matrix recalculated every time a parameter is changed, a 'changed' flag is set (i.e. the old cached matrix is now invalid).  Whenever the user then requests the updated final matrix, it is recalculated, the result cached, and a const reference returned.</p>
  
  <p>Everything sounds fine until I call my:</p>
  
  <pre><code>const QMatrix4x4&amp; oE_GLCamera::getModelViewProjection() const;
  </code></pre>
  
  <p>function from a const oE_GLCamera instance...  I use const references everywhere in my app to extract camera data from CAD viewports without changing the camera, but my getter function performs lazy evaluation on member variables if they are invalid - therefore breaking const-correctness.</p>
  
  <p>Is there a language feature or design paradigm I'm unaware of to help with this?  Or is lazy evaluation fundamentally incompatible with const-correctness?  I am aware of const_cast&lt;>, I have never used it myself but have a read few things about it which boil down to: If you have you use it, you have already gone wrong somewhere.  Or will it be my saviour?</p>
  
  <p>Any advice will be greatfully received,
  Cam</p>