Мы можем легко написать select1st и select2nd:
struct select1st
{
template< typename K, typename V >
const K& operator()( std::pair<K,V> const& p ) const
{
return p.first;
}
};
struct select2nd
{
template< typename K, typename V >
const V& operator()( std::pair<K,V> const& p ) const
{
return p.second;
}
};
Вот альтернативная, более гибкая версия:
struct select1st
{
template< typename P >
typename P::first_type const& operator()( P const& p ) const
{
return p.first;
}
};
struct select2nd
{
template< typename P >
typename P::second_type const& operator()( P const& p ) const
{
return p.second;
}
};
в дальнейшем:
transform(m.begin(),m.end(),back_inserter(keys), select1st());
transform(m.begin(),m.end(),back_inserter(vals), select2nd());