Missing two range overload for `thrust::transform_reduce`
- Dominant language
- C++
- Stars
- 2.5k
- Forks
- 486
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 295
Description
I was recently writing the following code using C++17:
```cpp
auto max_gap(std::vector nums) -> int {
return std::transform_reduce(
nums.begin() + 1, nums.end(), nums.begin(), 0,
[](auto a, auto b) { return std::max(a, b); },
std::minus{});
}
```
and when I went to write the equivalent in `Thrust` it wasn't possible because there is no two range overload of `thrust::transform_reduce`. The C++17 `std::transform_reduce` has both a one range and two range overload. Because of this, the morally equivalent code in `Thrust` is:
```cpp
auto max_gap(std::vector nums) -> int {
return thrust::transform_reduce(
thrust::make_zip_iterator(thrust::make_tuple(nums.begin() + 1, nums.begin())),
thrust::make_zip_iterator(thrust::make_tuple(nums.end(), nums.end() - 1)),
[](auto t) { return thrust::get<0>(t) - thrust::get<1>(t); }, 0,
[](auto a, auto b) { return std::max(a, b); });
}
```
which is far from ideal.
I would recommend adding the two range overload of `thrust::transform_reduce` in order to:
1) Be more consistent with what is available in standard C++
2) Avoid the necessary code in the 2nd example above.
Contributor guide
Assessment
This issue has not been assessed yet.