Removing strings from a vector via boost :: bind

I am trying to remove short lines from a vector.

std::vector<std::string> vec; // ... vec.erase(std::remove_if(vec.begin(), vec.end(), boost::bind(std::less<size_t>(), boost::bind(&std::string::length, _1), 5), vec.end()); 

The compiler produces a very large error message:

 qwer.cpp:20: error: no matching function for call to 'remove_if(__gnu_cxx::__nor mal_iterator<std::basic_string<char, std::char_traits<char>, std::allocator<char > >*, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator <char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::al locator<char> > > > >, __gnu_cxx::__normal_iterator<std::basic_string<char, std: :char_traits<char>, std::allocator<char> >*, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_strin g<char, std::char_traits<char>, std::allocator<char> > > > >, boost::_bi::bind_t <boost::_bi::unspecified, std::less<unsigned int>, boost::_bi::list2<boost::_bi: :bind_t<unsigned int, boost::_mfi::cmf0<unsigned int, std::basic_string<char, st d::char_traits<char>, std::allocator<char> > >, boost::_bi::list1<boost::arg<1> > >, boost::_bi::value<int> > >, __gnu_cxx::__normal_iterator<std::basic_string< char, std::char_traits<char>, std::allocator<char> >*, std::vector<std::basic_st ring<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::b asic_string<char, std::char_traits<char>, std::allocator<char> > > > >)' 

The following solution works:

 vec.erase(std::remove_if(vec.begin(), vec.end(), boost::bind(&std::string::length, _1) < 5), vec.end()); 

But I'm still wondering what I did wrong in the first version. Thanks!

+4
source share
1 answer

It looks like you have disabled your bracket (there must be two after 5, one to close the binding, one to close remove_if.) I am surprised that this did not give another error message regarding an invalid token or something else, since the paranas are clearly unbalanced ( Did you remove the extra close wig from the end, getting ready for SO?). This seems to be the case, because if you read the remove_if template arguments in the error message, the next one is boost bind_t, followed by another gnu :: iterator.

+5
source

All Articles