title: C++ fast ways to bind member functions
body: <p>I have a <code>class transition</code> and inside, a member function <code>rate</code>. I am asking for a method that would allow me to insert custom designed <code>rate</code>s into instants of <code>transition</code>, after those instants have been created, and would be fast at run-time!</p>
  
  <p>I would like to optimize the code for speed. <code>rate</code> does simple computations but is called very frequently and many times by the program. So I guess I should avoid virtual functions... Question: what are the other best methods to achieve this in C++ (templates,boost,...)? Comments about the speed of a particular method would be appreciated. Thanks! </p>
  
  <pre><code>class transition {
  public: 
    transition() : vec() {}
    double rate(T_vec::iterator a) { return ...; }
  private: 
    T_vec vec;
  };
  
  /* custom rate #1 */
  double my_rate_1( T_vec::iterator) { 
    /* do something */ 
    return ans; 
  }
  
  /* custom rate #2 */
  double my_rate_2( T_vec::iterator) { 
    /* do something */ 
    return ans; 
  }
  
  const int N=10;
  
  int main (void) {
  
    vector&lt;transition*&gt; ts(N);
    for(int i=0;i!=N;++i) ts[i] = new transition;
  
    /* How to efficiently implement the pseudo code that follows? */  
  
    ts[0]-&gt;rate = my_rate_1;
    ts[1]-&gt;rate = my_rate_2;
  
    /* ... */     
  
  }
  </code></pre>