help with boost::bind and boost::regex

I am trying to do the following: std::vector< std::string > filenames; //list of filenames retrieved using filesystem boost::regex r(".*txt$"); std::vector< std::string >::const_iterator iter = std::find_if( filenames.begin(), filenames.end(), boost::bind(boost::regex_match, _1, r) ); //Doesn't compile. I'm trying to find strings that match (or don't match) a particular regular expression. Help in properly using boost::bind and negating it would be helpful. thanks, matthew

Polder, Matthew J wrote:
I am trying to do the following:
std::vector< std::string > filenames; //list of filenames retrieved using filesystem
boost::regex r(".*txt$");
std::vector< std::string >::const_iterator iter = std::find_if( filenames.begin(), filenames.end(), boost::bind(boost::regex_match, _1, r) ); //Doesn't compile.
Unfortunately, boost::regex_match is too overloaded; you'll need to help by selecting an overload by hand: bool (*match)( std::string const &, boost::regex const &, boost::regex_constants::match_flag_type ) = &boost::regex_match; std::vector< std::string >::const_iterator iter = std::find_if( filenames.begin(), filenames.end(), boost::bind( match, _1, r, 0 ) ); // 0 == match_default (which - admittedly - could make one switch to a for loop... but you did ask.) Negating the result of a bind expression is achieved via operator!: !boost::bind( match, _1, r, 0 )
participants (2)
-
Peter Dimov
-
Polder, Matthew J