简体   繁体   中英

How to use range-v3's ranges::actions::transform?

I want to use ranges-v3 to transform an array in place. I can use ranges::transform successfully, but failed to use actions::transform .

int arr[]{1, 2, 3};
auto fn = [](auto e) { return e + 1; };
ranges::transform(arr, std::begin(arr), fn); // ok
arr |= actions::transform(std::begin(arr), fn); // error

Error Message:

fatal error: no matching function for call to object of type 'const ranges::actions::transform_fn'
        arg |= actions::transform(std::begin(arr), std::begin(arr),
               ^~~~~~~~~~~~~~~~~~

How to use actions::transform in such a case?

In range-v3 , you would simply do

arr |= ranges::actions::transform(fn);

Here's a demo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM