title: Call c++ member function with each element in a list?
body: <p>I have a list of <code>Thing</code> and a <code>Controller</code> that I want to <code>notify()</code> with each of the things. The code below works:</p>
  
  <pre><code>#include &lt;algorithm&gt;
  #include &lt;iostream&gt;
  #include &lt;tr1/functional&gt;
  #include &lt;list&gt;
  using namespace std;
  
  class Thing { public: int x; };
  
  class Controller
  {
  public:
      void notify(Thing&amp; t) { cerr &lt;&lt; t.x &lt;&lt; endl; }
  };
  
  class Notifier
  {
  public:
      Notifier(Controller* c) { _c = c; }
      void operator()(Thing&amp; t) { _c-&gt;notify(t); }
  private:
      Controller* _c;
  };
  
  int main()
  {
      list&lt;Thing&gt; things;
      Controller c;
  
      // ... add some things ...
      Thing t;
      t.x = 1; things.push_back(t);
      t.x = 2; things.push_back(t);
      t.x = 3; things.push_back(t);
  
      // This doesn't work:
      //for_each(things.begin(), things.end(),
      //         tr1::mem_fn(&amp;Controller::notify));
  
      for_each(things.begin(), things.end(), Notifier(&amp;c));
      return 0;
  }
  </code></pre>
  
  <p>My question is: can I get rid of the <code>Notifier</code> class by using some version of the "This doesn't work" line? Seems like I should be able to make something work, but can't quite get the right combination. (I've fumbled around with a number of different combinations.)</p>
  
  <p>Without using boost? (I would if I could.) I'm using g++ 4.1.2, yes I know it is old...</p>