title: Convert from pointer-to-member template function to functional type objects
body: <p>I have this code that works already:</p>
  
  <pre><code>// mem_fun example
  #include &lt;iostream&gt;
  #include &lt;functional&gt;
  #include &lt;vector&gt;
  #include &lt;algorithm&gt;
  #include &lt;string&gt;
  #include &lt;sstream&gt;
  #include &lt;map&gt;
  using namespace std;
  
  struct C
  {
      C(int i): y_(i) {};
      int y_;
      string op1(int x)
      {
         std::ostringstream oss;
         oss &lt;&lt; "operation 1: " &lt;&lt; x+y_;
         return oss.str();
      }
      string op2(string x)
      {
         std::ostringstream oss;
         oss &lt;&lt; "operation 2: " &lt;&lt; x &lt;&lt; "+" &lt;&lt; y_;
         return oss.str();
      }
  };
  
  struct container: map&lt;string, C&gt; 
  {
  // doesn't compile
  // void safeOperation(string key, ??? bound_function_and_arg_object )
  
      template&lt; typename argType &gt;
      void safeOperation(string key, string (C::*mf)(argType a), argType a)
      {
          iterator it = find(key);
          if (it != end())
          {
              C* pC = &amp;(it-&gt;second);
  
              cout &lt;&lt; (pC-&gt;*mf)(a) &lt;&lt; "\n";
          }
          else
          {
              cout &lt;&lt; "key: " &lt;&lt; key &lt;&lt; " missing\n";
          }
      }
  };
  
  
  int main () {
      container objects;
  
      objects.insert(container::value_type("a1", C(1)));
      objects.insert(container::value_type("b2", C(2)));
      objects.insert(container::value_type("c3", C(3)));
  
      objects.safeOperation("a1", &amp;C::op1, 1);    
      objects.safeOperation("b2", &amp;C::op1, 2);    
      objects.safeOperation("d4", &amp;C::op1, 4);    
      objects.safeOperation("c3", &amp;C::op2, string("3"));    
  
    return 0;
  }
  </code></pre>
  
  <p>I'd like to change the template function on the map to use std::mem_fun and to bind the parameters together with the operation, rather than specify them as separate parameters to safeOperation.</p>
  
  <p>In other words, I'd prefer to call safeOperation similar to this:</p>
  
  <pre><code>// wrong, but hopefully communicates what I'm trying to do:
  objects.safeOperation(someKey, bind(&amp;C::op1, 4)); 
  </code></pre>
  
  <p>The sample code is here: <a href="http://cpp.sh/74pgb" rel="nofollow">http://cpp.sh/74pgb</a></p>
  
  <p>I'm probably missing something simple, but appreciate the help. </p>