title: C++ this and constant object
body: <p>could you tell me why this code works? There is overloaded operator() which is used by <code>replace_if</code> algorithm. In main function I've created constant object of IsEqual class so only constant function member should be used. Somehow constancy isn't working and that operator is called.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include &lt;algorithm&gt;
  
  class IsEqual {
      int value;
  public:
      IsEqual(int v) : value(v) {}
      bool operator()(const int &amp;elem){
      this-&gt;value=6;
      return elem == value;
      }
  };
  
  int main()
  {
      const IsEqual tst(2);
      std::vector&lt;int&gt; vec = {3,2,1,4,3,7,8,6};
      std::replace_if(vec.begin(), vec.end(), tst, 5);
      for (int i : vec) std::cout &lt;&lt; i &lt;&lt; " ";
      std::cout&lt;&lt;std::endl;
  }
  </code></pre>
  
  <p>result: 3 2 1 4 3 7 8 5 </p>