bind2nd
bind2nd
template <class Operation,class T>
binder2nd <Operation> bind2nd(const Operation&op,const T&x);
返回第二个参数绑定的函数对象
此函数通过将其第二个参数绑定到固定值x,从二元函数对象op构造一元函数对象。bind2nd 返回的函数对象定义了operator(),只需要一个参数。此参数用于调用二进制函数对象op,其中x为第二个参数的固定值。 它的定义与以下行为相同:
template <class Operation, class T>
binder2nd<Operation> bind2nd (const Operation& op, const T& x)
{
return binder2nd<Operation>(op, typename Operation::second_argument_type(x));
}
要将第一个参数绑定到特定值,请参阅bind1st.
参数
op
二进制函数对象派生自binary_function。
x
op的第二个参数的固定值。
返回值
一个等效于op的一元函数对象,但第二个参数始终设置为x。
binder2nd是从unary_function派生的类型。
例
// bind2nd example
#include <iostream>
#include <functional>
#include <algorithm>
using namespace std;
int main () {
int numbers[] = {10,-20,-30,40,-50};
int cx;
cx = count_if ( numbers, numbers+5, bind2nd(less<int>(),0) );
cout << "There are " << cx << " negative elements.\n";
return 0;
}
有3个负面因素。
See also
| bind1st | Return function object with first parameter bound (function template ) |
|---|---|
| binder2nd | Generate function object class with 2nd parameter bound (class template ) |
| unary_function | Unary function object base class (class template ) |
| binary_function | Binary function object base class (class template ) |
bind2nd的更多相关文章
- STL bind1st bind2nd详解
STL bind1st bind2nd详解 先不要被吓到,其实这两个配接器很简单.首先,他们都在头文件<functional>中定义.其次,bind就是绑定的意思,而1st就代表fir ...
- error C2039: “bind2nd”: 不是“std”的成员
VS2012 出现如下错误: error C2039: "bind2nd": 不是"std"的成员 头文件中加上 #include <functi ...
- c++ bind1st 和 bind2nd的用法
std::bind1st 和 std::bind2nd将二元函数转换为一元函数,具体用法参加下面的代码. 代码介绍了两种使用方式,第一种是使用std::less和std::greater,第二种是使用 ...
- 关于标准库中的ptr_fun/binary_function/bind1st/bind2nd
http://www.cnblogs.com/shootingstars/archive/2008/11/14/860042.html 以前使用bind1st以及bind2nd很少,后来发现这两个函数 ...
- Bind2nd源码解析
例:transform(coll1.begin(), coll1.end(), back_inserter(coll2), bind2nd(multiplies<int>(), 10)); ...
- bind1st bind2nd的使用
STL中的函数 bind1st. bind2nd用于将一个二元算子转换成一元算子,需要两个 参数,要转换的bf和一个值v. 参考:http://blog.csdn.net/simahao/articl ...
- 函数适配器bind2nd 、mem_fun_ref 源码分析、函数适配器应用举例
一.适配器 三种类型的适配器: 容器适配器:用来扩展7种基本容器,利用基本容器扩展形成了栈.队列和优先级队列 迭代器适配器:(反向迭代器.插入迭代器.IO流迭代器) 函数适配器:函数适配器能够将仿函数 ...
- not1,not2,bind1st和bind2nd详解
1.引言 bind1st和bind2nd函数用于将一个二元函数对象(binary functor,bf)转换成一元函数对象(unary functor,uf).为了达到这个目的,它们需要两个参数:要转 ...
- STL源码剖析(仿函数/bind2nd)
仿函数(functors)其实就是重载了operator()的对象. 下面简单先看看它的一个例子: #include <iostream> using namespace std; tem ...
- not1,not2,bind1st,bind2nd
例子需要包含头文件 #include <vector> #include <algorithm> #include <functional> bind1st和bin ...
随机推荐
- Java中lambda表达式学习
一.Lambda表达式的基础语法: Java8中引入了一个新的操作符"->"该操作符称为箭头操作符或Lambda操作符,箭头操作符将Lambda表达式拆分为两部分: 左侧:L ...
- 【转】为什么我们做分布式使用Redis?
绝大部分写业务的程序员,在实际开发中使用 Redis 的时候,只会 Set Value 和 Get Value 两个操作,对 Redis 整体缺乏一个认知.这里对 Redis 常见问题做一个总结,解决 ...
- 【CSP-S膜你考】最近公共祖先 (数学)
Problem A. 最近公共祖先 (commonants.c/cpp/pas) 注意 Input file: commonants.in Output file: commonants.out Ti ...
- ImportError: cannot import name 'BaseDataset' from 'src.dataset'
因为我进行了相互调用,我在父类中调用了子类. from src.dataset import BaseDataset class PSINSDataset(BaseDataset): from src ...
- [技术博客] 数据库1+N查询问题
目录 问题简述 问题解决 group的方法简化查询 改正后的代码 作者:庄廓然 问题简述 本次开发过程中我们用到了rails的orm框架,使用orm框架可以很方便地进行对象的关联和查询,例如查询一个用 ...
- [Beta阶段]发布说明
小小易校园微信小程序发布说明 第二版小小易校园小程序发布啦~ 打开微信,点击右上角➕,选择扫一扫,扫描以下二维码即可进入小程序: 版本功能: 上一版功能请参见[Alpha阶段]发布说明. 当前版本的更 ...
- @Autowired和@Resource的区别和联系
背景: 今天下班路上看到一个大货车,于是想到了装配,然后脑海里跳出了一个注解@Autowired(自动装配),于是又想到最近工作项目用的都是@Resource注解来进行装配.于是本着学什么东西都要一钻 ...
- Spring Cloud Ribbon 源码分析---负载均衡算法
上一篇分析了Ribbon如何发送出去一个自带负载均衡效果的HTTP请求,本节就重点分析各个算法都是如何实现. 负载均衡整体是从IRule进去的: public interface IRule{ /* ...
- portaudio使用笔记《转》
原文链接:https://blog.csdn.net/gg_simida/article/details/77185755 介绍 PortAudio是一个免费.跨平台.开源的音频I/O库.看到I/O可 ...
- [linux]测硬盘读写速度、内存读写速度
测硬盘的读写速度可以用以下命令:dd if=/dev/zero of=file bs=1M count=1024 测内存读写速度可以使用以下命令: dd if=/dev/zero of=/dev/nu ...