title: C++ how to convert member functions to standalone functions (for use as function parameter) generically?
body: <p>For function parameters of template functions I find myself often wrapping member functions inside a lambda to create identical standalone functions with the first parameter being the object.</p>
  
  <p>A (dummy) example : </p>
  
  <pre><code>class A
  {
  public:
      double f1() const;
      double f2(int i) const;
  
      // some data
  };
  
  template &lt;typename Func&gt;
  double calculateSum(std::vector&lt;A&gt; as, Func f)
  {
      double result = 0.0;
      for (auto a : as)
          result += f(a);
      return result;
  }
  
  int main()
  {
      std::vector&lt;A&gt; as;
      int i = 0;
      auto sum1 = calculateSum(as, [](const A&amp; a) { return a.f1(); });
      auto sum2 = calculateSum(as, [&amp;i](const A&amp; a) { return a.f2(i); });
      return 0;
  }
  </code></pre>
  
  <p>Is there a way to define such lambdas more generically ? or is there a way to directly refer to the member functions instead of using lambdas ? </p>