thrust::pointer

Defined in thrust/detail/pointer.h

template<typename Element, typename Tag, typename Reference, typename Derived>
class pointer

pointer stores a pointer to an object allocated in memory. Like device_ptr, this type ensures type safety when dispatching standard algorithms on ranges resident in memory.

pointer generalizes device_ptr by relaxing the backend system associated with the pointer. Instead of the backend system specified by THRUST_DEVICE_SYSTEM, pointer's system is given by its second template parameter, Tag. For the purpose of Thrust dispatch, device_ptr<Element> and pointer<Element,device_system_tag> are considered equivalent.

The raw pointer encapsulated by a pointer may be obtained through its get member function or the raw_pointer_cast free function.

See also

device_ptr

See also

reference

See also

raw_pointer_cast

Note

pointer is not a smart pointer; it is the client’s responsibility to deallocate memory pointer to by pointer.

Template Parameters
  • Element – specifies the type of the pointed-to object.

  • Tag – specifies the system with which this pointer is associated. This may be any Thrust backend system, or a user-defined tag.

  • Reference – allows the client to specify the reference type returned upon derereference. By default, this type is reference<Element,pointer>.

  • Derived – allows the client to specify the name of the derived type when pointer is used as a base class. This is useful to ensure that arithmetic on values of the derived type return values of the derived type as a result. By default, this type is pointer<Element,Tag,Reference>.

Public Types

using raw_pointer = typename super_t::base_type

The type of the raw pointer

Public Functions

inline pointer()

pointer's default constructor initializes its encapsulated pointer to 0

inline pointer(::cuda::std::nullptr_t)
template<typename OtherElement>
inline explicit pointer(OtherElement *ptr)

This constructor allows construction of a pointer<const T, ...> from a T*.

Parameters

ptr – A raw pointer to copy from, presumed to point to a location in Tag's memory.

Template Parameters

OtherElementOtherElement shall be convertible to Element.

template<typename OtherPointer, typename detail::enable_if_pointer_is_convertible<OtherPointer, pointer>::type* = nullptr>
inline pointer(const OtherPointer &other)

This constructor allows initialization from another pointer-like object.

Parameters

other – The OtherPointer to copy.

Template Parameters

OtherPointer – The tag associated with OtherPointer shall be convertible to Tag, and its element type shall be convertible to Element.

inline derived_type &operator=(::cuda::std::nullptr_t)
template<typename OtherPointer>
inline detail::enable_if_pointer_is_convertible<OtherPointer, pointer, derived_type&>::type operator=(const OtherPointer &other)

Assignment operator allows assigning from another pointer-like object whose element type is convertible to Element.

Parameters

other – The other pointer-like object to assign from.

Template Parameters

OtherPointer – The tag associated with OtherPointer shall be convertible to Tag, and its element type shall be convertible to Element.

Returns

*this

inline Element *get() const

get returns this pointer's encapsulated raw pointer.

Returns

This pointer's raw pointer.

inline Element *operator->() const
inline explicit operator bool() const

Public Static Functions

static inline derived_type pointer_to(typename detail::pointer_traits_detail::pointer_to_param<Element>::type r)

Friends

template<typename charT, typename traits>
inline friend std::basic_ostream<charT, traits> &operator<<(std::basic_ostream<charT, traits> &os, const pointer &p)
inline friend bool operator==(::cuda::std::nullptr_t, pointer p)
inline friend bool operator==(pointer p, ::cuda::std::nullptr_t)
inline friend bool operator!=(::cuda::std::nullptr_t, pointer p)
inline friend bool operator!=(pointer p, ::cuda::std::nullptr_t)