title: C++ tools with the same functionality as Python's filter and map
body: <p>I am looking for a C++ analogs for a <code>map</code> or <code>filter</code> from Python programming language. The first of them applies some <em>function to every item of iterable and return a list of the results</em>, the second <em>constructs a list from those elements of iterable for which function returns true</em>. </p>
  
  <p>I would like to use the similar functionality in C++:</p>
  
  <ul>
  <li>Map some function to the container in order to get new container with a transformed data (and probably with a different length);</li>
  <li>Use some kind of conditional filtering for a container;</li>
  </ul>
  
  <p>Are there any fine implementations of Python's map and filter in C++?</p>
  
  <p>In this short example I am trying to work it out using such tools as <code>boost::bind</code> and <code>std::for_each</code> and I face with a difficulties. The <code>std::vector&lt;std::string&gt; result</code> should contain all the strings <code>std::vector&lt;std::string&gt; raw</code> that lexicographicaly higher than the last string from stdin. But in fact the <code>result</code> container is still empty at the return point.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include &lt;algorithm&gt;
  #include &lt;boost/bind.hpp&gt;
  
  void filter_strings(std::string&amp; current, std::string&amp; last, std::vector&lt;std::string&gt;&amp; results)
  {
      if (current &gt; last)
      {
          results.push_back(current);
          std::cout &lt;&lt; "Matched: " &lt;&lt; current &lt;&lt; std::endl;
      }
  }
  
  int main()
  {
      std::vector&lt;std::string&gt; raw, result;
      std::string input, last;
  
      //Populate first container with a data
      while(std::getline(std::cin, input))
          raw.push_back(input);
      last = raw.back();
  
      //Put into result vector all strings which lexicographically higher than the last one
      std::for_each(raw.begin(), raw.end(), boost::bind(&amp;filter_strings, _1, last, result));
  
      //For some reason the resulting container is empty
      std::cout &lt;&lt; "Results: " &lt;&lt; result.size() &lt;&lt; std::endl;
  
      return 0;
  }
  </code></pre>
  
  <p>The input and the output:</p>
  
  <pre><code>[vitaly@thermaltake 1]$ ./9_boost_bind 
  121
  123
  122
  120                      //Ctrl+D key press
  Matched: 121
  Matched: 123
  Matched: 122
  Results: 0
  </code></pre>
  
  <p>Any help will be appreciated.</p>