Question: I'd like to copy values that match a predicate (equal ints) from a `map<string,int>` to a `vector<int>`. 

This is what I tried:

```
#include <map>
#include <vector>
#include <algorithm>

int main()
{
    std::vector< int > v;
    std::map< std::string, int > m;

    m[ "1" ] = 1;
    m[ "2" ] = 2;
    m[ "3" ] = 3;
    m[ "4" ] = 4;
    m[ "5" ] = 5;

    std::copy_if( m.begin(), m.end(), v.begin(),
                  [] ( const std::pair< std::string,int > &it )
                  {
                    return ( 0 == ( it.second % 2 ) );
                  }
                  );
}

```

The error message from g++ 4.6.1 is : 

```
error: cannot convert 'std::pair<const std::basic_string<char>, int>' to 'int' in assignment

```

Is there a way to adjust the example to do the above copy?

Answer: 
With `boost::range` it is as easy as:

```
boost::push_back(
    v,
    m | boost::adaptors::map_values 
      | boost::adaptors::filtered([](int val){ return 0 == (val % 2); }));

```
Problem
-------

The copy fails because you're copying from a `map::iterator` which iterates over `pair<string const,int>` to a `vector::iterator` which iterates over `int`.

Solution
--------

Replace `copy_if` with `for_each` and do a `push_back` on your vector.

Example
-------

```
std::for_each( m.begin(), m.end(),
    [&v] ( std::pair< std::string const,int > const&it ) {
        if ( 0 == ( it.second % 2 ) ) {
            v.push_back(it.second);
        }
    }
);

```