Quando provo e compilare il codice (VS2010) Sto ottenendo il seguente errore: error C3499: a lambda that has been specified to have a void return type cannot return a value
esplicita ritorno Tipo di 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;
});
}
Come ho fatto a specificare che il lambda ha un tipo di ritorno 'vuoto'. Inoltre, come posso specificare che il lambda ha il tipo di ritorno 'bool'?
UPDATE
I seguenti compila. Qualcuno può dirmi perché questo compila e l'altro no?
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); }));
}
È possibile specificare esplicitamente con '->', per esempio '[&] (double d) -> double {// ...' – Flexo
Ti consiglierei di catturare solo implicitamente le variabili di cui hai bisogno (solo '[&] ...'), come quello che hai attualmente è inutilmente prolisso. – Xeo
@Xeo puoi dirmi perché è prolisso? Ho bisogno di cosa, espressione e bandiere nel lambda e questo è ciò che ho catturato. Che cosa potrei tagliare? – Ryan