bind函数使用
/*************************************************************************
> File Name: test.cpp
> Author: laiqingcai
> Mail: 837620452@qq.com
> Created Time: 2021年11月20日 星期六 22时53分13秒
************************************************************************/
#include <iostream>
#include <functional>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
//using namespace std::placeholders;
bool check_size(const string str, string::size_type size)
{
return str.size() >= size;
}
int main()
{
vector<string> v_str = {"h", "he", "hel", "hell", "hello"};
auto wc = find_if(v_str.begin(), v_str.end(), bind(check_size, placeholders::_1, 3));
cout << *wc << endl;
}
placeholders使用
/*************************************************************************
> File Name: test.cpp
> Author: laiqingcai
> Mail: 837620452@qq.com
> Created Time: 2021年11月20日 星期六 22时53分13秒
************************************************************************/
#include <iostream>
#include <functional>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
//using namespace std::placeholders;
bool check_size(const string str, string::size_type size)
{
return str.size() >= size;
}
int main()
{
vector<string> v_str = {"h", "he", "hel", "hell", "hello"};
auto checksize = bind(check_size, placeholders::_1, 3);
string str = "hello";
auto wc1 = checksize(str);
cout << wc1 << endl;
}