title: Possible to have C++ anonymous functions with boost?
body: <p>I'm trying to solve a problem that anonymous functions make much, much easier, and was wondering if this was possible in c++.</p>
  
  <p>What I would like to do is (essentially)</p>
  
  <pre><code>template&lt;typename T&gt;
  T DoSomething(T one, function&lt;T(T)&gt; dosomething)
  {
      return one + dosomething(5);
  }
  
  void GetMyVal(...)
  {
     DoSomething&lt;int&gt;(1, /*anonymous func here*/)
  }
  </code></pre>
  
  <p>This example is very, very simplified for what I have to do. In C# I would do p => p*5. I know this is easy with C++0x, but I can't use that. I feel that I should be able to do it with either boost::lambda, or a compination of boost::bind and boost::function with placeholders, but I can't seem to get it to work. This may not be possible and thats also fine, but please answer if its not possible. Thanks.</p>
  
  <p>EDIT:
  Ok, it seems the simple case of an int works fine, what about a more complicated structure? So, lets try</p>
  
  <pre><code>struct NumHolder
  {
    int x;
  }
  
  template&lt;typename T&gt;
  T DoSomething(T one, function&lt;T(NumHolder)&gt; dosomething)
  {
      NumHolder temp;
      temp = 5
      return one + dosomething(temp);
  }
  
  void GetMyVal(...)
  {
     DoSomething&lt;int&gt;(1, /*anonymous func here*/)
  }
  </code></pre>
  
  <p>Here my C# expression would be along the lines of p => p.temp * 5. Is this possible to do in C++ with boost?</p>
  
  <p>EDIT 2: OK, now I'm just curious :D How would I call a function within the lambda expression? So, if we have </p>
  
  <pre><code>int ChangeVal(int mult)
  {
      return mult*5;
  }
  
  struct NumHolder
  {
    int x;
  }
  
  template&lt;typename T&gt;
  T DoSomething(T one, function&lt;T(NumHolder)&gt; dosomething)
  {
      NumHolder temp;
      temp = 5
      return one + dosomething(temp);
  }
  
  void GetMyVal(...)
  {
     DoSomething&lt;int&gt;(1, /*anonymous func here*/)
  }
  </code></pre>
  
  <p>In C# I could call p => ChangeVal(p). What would the syntax be for this with the C++ lambda expressions?</p>