The problem is when I compiled the following program, the compiler showed me an error like this " error: ‘_1’ was not declared in this scope".
1 #include <iostream>
2 #include <vector>
3 #include <functional>
4 #include <string>
5 #include <algorithm>
6
7 using namespace std;
8
9 bool check_size(const string &s, string::size_type sz) {
10 cout << s << endl;
11 return s.size() >= sz;
12 }
13
14 auto newCallable = bind(check_size, _1, 6);
15
16 int main() {
17
18 string s = "Hello World !!!";
19 newCallable(s);
20 return EXIT_SUCCESS;
21 }
I guess the problem should be caused by lack of some important header file which I didn't found.
Finally, I found the solution to this error: the _1 form of placeholder should be in namespace std::placeholders. So I corrected my program in line 16
as follows:
auto newCallable = bind(check_size, placeholders::_1, 6);
Then it works well.