dimanche 30 juillet 2017

How can you insert the return value of a lambda in a vector?

I am trying to use a lambda for a frequently occurring vector insertion to prevent calling an equivalent function:

std::vector<vector<double>> A
A.push_back(
            //*
            someFunction(lots, of, parameters, to, deal, with)
            //*/
            /*
            [&]() -> vector<double> 
            {
                //body identical to that of someFunction        
            }
            //*/
           );

The return and body of someFunction is identical to that of the lambda.

  • Is there something wrong with the syntax?
  • Is this even worth the effort (considering the reduced readability) or is the effect going to be identical?

Aucun commentaire:

Enregistrer un commentaire