I have a list of words and I want to get all words that match with words from a file. My initial solution looks like this:
void matchWords(std::ostream_iterator<std::string> out,std::set<std::string> const &list){
using in_iter=std::istream_iterator<std::string>;
std::ifstream allwords{"/usr/share/dict/words"};
in_iter input{allwords};
copy_if(input,in_iter{},out,[&list](std::string const& s){return list.count(s);});
}
Which is case sensitive. However I want to provide a case insensitive solution as well. I tried something like this:
void matchWordsCaseInsensitive(std::ostream_iterator<std::string> out,std::set<std::string> const &list){
using in_iter=std::istream_iterator<std::string>;
std::ifstream allwords{"/usr/share/dict/words"};
in_iter input{allwords};
copy_if(input,in_iter{},out,[&list](std::string const& s){
std::lexicographical_compare(list.begin(), list.end(), s.begin(), s.end(),
[](char const lhc, char const rhc){return tolower(lhc) < tolower(rhc);});
});
}
But this raises a compile error: No matching function for call to object of type lambda. Can somebody explain why this happens?
Aucun commentaire:
Enregistrer un commentaire