# STL中的函数对象(Funciont Objects)

vector<int> V(100);
generate(V.begin(), V.end(), rand);

struct less_mag : public binary_function<double, double, bool> {
bool operator()(double x, double y) { return fabs(x) < fabs(y); }
};

vector<double> V;
...
sort(V.begin(), V.end(), less_mag());

struct adder : public unary_function<double, void>
{
double sum;
void operator()(double x) { sum += x; }
};

vector<double> V;
...
cout << "The sum is " << result.sum << endl;

list<int> L;
...
list<int>::iterator new_end =
remove_if(L.begin(), L.end(),
compose2(logical_and<bool>(),
bind2nd(greater<int>(), 100),
bind2nd(less<int>(), 1000)));
L.erase(new_end, L.end());

Generator
Unary Function
Binary Function

Predicate
Binary Predicate

plus
minus
multiplies (formerly called times)
divides
modulus,
negate
equal_to
not_equal_to
greater
less
greater_equal
less_equal,
logical_and
logical_or
logical_not
subtractive_rng
identity
project1st
project2nd
select1st
select2nd
unary_function
binary_function
unary_compose
binary_compose
unary_negate
binary_negate
binder1st
binder2nd
pointer_to_unary_function
pointer_to_binary_function

compose1
compose2
not1
not2
bind1st
bind2nd
ptr_fun

#### STL函数对象之预定义函数对象和函数对象绑定器

2015-02-11 14:57:35

#### STL算法设计理念 - 预定义函数对象

2015-07-09 21:06:28

#### STL预定义函数对象

2018-01-15 16:26:11

#### C++ STL/ (11) 函数对象

2017-04-09 16:55:10

#### C++中的函数对象（Function Object）

2015-12-31 11:35:07

#### STL算法之回调函数和函数对象的理解及设计

2016-05-01 00:26:20

#### STL之函数对象

2014-04-14 17:20:05

#### STL中的函数对象(一)

2015-08-29 10:23:11

#### STL中的常用算法

2013-09-11 17:14:18