fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <functional>
  4. #include <iterator>
  5. #include <vector>
  6. #include <string>
  7.  
  8. using namespace std::placeholders;
  9.  
  10. bool check(const std::string &s, std::string::size_type sz)
  11. {
  12. return s.size() >= sz;
  13. }
  14.  
  15. int main()
  16. {
  17. std::vector<int> u = { 19, 7, 32, 2, 3, 4, 11, 15, 29, 1, 41 };
  18. std::vector<std::string> v = { "x", "zzz", "yy", "bbbbbb", "tttt", "rrr", "xxxxxx" };
  19.  
  20. std::string s("abc");
  21. auto it = std::find_if(u.begin(), u.end(), std::bind(check, _2, s));
  22. std::cout << *it << std::endl;
  23. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
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>()(
                                                               ^
stdout
Standard output is empty