16template <
typename TYPE, std::
size_t MAX_SIZE>
18 : m_size(0), m_elements() {}
20template <
typename TYPE, std::
size_t MAX_SIZE>
23 : m_size(size), m_elements() {
28template <
typename TYPE, std::
size_t MAX_SIZE>
31 : m_size(parent.m_size), m_elements() {
35 construct(
i, parent[
i]);
39template <
typename TYPE, std::
size_t MAX_SIZE>
45template <
typename TYPE, std::
size_t MAX_SIZE>
53 return *(
reinterpret_cast<pointer>(m_elements) +
pos);
56template <
typename TYPE, std::
size_t MAX_SIZE>
67template <
typename TYPE, std::
size_t MAX_SIZE>
72 return *(
reinterpret_cast<pointer>(m_elements) +
pos);
75template <
typename TYPE, std::
size_t MAX_SIZE>
83template <
typename TYPE, std::
size_t MAX_SIZE>
91 return *(
reinterpret_cast<pointer>(m_elements));
94template <
typename TYPE, std::
size_t MAX_SIZE>
105template <
typename TYPE, std::
size_t MAX_SIZE>
112 return *(
reinterpret_cast<pointer>(m_elements) + m_size - 1);
115template <
typename TYPE, std::
size_t MAX_SIZE>
123 return *(
reinterpret_cast<const_pointer>(m_elements) + m_size - 1);
126template <
typename TYPE, std::
size_t MAX_SIZE>
129 return reinterpret_cast<pointer>(m_elements);
132template <
typename TYPE, std::
size_t MAX_SIZE>
139template <
typename TYPE, std::
size_t MAX_SIZE>
144 assert(array_max_size >= count);
158template <
typename TYPE, std::
size_t MAX_SIZE>
163 assert(m_size < array_max_size);
166 auto id = element_id(
pos);
169 memmove(
static_cast<void*
>(
id.m_ptr + 1),
170 static_cast<const void*
>(
id.m_ptr),
171 (m_size -
id.m_index) * value_size);
174 construct(
id.m_index, value);
183template <
typename TYPE, std::
size_t MAX_SIZE>
188 assert(m_size + count <= array_max_size);
191 auto id = element_id(
pos);
194 memmove(
static_cast<void*
>(
id.m_ptr + count),
195 static_cast<const void*
>(
id.m_ptr),
196 (m_size -
id.m_index) * value_size);
200 construct(
id.m_index +
i, value);
210template <
typename TYPE, std::
size_t MAX_SIZE>
211template <
typename...
Args>
216 assert(m_size < array_max_size);
219 auto id = element_id(
pos);
222 memmove(
static_cast<void*
>(
id.m_ptr + 1),
223 static_cast<const void*
>(
id.m_ptr),
224 (m_size -
id.m_index) * value_size);
227 new (
id.m_ptr) value_type(std::forward<Args>(
args)...);
236template <
typename TYPE, std::
size_t MAX_SIZE>
237template <
typename...
Args>
241 return *(emplace(end(), std::forward<Args>(
args)...));
244template <
typename TYPE, std::
size_t MAX_SIZE>
248 insert(end(), value);
251template <
typename TYPE, std::
size_t MAX_SIZE>
256 auto id = element_id(
pos);
259 destruct(
id.m_index);
262 memmove(
static_cast<void*
>(
id.m_ptr),
263 static_cast<const void*
>(
id.m_ptr + 1),
264 (m_size -
id.m_index - 1) * value_size);
273template <
typename TYPE, std::
size_t MAX_SIZE>
289 static_cast<const void*
>(
last_id.m_ptr),
290 (m_size -
last_id.m_index) * value_size);
299template <
typename TYPE, std::
size_t MAX_SIZE>
305template <
typename TYPE, std::
size_t MAX_SIZE>
314template <
typename TYPE, std::
size_t MAX_SIZE>
321template <
typename TYPE, std::
size_t MAX_SIZE>
340 insert(end(),
new_size - m_size, value);
344template <
typename TYPE, std::
size_t MAX_SIZE>
347 return reinterpret_cast<iterator>(m_elements);
350template <
typename TYPE, std::
size_t MAX_SIZE>
357template <
typename TYPE, std::
size_t MAX_SIZE>
364template <
typename TYPE, std::
size_t MAX_SIZE>
367 return (
reinterpret_cast<iterator>(m_elements) + m_size);
370template <
typename TYPE, std::
size_t MAX_SIZE>
377template <
typename TYPE, std::
size_t MAX_SIZE>
384template <
typename TYPE, std::
size_t MAX_SIZE>
391template <
typename TYPE, std::
size_t MAX_SIZE>
398template <
typename TYPE, std::
size_t MAX_SIZE>
405template <
typename TYPE, std::
size_t MAX_SIZE>
412template <
typename TYPE, std::
size_t MAX_SIZE>
419template <
typename TYPE, std::
size_t MAX_SIZE>
426template <
typename TYPE, std::
size_t MAX_SIZE>
432template <
typename TYPE, std::
size_t MAX_SIZE>
439template <
typename TYPE, std::
size_t MAX_SIZE>
443 return array_max_size;
446template <
typename TYPE, std::
size_t MAX_SIZE>
450 return array_max_size;
453template <
typename TYPE, std::
size_t MAX_SIZE>
462template <
typename TYPE, std::
size_t MAX_SIZE>
464 size_type
pos, const_reference value) {
470 pointer ptr =
reinterpret_cast<pointer
>(m_elements) +
pos;
471 new (ptr) value_type(value);
474template <
typename TYPE, std::
size_t MAX_SIZE>
475VECMEM_HOST_AND_DEVICE
void static_vector<TYPE, MAX_SIZE>::destruct(
482 pointer ptr =
reinterpret_cast<pointer
>(m_elements) +
pos;
486template <
typename TYPE, std::
size_t MAX_SIZE>
487VECMEM_HOST_AND_DEVICE
typename static_vector<TYPE, MAX_SIZE>::ElementId
488static_vector<TYPE, MAX_SIZE>::element_id(const_iterator
pos) {
490 size_type
const index =
static_cast<size_type
>(
pos - begin());
492 pointer
const ptr =
reinterpret_cast<pointer
>(m_elements) + index;
Type mimicking std::reverse_iterator.
Definition reverse_iterator.hpp:25
Class mimicking std::vector on top of a fixed sized array.
Definition static_vector.hpp:30
VECMEM_HOST_AND_DEVICE size_type capacity() const
Return the current (fixed) capacity of the vector.
Definition static_vector.ipp:447
VECMEM_HOST_AND_DEVICE void assign(size_type count, const_reference value)
Assign new values to the vector.
Definition static_vector.ipp:140
VECMEM_HOST_AND_DEVICE const_iterator cend() const
Return a constant forward iterator pointing at the end of the vector.
Definition static_vector.ipp:378
value_type * pointer
Value pointer type.
Definition static_vector.hpp:56
value_type & reference
Value reference type.
Definition static_vector.hpp:52
VECMEM_HOST_AND_DEVICE ~static_vector()
Destructor.
Definition static_vector.ipp:40
VECMEM_HOST_AND_DEVICE reference at(size_type pos)
Return a specific element of the vector in a "safe way" (non-const)
Definition static_vector.ipp:47
VECMEM_HOST_AND_DEVICE void resize(std::size_t new_size)
Resize the vector.
Definition static_vector.ipp:315
VECMEM_HOST_AND_DEVICE bool empty() const
Check whether the vector is empty.
Definition static_vector.ipp:427
VECMEM_HOST_AND_DEVICE size_type size() const
Return the number of elements in the vector.
Definition static_vector.ipp:433
std::size_t size_type
Size type for the array.
Definition static_vector.hpp:39
VECMEM_HOST_AND_DEVICE iterator erase(const_iterator pos)
Remove one element from the vector.
Definition static_vector.ipp:252
VECMEM_HOST_AND_DEVICE static_vector()
Default constructor.
Definition static_vector.ipp:17
VECMEM_HOST_AND_DEVICE iterator begin()
Return a forward iterator pointing at the beginning of the vector.
Definition static_vector.ipp:345
VECMEM_HOST_AND_DEVICE reference operator[](size_type pos)
Return a specific element of the vector (non-const)
Definition static_vector.ipp:68
const value_type * const_pointer
Constant value pointer type.
Definition static_vector.hpp:58
VECMEM_HOST_AND_DEVICE void clear()
Clear the vector.
Definition static_vector.ipp:306
VECMEM_HOST_AND_DEVICE const_reverse_iterator crend() const
Return a constant reverse iterator pointing at the beginning of the vector.
Definition static_vector.ipp:420
VECMEM_HOST_AND_DEVICE pointer data()
Access the underlying memory array (non-const)
Definition static_vector.ipp:127
VECMEM_HOST_AND_DEVICE reference emplace_back(Args &&... args)
Add a new element at the end of the vector.
VECMEM_HOST_AND_DEVICE void push_back(const_reference value)
Add a new element at the end of the vector.
Definition static_vector.ipp:245
VECMEM_HOST_AND_DEVICE iterator emplace(const_iterator pos, Args &&... args)
Insert a new element into the vector.
VECMEM_HOST_AND_DEVICE iterator end()
Return a forward iterator pointing at the end of the vector.
Definition static_vector.ipp:365
VECMEM_HOST_AND_DEVICE const_reverse_iterator crbegin() const
Return a constant reverse iterator pointing at the end of the vector.
Definition static_vector.ipp:399
VECMEM_HOST_AND_DEVICE reference back()
Return the last element of the vector (non-const)
Definition static_vector.ipp:106
const value_type & const_reference
Constant value reference type.
Definition static_vector.hpp:54
VECMEM_HOST_AND_DEVICE reverse_iterator rend()
Return a reverse iterator pointing at the beginning of the vector.
Definition static_vector.ipp:406
VECMEM_HOST_AND_DEVICE void reserve(size_type new_cap)
Reserve additional storage for the vector.
Definition static_vector.ipp:454
VECMEM_HOST_AND_DEVICE const_iterator cbegin() const
Return a constant forward iterator pointing at the beginning of the vector.
Definition static_vector.ipp:358
pointer iterator
Forward iterator type.
Definition static_vector.hpp:61
VECMEM_HOST_AND_DEVICE iterator insert(const_iterator pos, const_reference value)
Insert a new element into the vector.
Definition static_vector.ipp:159
VECMEM_HOST_AND_DEVICE reverse_iterator rbegin()
Return a reverse iterator pointing at the end of the vector.
Definition static_vector.ipp:385
VECMEM_HOST_AND_DEVICE size_type max_size() const
Return the maximum (fixed) number of elements in the vector.
Definition static_vector.ipp:440
TYPE value_type
Type of the array elements.
Definition static_vector.hpp:37
const_pointer const_iterator
Constant forward iterator type.
Definition static_vector.hpp:63
VECMEM_HOST_AND_DEVICE reference front()
Return the first element of the vector (non-const)
Definition static_vector.ipp:84
VECMEM_HOST_AND_DEVICE void pop_back()
Remove the last element of the vector.
Definition static_vector.ipp:300
Main namespace for the vecmem classes/functions.
Definition atomic_ref.hpp:16
std::vector< T, vecmem::polymorphic_allocator< T > > vector
Alias type for vectors with our polymorphic allocator.
Definition vector.hpp:35