0

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?

cigien
  • 57,834
  • 11
  • 73
  • 112
xmllmx
  • 39,765
  • 26
  • 162
  • 323

1 Answers1

2

In range-v3, you would simply do

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

Here's a demo

cigien
  • 57,834
  • 11
  • 73
  • 112