Gdy próbuję i skompilować ten kod (VS2010) otrzymuję następujący błąd: error C3499: a lambda that has been specified to have a void return type cannot return a value
Explicit Typ Powrót Lambda
void DataFile::removeComments()
{
string::const_iterator start, end;
boost::regex expression("^\\s?#");
boost::match_results<std::string::const_iterator> what;
boost::match_flag_type flags = boost::match_default;
// Look for lines that either start with a hash (#)
// or have nothing but white-space preceeding the hash symbol
remove_if(rawLines.begin(), rawLines.end(), [&expression, &start, &end, &what, &flags](const string& line)
{
start = line.begin();
end = line.end();
bool temp = boost::regex_search(start, end, what, expression, flags);
return temp;
});
}
Jak ja określić, że lambda ma 'void' typ zwrotny. Ponadto, w jaki sposób określić, że lambda ma typ powrotu "bool"?
UPDATE
Poniższe kompiluje. Czy ktoś może mi powiedzieć, dlaczego to się kompiluje, a drugi nie?
void DataFile::removeComments()
{
boost::regex expression("^(\\s+)?#");
boost::match_results<std::string::const_iterator> what;
boost::match_flag_type flags = boost::match_default;
// Look for lines that either start with a hash (#)
// or have nothing but white-space preceeding the hash symbol
rawLines.erase(remove_if(rawLines.begin(), rawLines.end(), [&expression, &what, &flags](const string& line)
{ return boost::regex_search(line.begin(), line.end(), what, expression, flags); }));
}
można jednoznacznie określić jej '->', np '[&] (double d) -> double {// ...' – Flexo
Radzę ci tylko domyślnie przechwycić potrzebne zmienne (tylko '[&] ...'), ponieważ to co masz obecnie jest niepotrzebnie gadatliwy. – Xeo
@Xeo czy możesz mi powiedzieć, dlaczego jest to skrót? Potrzebuję czegoś, ekspresji i flag w lambda i to właśnie złapałem. Co mógłbym wyciąć? – Ryan