std::transform using C++0x lambda expression

Steve Townsend picture Steve Townsend · Oct 7, 2010 · Viewed 27.9k times · Source

How is this done in C++0x?

std::vector<double> myv1;
std::transform(myv1.begin(), myv1.end(), myv1.begin(),
               std::bind1st(std::multiplies<double>(),3));

Original question and solution is here.

Answer

Edward Strange picture Edward Strange · Oct 7, 2010
std::transform(myv1.begin(), myv1.end(), myv1.begin(), 
   [](double d) -> double { return d * 3; });