有没有返回p->first
和p->second
的内置函数对象,让我可以愉快的写
transform(m.begin(),m.end(),back_inserter(keys),get_first);
transform(m.begin(),m.end(),back_inserter(vals),get_second);
基于 STL 的解决方案是最好的,boost
解决方案次之。
是的,我知道 boost::lambda
,我不想开始使用它。
最佳答案
g++
有非标准扩展和 SGI
称为 select1st
和 select2nd
。因此,STL 中可能没有任何内容。
Boost的bind也可以做到这一点,给它一个指向正确成员函数的指针
boost::bind(&std::map<string,string>::value_type::second,_1)
关于C++ 函数对象返回 `p->first` 和 `p->second`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5218017/