vector< T, Allocator >

vector< T, Allocator >#

stdgpu: stdgpu::vector< T, Allocator >
stdgpu Latest
Efficient STL-like Data Structures on the GPU

Detailed Description

template<typename T, typename Allocator = safe_device_allocator<T>>
class stdgpu::vector< T, Allocator >

A generic container similar to std::vector on the GPU.

Template Parameters
TThe type of the stored elements
AllocatorThe allocator type

Differences to std::vector:

  • index_type instead of size_type
  • Manual allocation and destruction of container required
  • max_size and capacity limited to initially allocated size
  • No guaranteed valid state when reaching capacity limit
  • Additional non-standard capacity functions full() and valid()
  • insert() and erase() only implemented for special case with device_end()
  • Some member functions missing

Public Types

using allocator_type = Allocator
 
using const_pointer = const value_type *
 
using const_reference = const value_type &
 
using difference_type = std::ptrdiff_t
 
using index_type = index_t
 
using pointer = value_type *
 
using reference = value_type &
 
using value_type = T
 

Public Member Functions

 vector ()=default
 
STDGPU_DEVICE_ONLY reference at (const index_type n)
 
STDGPU_DEVICE_ONLY const_reference at (const index_type n) const
 
STDGPU_DEVICE_ONLY reference back ()
 
STDGPU_DEVICE_ONLY const_reference back () const
 
STDGPU_HOST_DEVICE index_t capacity () const noexcept
 
void clear ()
 
template<typename ExecutionPolicy , STDGPU_DETAIL_OVERLOAD_IF(is_execution_policy_v< remove_cvref_t< ExecutionPolicy > >) >
void clear (ExecutionPolicy &&policy)
 
const T * data () const noexcept
 
T * data () noexcept
 
device_ptr< T > device_begin ()
 
device_ptr< const T > device_begin () const
 
device_ptr< const T > device_cbegin () const
 
device_ptr< const T > device_cend () const
 
device_ptr< T > device_end ()
 
device_ptr< const T > device_end () const
 
stdgpu::device_range< T > device_range ()
 
stdgpu::device_range< const T > device_range () const
 
template<class... Args>
STDGPU_DEVICE_ONLY bool emplace_back (Args &&... args)
 
STDGPU_HOST_DEVICE bool empty () const
 
void erase (device_ptr< const T > begin, device_ptr< const T > end)
 
template<typename ExecutionPolicy , STDGPU_DETAIL_OVERLOAD_IF(is_execution_policy_v< remove_cvref_t< ExecutionPolicy > >) >
void erase (ExecutionPolicy &&policy, device_ptr< const T > begin, device_ptr< const T > end)
 
STDGPU_DEVICE_ONLY reference front ()
 
STDGPU_DEVICE_ONLY const_reference front () const
 
STDGPU_HOST_DEVICE bool full () const
 
STDGPU_HOST_DEVICE allocator_type get_allocator () const noexcept
 
template<typename ValueIterator , STDGPU_DETAIL_OVERLOAD_IF(detail::is_iterator_v< ValueIterator >) >
void insert (device_ptr< const T > position, ValueIterator begin, ValueIterator end)
 
template<typename ExecutionPolicy , typename ValueIterator , STDGPU_DETAIL_OVERLOAD_IF( is_execution_policy_v< remove_cvref_t< ExecutionPolicy > > &&detail::is_iterator_v< ValueIterator >) >
void insert (ExecutionPolicy &&policy, device_ptr< const T > position, ValueIterator begin, ValueIterator end)
 
STDGPU_HOST_DEVICE index_t max_size () const noexcept
 
STDGPU_DEVICE_ONLY reference operator[] (const index_type n)
 
STDGPU_DEVICE_ONLY const_reference operator[] (const index_type n) const
 
STDGPU_DEVICE_ONLY pair< T, bool > pop_back ()
 
STDGPU_DEVICE_ONLY bool push_back (const T &element)
 
void shrink_to_fit ()
 
STDGPU_HOST_DEVICE index_t size () const
 
bool valid () const
 
template<typename ExecutionPolicy , STDGPU_DETAIL_OVERLOAD_IF(is_execution_policy_v< remove_cvref_t< ExecutionPolicy > >) >
bool valid (ExecutionPolicy &&policy) const
 

Static Public Member Functions

static vector< T, Allocator > createDeviceObject (const index_t &capacity, const Allocator &allocator=Allocator())
 
template<typename ExecutionPolicy , STDGPU_DETAIL_OVERLOAD_IF(is_execution_policy_v< remove_cvref_t< ExecutionPolicy > >) >
static vector< T, Allocator > createDeviceObject (ExecutionPolicy &&policy, const index_t &capacity, const Allocator &allocator=Allocator())
 
template<typename ExecutionPolicy , STDGPU_DETAIL_OVERLOAD_IF(is_execution_policy_v< remove_cvref_t< ExecutionPolicy > >) >
static void destroyDeviceObject (ExecutionPolicy &&policy, vector< T, Allocator > &device_object)
 
static void destroyDeviceObject (vector< T, Allocator > &device_object)