15 #ifndef TLX_CONTAINER_SIMPLE_VECTOR_HEADER 16 #define TLX_CONTAINER_SIMPLE_VECTOR_HEADER 48 template <
typename ValueType,
53 using value_type = ValueType;
74 : size_(0), array_(nullptr)
79 : size_(sz), array_(nullptr) {
81 array_ = create_array(size_);
91 : size_(v.size_), array_(v.array_)
92 { v.size_ = 0, v.array_ =
nullptr; }
96 if (&v ==
this)
return *
this;
97 destroy_array(array_, size_);
98 size_ = v.size_, array_ = v.array_;
99 v.size_ = 0, v.array_ =
nullptr;
111 destroy_array(array_, size_);
142 return array_ + size_;
146 return array_ + size_;
163 return array_[size_ - 1];
167 return array_[size_ - 1];
172 return *(begin() + i);
176 return *(begin() + i);
181 return *(begin() + i);
185 return *(begin() + i);
191 value_type* tmp = array_;
192 array_ = create_array(new_size);
193 std::move(tmp, tmp +
std::min(size_, new_size), array_);
194 destroy_array(tmp, size_);
198 array_ = create_array(new_size);
205 destroy_array(array_, size_);
211 void fill(
const value_type& v = value_type()) noexcept {
212 std::fill(array_, array_ + size_, v);
221 return new value_type[size];
225 return static_cast<ValueType*
>(
226 operator new (size *
sizeof(ValueType)));
240 for (
size_t i = 0; i < size; ++i)
241 array[i].~ValueType();
242 operator delete (array);
246 operator delete (array);
254 template <
typename T>
261 #endif // !TLX_CONTAINER_SIMPLE_VECTOR_HEADER iterator end() noexcept
return mutable iterator beyond last element
Do not initialize objects at allocation and do not destroy them.
const_reference front() const noexcept
returns reference to the first element in the container
Do not initialize objects at allocation, but destroy on deallocation.
void resize(size_type new_size)
resize the array to contain exactly new_size items
SimpleVector(const size_type &sz)
allocate vector's memory
const_iterator begin() const noexcept
return constant iterator to first element
const_reference back() const noexcept
returns reference to the last element in the container
static void destroy_array(ValueType *array, size_t size)
Simpler non-growing vector without initialization.
reference front() noexcept
returns reference to the last element in the container
reference at(size_type i) noexcept
return the i-th position of the vector
const_iterator cbegin() const noexcept
return constant iterator to first element
Initialize objects at allocation and destroy on deallocation.
const value_type * const_iterator
iterator data() noexcept
return iterator to beginning of vector
const_iterator cend() const noexcept
return constant iterator beyond last element
void fill(const value_type &v=value_type()) noexcept
Zero the whole array content.
const_iterator data() const noexcept
return iterator to beginning of vector
void swap(SimpleVector &obj) noexcept
swap vector with another one
const value_type & const_reference
static uint32_t min(uint32_t x, uint32_t y)
iterator begin() noexcept
return mutable iterator to first element
void swap(CountingPtr< A, D > &a1, CountingPtr< A, D > &a2) noexcept
swap enclosed object with another counting pointer (no reference counts need change) ...
reference back() noexcept
returns reference to the first element in the container
static ValueType * create_array(size_t size)
size_type size() const noexcept
return number of items in vector
const_iterator end() const noexcept
return constant iterator beyond last element
SimpleVector(SimpleVector &&v) noexcept
move-constructor
value_type * array_
pointer to allocated memory area
void destroy()
deallocate contained array
~SimpleVector()
delete vector
SimpleVectorMode
enum class to select SimpleVector object initialization
size_type size_
size of allocated memory
const_reference at(size_type i) const noexcept
return constant reference to the i-th position of the vector
SimpleVector()
allocate empty simple vector