title: How to combine a function and a predicate in for_each?
body: <p>How can you call a <code>Function</code> over <em>some</em> part of a container, using <code>for_each()</code> ? </p>
  
  <p>I have created a <code>for_each_if()</code> to do a </p>
  
  <pre><code>for( i in shapes )
      if( i.color == 1 )
          displayShape(i);
  </code></pre>
  
  <p>and the call looks like</p>
  
  <pre><code>for_each_if( shapes.begin(), shapes.end(),
                         bind2nd( ptr_fun(colorEquals), 0 ),
                         ptr_fun( displayShape ) );
  
  bool colorEquals( Shape&amp; s, int color ) {
      return s.color == color;
  }
  </code></pre>
  
  <p>However, I feel immitating STL-like algorithms is not something that I should be doing.</p>
  
  <ol>
  <li><p><em>Is there a way to use only existing STL keywords to produce this ?</em></p>
  
  <p>I did <em>not</em> want to do a </p>
  
  <pre><code> for_each( shapes.begin(), shapes.end(),
                     bind2nd( ptr_fun(display_shape_if_color_equals), 0 ) );
  </code></pre>
  
  <p>because, in a more complicated case, the functor name would be misleading with respect to what the functor </p></li>
  <li><p>*Is there a way to access a struct's member (like <code>colorEquals</code>) for functions like <code>for_each</code> without having to create a function ? *</p></li>
  </ol>