Where there is a dream ,there is hope

  C++博客 :: 首页 :: 联系 :: 聚合  :: 管理
  64 Posts :: 0 Stories :: 8 Comments :: 0 Trackbacks

常用链接

留言簿(1)

我参与的团队

搜索

  •  

最新评论

阅读排行榜

评论排行榜

之前写查找一个VECTOR中保存的一个结构的时候,知道其中的一个数据成员,每次都是遍历一遍,写久了觉得好麻烦,觉得不应该是这样才对。果真在网上找到了这个方法:

用boost::bind,非常简单:

find_if(v.begin(),v.end(),bind(&A::id,_1)==25);


如果需要,下面是完整示例代码:

#include   <algorithm>
#include   <vector>
#include   <boost/bind.hpp>

struct   A
{
    int   id;
};

int   main()
{
    using   namespace   std;
    using   namespace   boost;
    vector <A>   v;
    find_if(v.begin(),v.end(),bind(&A::id,_1)==25);
}

//bind用法



posted on 2011-06-22 15:34 IT菜鸟 阅读(1757) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理