title: Non-const copy constructor
body: <p>I'm doing copy on write optimization for object (i.e. when calling a copy-constructor just save pointer to an object and really copy it only if we need to change our object, or if object we are pointing to going to change).</p>
  
  <p>Before changing our object we need to notify others about it, so they can perform real coping. For this action I decided to use observer pattern:</p>
  
  <pre><code>struct subject {
      void register_observer(const event&amp; e, observer&amp; obs);
      void notify(const event&amp; e) const;
  
  private:
      std::map&lt;event, std::vector&lt;observer*&gt; &gt; _observers;
  };
  </code></pre>
  
  <p>and for observers:</p>
  
  <pre><code>struct observer {
      virtual void onEvent(event e);
  };
  </code></pre>
  
  <p>then, our object inherits both of them. The problem is, that in copy-constructor, we need to call register_observer, which is non-const method, when we get const argument:</p>
  
  <pre><code>my_class::my_class(my_class const &amp;other) {
      if (other._copy != NULL) this-&gt;_copy = &amp;other;
      else {
          this-&gt;_copy = other._copy;
          this-&gt;_copy-&gt;register_observer(event::CHANGED, *this);
      }
  }
  </code></pre>
  
  <p>One possible solution I've discovered is to use <code>mutable</code>, but I think it doesn't fit there, because object is logically changed.</p>
  
  <p>Any other ideas?</p>