title: Is it possible to avoid use of virtual method call in this case?
body: <p>I have a type of data that must be stored in a contiguous array which is iterated over for the purpose of updating that data. The tricky part is that I want to have the possibility to dynamically change the way any object is updated.</p>
  
  <p>This is what I have come up with so far:</p>
  
  <pre><code>struct Update {
      virtual void operator()(Data &amp; data) {}
  };
  
  struct Data {
      int a, b, c;
      Update * update;
  };
  
  struct SpecialBehavior : public Update {
      void operator()(Data &amp; data) override { ... }
  };
  </code></pre>
  
  <p>I would then assign every data object some type of Update. Then during update all data gets passed to its own update functor:</p>
  
  <pre><code>for (Data &amp; data : all)
     data-&gt;update(data);
  </code></pre>
  
  <p>This is as far as I understand called the Strategy Pattern.</p>
  
  <p>My question: is there some way to do this more efficiently? Some way to achieve the same flexibility without the cost of calling a virtual method?</p>