Boost logo

Boost Users :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2007-02-01 14:47:55


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 )


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net