thrust

◆ device_reference() [2/2]

template<typename T>
__host__ __device__ thrust::device_reference< T >::device_reference ( const pointer ptr)
inlineexplicit

This copy constructor initializes this device_reference to refer to an object pointed to by the given device_ptr. After this device_reference is constructed, it shall refer to the object pointed to by ptr.

Parameters
ptrA device_ptr to copy from.

The following code snippet demonstrates the semantic of this copy constructor.

#include <assert.h>
...
thrust::device_vector<int> v(1,0);
// ref equals the object pointed to by ptr
assert(ref == *ptr);
// the address of ref equals ptr
assert(&ref == ptr);
// modifying *ptr modifies ref
*ptr = 13;
assert(ref == 13);

References thrust::device_reference< T >::operator=(), and thrust::swap().