title: C++ best way to build vector of strings from multiple returns of function calls
body: <p>I'm practicing C++, so this is not code that will go into production, but I'm very curious to know:</p>
  
  <p>I have a vector of pointers to objects of type <code>Player</code>:</p>
  
  <pre><code>std::vector&lt;Player*&gt; _players;
  </code></pre>
  
  <p>Each player returns me his name as <code>std::string</code> when I call it's method <code>get_name()</code>, for example:</p>
  
  <pre><code>std::string player0_name = _players[0]-&gt;get_name();
  </code></pre>
  
  <p>I want to pass all player names to a function that expects them as reference to a vector of strings:</p>
  
  <pre><code>void all_player_names( std::vector&lt; std::string &gt;&amp; );
  </code></pre>
  
  <p>Now I know it would be easy to do this via some temporary variable. I could first create a vector of strings, store all player names there, then pass it to the function <code>all_player_names</code> as reference.</p>
  
  <p>But I'm looking for a way of doing that without having to create a temporary variable. It should be something similar like a list comprehension in Python. It has to iterate over the array of <code>Player</code> pointers, call the <code>get_name()</code> function on each of them, build a vector out of the returned strings and directly pass it to the function <code>all_player_names</code>. I'm assuming it should be possible with lambda functions and some algorithm from the STL, but I don't know which one.</p>
  
  <p>So it should look more or less like that:</p>
  
  <pre><code>all_player_names(&lt;function that i'm looking for&gt;(
      _players, [](Player* p) { return p-&gt;get_name();}
  );
  </code></pre>
  
  <p>Is there such an algorithm in the STL?</p>