function template
<functional>
std::bind1st
template <class Operation, class T> binder1st<Operation> bind1st (const Operation& op, const T& x);
繫結第一個引數的函式物件
此函式使用二進位制函式物件
op,透過將第一個引數繫結到固定值
x來構造一個一元函式物件。
返回的函式物件
bind1st定義了其
operator(),使其只能接受一個引數。此引數用於呼叫二進位制函式物件
op,並將
x作為第一個引數的固定值。
它的定義與以下行為相同:
1 2 3 4 5
|
template <class Operation, class T>
binder1st<Operation> bind1st (const Operation& op, const T& x)
{
return binder1st<Operation>(op, typename Operation::first_argument_type(x));
}
|
要將第二個引數繫結到特定值,請參閱
bind2nd。
引數
- op
- 派生自 binary_function 的二進位制函式物件。
- x
- op 的第一個引數的固定值。
返回值
等效於
op但第一個引數始終設定為
x的一元函式物件。
binder1st 是派生自
unary_function 的型別。
示例
1 2 3 4 5 6 7 8 9 10 11 12 13
|
// 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(equal_to<int>(),10) );
cout << "There are " << cx << " elements that are equal to 10.\n";
return 0;
}
|
There are 2 elements that are equal to 10.
|
另見
- bind2nd
- 返回第二個引數被繫結的函式物件 (函式模板)
- binder1st
- 生成第一個引數被繫結的函式物件類 (類模板)
- unary_function
- 一元函式物件基類 (類模板)
- binary_function
- 二元函式物件基類 (類模板)