10.22
bool func(const string &s, string::size_type sz)
{
return s.size() <= sz;
}
std::cout << count_if(v.cbegin(), v.cend(), bind(func, _1, 6));
10.23
bind接受n+1个参数,n是arg_list 中参数的数目
10.24
auto check_size(string const& str, size_t sz)
{
return str.size() < sz;
}
auto result = find_if(vec.begin(), vec.end(), bind(check_size, str, _1));
10.25
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
using std::string; using std::vector;
using namespace std::placeholders;
void elimdups(vector<string> &vs)
{
std::sort(vs.begin(), vs.end());
vs.erase(unique(vs.begin(), vs.end()), vs.end());
}
bool check_size(const string &s, string::size_type sz)
{
return s.size() >= sz;
}
void biggies(vector<string> &words, vector<string>::size_type sz)
{
elimdups(words);
auto iter = std::stable_partition(words.begin(), words.end(), bind(check_size, _1, sz));
for_each(words.begin(), iter, [](const string &s) { std::cout << s << " "; });
}
int main()
{
std::vector<std::string> v{
"the", "quick", "red", "fox", "jumps", "over", "the", "slow", "red", "turtle"
};
biggies(v, 4);
}