xmllmx
xmllmx

Reputation: 42255

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?

Upvotes: 1

Views: 808

Answers (1)

cigien
cigien

Reputation: 60218

In range-v3, you would simply do

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

Here's a demo

Upvotes: 3

Related Questions