std::bind 綁定器
- 將函數(shù)赴捞、成員函數(shù)和閉包轉(zhuǎn)換成function函數(shù)對象
- 將多元(n>1) 轉(zhuǎn)換為一元的函數(shù)對象或者(n-1)元函數(shù)對象铭污。
//查找元素值大于10的元素的個(gè)數(shù)
int count = count_if(coll.begin(), coll.end(), std::bind1st(less<int>(), 10));
//查找元素之小于10的元素
int count = count_if(coll.begin(), coll.end(), std::bind2nd(less<int>(), 10));
bind 函數(shù)組合
//查找集合中大于5小于10的元素個(gè)數(shù)
auto f = bind(std::logical_and<bool>(), bind(std::greater<int>(),_1,5), bind(std::less_equal<int>(),_1,10));
int count = count_if(coll.begin(), coll.end(), f);
function 是為了泛化函數(shù)對象列林、函數(shù)指針、引用函數(shù)赞哗、成員函數(shù)的指針
bind是為了替換和增強(qiáng)之前的bind1st和bind2end,用起來方便帘瞭。