NVIDIA / NVIDIA/cccl

thrust::detail::unary_transform_functor<UnaryFunction>::operator() is overconstrained

Open
#786 4 comments 0 reactions 1 assignee Claimed by @elstehle View on GitHub
thrust
Dominant language
C++
Stars
2.5k
Forks
486
Avg merge
2d 6h
Merged PRs (30d)
295

Description

I am trying to use thrust with a custom container that can maintain the stored elements split in separate buffers to achieve a Struct of Array layout. Therefore my container's iterator's `reference` type is not `value_type&`, but a different proxy reference type. The situation is quite comparable to `std::vector`. My container and `std::vector` work for some of thrust's algorithm but fail for example with `thrust::transform`:
```c++
std::vector vb;
thrust::transform(vb.begin(), vb.end(), vb.begin(), thrust::negate<>{}); // error
```
Compiling with e.g. gcc11/nvcc 11.4:
```
/usr/local/cuda/include/thrust/detail/function.h(125): error: no instance of function template "thrust::detail::unary_transform_functor::operator() [with UnaryFunction=thrust::negate]" matches the argument list
argument types are: (const thrust::detail::tuple_of_iterator_references)
object type is: thrust::detail::unary_transform_functor>
```
Notice the `thrust::detail::tuple_of_iterator_references`.

The probem is that `thrust::detail::unary_transform_functor::operator()` is constrained with `enable_if_non_const_reference_or_tuple_of_iterator_references::type>::type`, which effectively only allows true C++ references as return values from the output iterator's dereference operator and no proxy references. Removing this constraint/the `enable_if` makes the example with `std::vector` and also my custom container compile and run successfully with thrust.

Please consider removing this constraint from `thrust::detail::unary_transform_functor::operator()`. Thank you!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.