<p>I recently ran into a problem that I thought boost::lambda or boost::phoenix could help be solve, but I was not able to get the syntax right and so I did it another way. What I wanted to do was remove all the elements in "strings" that were less than a certain length and not in another container.</p>

<p>This is my first try:</p>

<pre><code>std::vector&lt;std::string&gt; strings = getstrings();
std::set&lt;std::string&gt; others = getothers();
strings.erase(std::remove_if(strings.begin(), strings.end(), (_1.length() &lt; 24 &amp;&amp;  others.find(_1) == others.end())), strings.end());
</code></pre>

<p>How I ended up doing it was this:</p>

<pre><code>struct Discard
{
    bool operator()(std::set&lt;std::string&gt; &amp;cont, const std::string &amp;s)
    {
        return cont.find(s) == cont.end() &amp;&amp; s.length() &lt; 24;
    }
};

lines.erase(std::remove_if( lines.begin(), lines.end(), boost::bind&lt;bool&gt;(Discard(), old_samples, _1)), lines.end());
</code></pre>

You need boost::labmda::bind to lambda-ify function calls, for example the length < 24 part becomes:
```
```
bind(&string::length, _1) < 24
```
```
EDIT
See "Head Geek"'s post for why set::find is tricky.  He got it to resolve the correct set::find overload (so I copied that part), but he missed an essential boost::ref() -- which is why the comparison with end() always failed (the container was copied).
```
```
int main()
{
  vector<string> strings = getstrings();
  set<string> others = getothers();
  set<string>::const_iterator (set<string>::*findFn)(const std::string&) const = &set<string>::find;
  strings.erase(
    remove_if(strings.begin(), strings.end(),
        bind(&string::length, _1) < 24 &&
        bind(findFn, boost::ref(others), _1) == others.end()
      ), strings.end());
  copy(strings.begin(), strings.end(), ostream_iterator<string>(cout, ", "));
  return 0;
}
```
```