title: Why do people write private-field getters returning a non-const reference?
body: <p>We can all agree on public variables being bad for encapsulation and all that. However, I noticed a lot of code that does this type of stuff:</p>
  
  <pre><code>class foo {
  private:
      int integer_;
      string someString_;
      // other variables
  public:
      int&amp; integer() { return integer_; }
      string&amp; someString() { return someString_; }
      // other "functions"
  }
  
  int main() {
      foo f;
      f.integer() = 10;
      f.someString() = "something";
      return 0;
  }
  </code></pre>
  
  <p>I have seen this being used in many places and I don't get why. Basically it returns a reference to the data and thus exposes it directly to the outside. So encapsulation is not really achieved, not from any perspective.</p>
  
  <p>Why is this commonly used?</p>