title: How can I tell if a function has been used to modify information or not?
body: <p>I want to do something like this:</p>
  
  <pre><code>class bar{
  public:
      bool edit;
      int foo[];
  
  
      //If the intention is to change some value in foo:
      float &amp; operator [] (int i){
        edit = true;
        return foo[i];
      }
  
      //But if I just want to read
      float &amp; operator [] (int i){
          return foo[i];
      }
  }
  </code></pre>
  
  <p>I want the right way to do it if it can be done.</p>
  
  <p>The simple solution would be to store two vectors, old and new, and check them each time. But I want an efficient solution without having to manually change "edit" every time I change some value.</p>
  
  <p>Perhaps with r-values and l-values?</p>
  
  <p>EDIT:
  The idea is for example, that if I will check the sum of "foo", store the value so I do not have to check foo every time I want to know the sum, only when foo has been modified.</p>