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 ...
随机推荐
- .Net 下基于Redlock redis 分布式锁实现
Redlock-cs (C#/.NET implementation). RedLock.net (C#/.NET implementation). Includes async and lock e ...
- git 提交代码报错failed to push some refs to 解决笔记
Administrator@SC- MINGW64 /e/gitrepository (master) $ git push django master To github.com:zgc137/dj ...
- ACM数据结构-线段树
1.维护区间最大最小值模板(以维护最小值为例) #include<iostream> #include<stdio.h> #define LEN 11 #define MAX ...
- 读RAM时的时序风险
读RAM时的时序有两个风险:1.数据已经存储好,读所需的时间.2.数据同时更新,读所需的时间节点.对于前者,只要延时足够节拍就行.对于后者,还必须要考虑数据建立的时间,同样延时的准备可能会因为数据尚未 ...
- shell 文件的包含
使用.或者source api.sh function intadd() { let data=$+$ echo $data } test.sh #!/bin/bash . api.sh read d ...
- WSL调用Windows下的ParaView对OpenFOAM进行后处理
OpenFOAM可以在windows下的Linux子系统(WSL)安装,但是很麻烦的一个问题是WSL没有图形化的界面,只有一个控制台窗口,在后处理的过程中我们就没有办法直接调用paraFoam命令启动 ...
- PHP面试-复习知识点整理
false的七种情况 整型0 浮点0.0 布尔false 空字符串'',"" 字符串'0' 空数组[] NULL 超全局数组 $GLOBALS,包含下面8个超全局数组的值 $_GE ...
- 南开大学2020年数学分析高等代数考研试题回忆版TeX排版
南开大学2020年数学分析高等代数考研试题回忆版TeX排版 220328[南开大学2020年高等代数考研试题回忆版] 220329[南开大学2020年数学分析考研试题回忆版]
- 线程:Java中wait、notify、notifyAll使用详解
基础知识 首先我们需要知道,这几个都是Object对象的方法.换言之,Java中所有的对象都有这些方法. public final native void notify(); public final ...
- PHP系列 | Thinkphp3.2 上传七牛 bad token 问题 [ layui.upload 图片/文件上传]
前端代码 <div class="logo_out" id="upload-logo"></div> JS代码 /** * 上传图片 * ...