bind1st 和 bind2nd的区别

本文详细介绍了bind1st和bind2nd在C++中的使用方法,通过具体示例展示了它们如何在算法操作中提高代码的灵活性和效率。重点讨论了它们之间的区别及应用场景。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

今天总算是弄明白bind1st和bind2nd是怎么用的,有什么区别了。只知道工作,不知道学习很久了。

 

// bind1st example
#include <iostream>
#include <functional>
#include <algorithm>
using namespace std;

int main () {
  int numbers[] = {10,20,30,40,50,10};
  int cx;
  cx = count_if (numbers, numbers+6, bind1st(greater<int>(),10) );
  cout << "There are " << cx << " elements that are equal to 10.\n";
  return 0;
}

// bind2nd example
#include <iostream>
#include <functional>
#include <algorithm>
using namespace std;

int main () {
  int numbers[] = {10,20,30,40,50,10};
  int cx;
  cx = count_if (numbers, numbers+6, bind2nd(greater<int>(),10) );
  cout << "There are " << cx << " elements that are equal to 10.\n";
  return 0;
}

 

Reference:

http://stackoverflow.com/questions/6112573/bind1st-and-bind2nd

http://stackoverflow.com/questions/6863677/use-bind1st-or-bind2nd

http://www.cplusplus.com/reference/functional/bind1st/

http://www.cplusplus.com/reference/functional/bind2nd/

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值