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

后端 未结 6 1212
灰色年华
灰色年华 2020-12-28 13:05

How is this done in C++0x?

std::vector myv1;
std::transform(myv1.begin(), myv1.end(), myv1.begin(),
               std::bind1st(std::multiplies         


        
6条回答
  •  [愿得一人]
    2020-12-28 13:51

    I'm using VS2012 which support the C++11 bind adaptor. To bind the first element of the binary function (as bind1st use to do) you need to add an _1 (placeholder argument). Need to include the functional for bind.

    using namespace std::placeholders;
    std::transform( myv1.begin(), myv1.end(), myv1.begin(),
                     std::bind( std::multiplies(),3,_1));
    

提交回复
热议问题