#include <iostream>
#include <algorithm>
#include <functional>
#include <iterator>
#include <vector>
#include <string>
using namespace std::placeholders;
bool check(const std::string &s, std::string::size_type sz)
{
return s.size() >= sz;
}
int main()
{
std::vector<int> u = { 19, 7, 32, 2, 3, 4, 11, 15, 29, 1, 41 };
std::vector<std::string> v = { "x", "zzz", "yy", "bbbbbb", "tttt", "rrr", "xxxxxx" };
std::string s("abc");
auto it = std::find_if(u.begin(), u.end(), std::bind(check, _2, s));
std::cout << *it << std::endl;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8ZnVuY3Rpb25hbD4KI2luY2x1ZGUgPGl0ZXJhdG9yPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8c3RyaW5nPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDo6cGxhY2Vob2xkZXJzOwoKYm9vbCBjaGVjayhjb25zdCBzdGQ6OnN0cmluZyAmcywgc3RkOjpzdHJpbmc6OnNpemVfdHlwZSBzeikKewoJcmV0dXJuIHMuc2l6ZSgpID49IHN6Owp9CgppbnQgbWFpbigpCnsKCXN0ZDo6dmVjdG9yPGludD4JCSB1ID0geyAxOSwgNywgMzIsIDIsIDMsIDQsIDExLCAxNSwgMjksIDEsIDQxIH07CglzdGQ6OnZlY3RvcjxzdGQ6OnN0cmluZz4gdiA9IHsgIngiLCAienp6IiwgInl5IiwgImJiYmJiYiIsICJ0dHR0IiwgInJyciIsICJ4eHh4eHgiIH07CgoJc3RkOjpzdHJpbmcgcygiYWJjIik7CglhdXRvIGl0ID0gc3RkOjpmaW5kX2lmKHUuYmVnaW4oKSwgdS5lbmQoKSwgc3RkOjpiaW5kKGNoZWNrLCBfMiwgcykpOwoJc3RkOjpjb3V0IDw8ICppdCA8PCBzdGQ6OmVuZGw7Cn0=
In file included from /usr/include/c++/5/bits/stl_algobase.h:71:0,
from /usr/include/c++/5/bits/char_traits.h:39,
from /usr/include/c++/5/ios:40,
from /usr/include/c++/5/ostream:38,
from /usr/include/c++/5/iostream:39,
from prog.cpp:1:
/usr/include/c++/5/bits/predefined_ops.h: In instantiation of 'bool __gnu_cxx::__ops::_Iter_pred<_Predicate>::operator()(_Iterator) [with _Iterator = __gnu_cxx::__normal_iterator<int*, std::vector<int> >; _Predicate = std::_Bind<bool (*(std::_Placeholder<2>, std::basic_string<char>))(const std::basic_string<char>&, unsigned int)>]':
/usr/include/c++/5/bits/stl_algo.h:120:14: required from '_RandomAccessIterator std::__find_if(_RandomAccessIterator, _RandomAccessIterator, _Predicate, std::random_access_iterator_tag) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<int*, std::vector<int> >; _Predicate = __gnu_cxx::__ops::_Iter_pred<std::_Bind<bool (*(std::_Placeholder<2>, std::basic_string<char>))(const std::basic_string<char>&, unsigned int)> >]'
/usr/include/c++/5/bits/stl_algo.h:161:23: required from '_Iterator std::__find_if(_Iterator, _Iterator, _Predicate) [with _Iterator = __gnu_cxx::__normal_iterator<int*, std::vector<int> >; _Predicate = __gnu_cxx::__ops::_Iter_pred<std::_Bind<bool (*(std::_Placeholder<2>, std::basic_string<char>))(const std::basic_string<char>&, unsigned int)> >]'
/usr/include/c++/5/bits/stl_algo.h:3815:28: required from '_IIter std::find_if(_IIter, _IIter, _Predicate) [with _IIter = __gnu_cxx::__normal_iterator<int*, std::vector<int> >; _Predicate = std::_Bind<bool (*(std::_Placeholder<2>, std::basic_string<char>))(const std::basic_string<char>&, unsigned int)>]'
prog.cpp:21:68: required from here
/usr/include/c++/5/bits/predefined_ops.h:234:30: error: no match for call to '(std::_Bind<bool (*(std::_Placeholder<2>, std::basic_string<char>))(const std::basic_string<char>&, unsigned int)>) (int&)'
{ return bool(_M_pred(*__it)); }
^
In file included from prog.cpp:3:0:
/usr/include/c++/5/functional:1129:2: note: candidate: template<class ... _Args, class _Result> _Result std::_Bind<_Functor(_Bound_args ...)>::operator()(_Args&& ...) [with _Args = {_Args ...}; _Result = _Result; _Functor = bool (*)(const std::basic_string<char>&, unsigned int); _Bound_args = {std::_Placeholder<2>, std::basic_string<char, std::char_traits<char>, std::allocator<char> >}]
operator()(_Args&&... __args)
^
/usr/include/c++/5/functional:1129:2: note: template argument deduction/substitution failed:
/usr/include/c++/5/functional:1125:38: error: invalid initialization of reference of type 'const std::basic_string<char>&' from expression of type 'std::_No_tuple_element'
= decltype( std::declval<_Functor>()(
^
/usr/include/c++/5/functional:1143:2: note: candidate: template<class ... _Args, class _Result> _Result std::_Bind<_Functor(_Bound_args ...)>::operator()(_Args&& ...) const [with _Args = {_Args ...}; _Result = _Result; _Functor = bool (*)(const std::basic_string<char>&, unsigned int); _Bound_args = {std::_Placeholder<2>, std::basic_string<char, std::char_traits<char>, std::allocator<char> >}]
operator()(_Args&&... __args) const
^
/usr/include/c++/5/functional:1143:2: note: template argument deduction/substitution failed:
/usr/include/c++/5/functional:1139:52: error: invalid initialization of reference of type 'const std::basic_string<char>&' from expression of type 'std::_No_tuple_element'
typename add_const<_Functor>::type>::type>()(
^
/usr/include/c++/5/functional:1157:2: note: candidate: template<class ... _Args, class _Result> _Result std::_Bind<_Functor(_Bound_args ...)>::operator()(_Args&& ...) volatile [with _Args = {_Args ...}; _Result = _Result; _Functor = bool (*)(const std::basic_string<char>&, unsigned int); _Bound_args = {std::_Placeholder<2>, std::basic_string<char, std::char_traits<char>, std::allocator<char> >}]
operator()(_Args&&... __args) volatile
^
/usr/include/c++/5/functional:1157:2: note: template argument deduction/substitution failed:
/usr/include/c++/5/functional:1153:69: error: invalid initialization of reference of type 'const std::basic_string<char>&' from expression of type 'std::_No_tuple_element'
typename add_volatile<_Functor>::type>::type>()(
^
/usr/include/c++/5/functional:1171:2: note: candidate: template<class ... _Args, class _Result> _Result std::_Bind<_Functor(_Bound_args ...)>::operator()(_Args&& ...) const volatile [with _Args = {_Args ...}; _Result = _Result; _Functor = bool (*)(const std::basic_string<char>&, unsigned int); _Bound_args = {std::_Placeholder<2>, std::basic_string<char, std::char_traits<char>, std::allocator<char> >}]
operator()(_Args&&... __args) const volatile
^
/usr/include/c++/5/functional:1171:2: note: template argument deduction/substitution failed:
/usr/include/c++/5/functional:1167:63: error: invalid initialization of reference of type 'const std::basic_string<char>&' from expression of type 'std::_No_tuple_element'
typename add_cv<_Functor>::type>::type>()(
^