24 #include "RAJA/config.hpp"
54 template<
typename T,
typename Allocator = std::allocator<T>>
57 using allocator_traits_type = std::allocator_traits<Allocator>;
58 using propagate_on_container_copy_assignment =
59 typename allocator_traits_type::propagate_on_container_copy_assignment;
60 using propagate_on_container_move_assignment =
61 typename allocator_traits_type::propagate_on_container_move_assignment;
62 using propagate_on_container_swap =
63 typename allocator_traits_type::propagate_on_container_swap;
72 using pointer =
typename allocator_traits_type::pointer;
96 allocator_traits_type::select_on_container_copy_construction(
102 copy_construct_items_back(other.
size(), other.
data());
109 : m_data(other.m_data),
110 m_allocator(
std::move(other.m_allocator)),
111 m_capacity(other.m_capacity),
114 other.m_data =
nullptr;
115 other.m_capacity = 0;
126 copy_assign_private(rhs, propagate_on_container_copy_assignment {});
138 move_assign_private(std::move(rhs),
139 propagate_on_container_move_assignment {});
158 swap_private(other, propagate_on_container_swap {});
194 bool empty()
const {
return (m_size == 0); }
224 void clear() { destroy_items_after(0); }
234 if (new_size >=
size())
237 construct_items_back(new_size);
241 destroy_items_after(new_size);
253 if (new_size >=
size())
256 construct_items_back(new_size, new_value);
260 destroy_items_after(new_size);
298 template<
typename... Os>
301 emplace_front_private(std::forward<Os>(os)...);
313 template<
typename... Os>
316 emplace_back_private(std::forward<Os>(os)...);
322 void pop_back() { destroy_items_after(m_size - 1); }
334 void copy_assign_private(
RAJAVec const& rhs, std::true_type)
336 if (m_allocator != rhs.m_allocator)
340 m_allocator = rhs.m_allocator;
343 copy_assign_private(rhs, std::false_type {});
350 void copy_assign_private(
RAJAVec const& rhs, std::false_type)
353 if (
size() < rhs.size())
355 copy_assign_items(0,
size(), rhs.data());
356 copy_construct_items_back(rhs.size(), rhs.data());
360 copy_assign_items(0, rhs.size(), rhs.data());
361 destroy_items_after(
size());
369 void move_assign_private(
RAJAVec&& rhs, std::true_type)
375 m_allocator = std::move(rhs.m_allocator);
376 m_capacity = rhs.m_capacity;
379 rhs.m_data =
nullptr;
388 void move_assign_private(
RAJAVec&& rhs, std::false_type)
390 if (m_allocator == rhs.m_allocator)
396 m_capacity = rhs.m_capacity;
399 rhs.m_data =
nullptr;
406 if (
size() < rhs.size())
408 move_assign_items(0,
size(), rhs.data());
409 move_construct_items_back(rhs.size(), rhs.data());
413 move_assign_items(0, rhs.size(), rhs.data());
414 destroy_items_after(
size());
422 void swap_private(
RAJAVec& other, std::true_type)
425 swap(m_data, other.m_data);
426 swap(m_allocator, other.m_allocator);
427 swap(m_capacity, other.m_capacity);
428 swap(m_size, other.m_size);
434 void swap_private(
RAJAVec& other, std::false_type)
437 swap(m_data, other.m_data);
438 swap(m_capacity, other.m_capacity);
439 swap(m_size, other.m_size);
449 m_data[i] = o_data[i];
460 m_data[i] = std::move(o_data[i]);
467 template<
typename... Os>
468 void construct_items_back(
size_type new_size, Os&&... os)
470 for (; m_size < new_size; ++m_size)
472 allocator_traits_type::construct(m_allocator, m_data + m_size,
473 std::forward<Os>(os)...);
482 for (; m_size < new_size; ++m_size)
484 allocator_traits_type::construct(m_allocator, m_data + m_size,
494 for (; m_size < new_size; ++m_size)
496 allocator_traits_type::construct(m_allocator, m_data + m_size,
497 std::move(o_data[m_size]));
504 void destroy_items_after(
size_type new_end)
506 for (; m_size > new_end; --m_size)
508 allocator_traits_type::destroy(m_allocator, m_data + m_size - 1);
515 template<
typename... Os>
516 void emplace_front_private(Os&&... os)
523 allocator_traits_type::construct(m_allocator, m_data + i,
524 std::move(m_data[i - 1]));
525 for (--i; i > 0; --i)
527 m_data[i] = std::move(m_data[i - 1]);
529 allocator_traits_type::destroy(m_allocator, m_data);
531 allocator_traits_type::construct(m_allocator, m_data,
532 std::forward<Os>(os)...);
539 template<
typename... Os>
540 void emplace_back_private(Os&&... os)
543 allocator_traits_type::construct(m_allocator, m_data + m_size,
544 std::forward<Os>(os)...);
553 static constexpr
const size_type s_init_cap = 8;
554 static constexpr
const double s_grow_fac = 1.5;
564 next_cap =
static_cast<size_type>(m_capacity * s_grow_fac);
566 return std::max(target_size, next_cap);
574 if (m_capacity < target_size)
576 change_cap(get_next_cap(target_size));
585 if (m_capacity > target_size)
587 change_cap(
std::max(m_size, target_size));
600 tdata = allocator_traits_type::allocate(m_allocator, next_cap);
607 allocator_traits_type::construct(m_allocator, tdata + i,
608 std::move(m_data[i]));
609 allocator_traits_type::destroy(m_allocator, m_data + i);
611 allocator_traits_type::deallocate(m_allocator, m_data, m_capacity);
615 m_capacity = next_cap;
Header file defining prototypes for routines used to manage memory for CPU reductions and other opera...
Class template that provides a simple vector implementation sufficient to insulate RAJA entities from...
Definition: RAJAVec.hpp:56
void push_front(value_type &&item)
Definition: RAJAVec.hpp:295
iterator begin()
Definition: RAJAVec.hpp:183
void emplace_back(Os &&... os)
Definition: RAJAVec.hpp:314
RAJAVec(RAJAVec &&other)
Definition: RAJAVec.hpp:108
const_iterator cend() const
Definition: RAJAVec.hpp:178
void pop_back()
Definition: RAJAVec.hpp:322
size_type capacity() const
Definition: RAJAVec.hpp:204
RAJAVec & operator=(RAJAVec &&rhs)
Definition: RAJAVec.hpp:134
void clear()
Definition: RAJAVec.hpp:224
const_iterator cbegin() const
Definition: RAJAVec.hpp:189
void emplace_front(Os &&... os)
Definition: RAJAVec.hpp:299
RAJA_INLINE void resize(size_type new_size)
Definition: RAJAVec.hpp:232
iterator end()
Definition: RAJAVec.hpp:172
~RAJAVec()
Definition: RAJAVec.hpp:147
const_pointer data() const
Definition: RAJAVec.hpp:167
void swap(RAJAVec &other)
Definition: RAJAVec.hpp:156
size_type size() const
Definition: RAJAVec.hpp:199
void reserve(size_type target_capacity)
Definition: RAJAVec.hpp:214
const_reference front() const
Definition: RAJAVec.hpp:278
const value_type * const_iterator
Definition: RAJAVec.hpp:75
const_reference back() const
Definition: RAJAVec.hpp:286
void push_back(const_reference item)
Definition: RAJAVec.hpp:307
RAJA_INLINE void resize(size_type new_size, const_reference new_value)
Definition: RAJAVec.hpp:251
std::size_t size_type
Definition: RAJAVec.hpp:68
const value_type & const_reference
Definition: RAJAVec.hpp:71
bool empty() const
Definition: RAJAVec.hpp:194
reference front()
Definition: RAJAVec.hpp:275
const_iterator end() const
Definition: RAJAVec.hpp:175
RAJAVec & operator=(const RAJAVec &rhs)
Definition: RAJAVec.hpp:122
value_type & reference
Definition: RAJAVec.hpp:70
RAJAVec(const RAJAVec &other)
Definition: RAJAVec.hpp:93
allocator_type get_allocator() const
Definition: RAJAVec.hpp:209
std::ptrdiff_t difference_type
Definition: RAJAVec.hpp:69
void push_front(const_reference item)
Definition: RAJAVec.hpp:292
typename allocator_traits_type::const_pointer const_pointer
Definition: RAJAVec.hpp:73
value_type * iterator
Definition: RAJAVec.hpp:74
typename allocator_traits_type::pointer pointer
Definition: RAJAVec.hpp:72
reference operator[](difference_type i)
Definition: RAJAVec.hpp:267
void push_back(value_type &&item)
Definition: RAJAVec.hpp:310
const_reference operator[](difference_type i) const
Definition: RAJAVec.hpp:270
T value_type
Definition: RAJAVec.hpp:66
void shrink_to_fit()
Definition: RAJAVec.hpp:219
reference back()
Definition: RAJAVec.hpp:283
const_iterator begin() const
Definition: RAJAVec.hpp:186
RAJAVec(size_type init_cap=0, const allocator_type &a=allocator_type())
Definition: RAJAVec.hpp:80
Allocator allocator_type
Definition: RAJAVec.hpp:67
pointer data()
Definition: RAJAVec.hpp:164
Definition: AlignedRangeIndexSetBuilders.cpp:35
RAJA_HOST_DEVICE constexpr RAJA_INLINE Result max(Args... args)
Definition: foldl.hpp:155
Definition: ListSegment.hpp:416
RAJA_INLINE void swap(RAJA::TypedListSegment< StorageT > &a, RAJA::TypedListSegment< StorageT > &b)
Specialization of std::swap for TypedListSegment.
Definition: ListSegment.hpp:420