是否有拆开一个std ::对一个标准的C ++函数对象? [英] Is there a standard C++ function object for taking apart a std::pair?
本文介绍了是否有拆开一个std ::对一个标准的C ++函数对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有谁知道,如果有一个事实上的标准(即TR1或升压)C ++函数对象访问一个std ::对的要素是什么?两次在过去24小时内,我希望我有这样的事情在键为Perl
函数散列。例如,这将是很好运行的std ::一个std ::地图对象变换和转储所有键(或值)到另一个容器。我当然可以写这样的功能对象,但我想preFER重用东西是有很多的眼球就可以了。
Does anyone know if there's a de-facto standard (i.e., TR1 or Boost) C++ function object for accessing the elements of a std::pair? Twice in the past 24 hours I've wished I had something like the keys
function for Perl hashes. For example, it would be nice to run std::transform on a std::map object and dump all the keys (or values) to another container. I could certainly write such a function object but I'd prefer to reuse something that's had a lot of eyeballs on it.
推荐答案
的boost ::绑定
是你寻找什么。
boost::bind(&std::pair::second, _1); // returns the value of a pair
例如:
typedef std::map<std::string, int> map_type;
std::vector<int> values; // will contain all values
map_type map;
std::transform(map.begin(),
map.end(),
std::back_inserter(values),
boost::bind(&map_type::value_type::second, _1));
这篇关于是否有拆开一个std ::对一个标准的C ++函数对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文