Enable swap(...) for temporaries and between different reference types#1646
Enable swap(...) for temporaries and between different reference types#1646upsj wants to merge 1 commit intoNVIDIA:mainfrom
Conversation
|
Can one of the admins verify this patch? |
ericniebler
left a comment
There was a problem hiding this comment.
All the thrust reference-like types inherit from thrust::reference. We could simplify a lot of this by just defining some hidden swap friend functions there.
And that makes me wonder if we want to support arbitrary mixing of reference-like types (e.g., swapping a device_reference with kinds of tagged_reference). Maybe @jrhemstad could comment on that?
|
|
||
| // test thrust::swap() | ||
| thrust::swap(ref1, ref2); | ||
| swap(ref1, ref2); |
There was a problem hiding this comment.
I think the point of this code is to test thrust::swap, no?
The existence of thrust::swap is a bit unfortunate. If you try to swap a type that has both std:: and thrust:: as associated namespace, the compiler has no way to pick between std::swap and thrust::swap. We could consider defining thrust::swap as a global function object that dispatches to (unqualified) swap in a context that has brought std::swap in with a using declaration. Then a simple call to thrust::swap will do the ADL lookup internally, and the potential ambiguity between std::swap and thrust::swap goes away. I think that's a change that is unlikely to break anybody.
@allisonvacanti thoughts?
There was a problem hiding this comment.
Good catch, your proposed fix sounds good to me so long as nothing is specializing thrust::swap.
The THRUST_INLINE_CONSTANT macro may be needed when defining the function object, see https://github.com/NVIDIA/thrust/blob/main/thrust/detail/config/cpp_compatibility.h#L47-L74
An attempt at resolving the issues surrounding swap(...) between temporary device references and between different reference(-like) types
Closes NVIDIA/cccl#802