15#ifndef TLX_CONTAINER_SIMPLE_VECTOR_HEADER
16#define TLX_CONTAINER_SIMPLE_VECTOR_HEADER
48template <
typename ValueType,
92 { v.size_ = 0, v.array_ =
nullptr; }
96 if (&v ==
this)
return *
this;
99 v.size_ = 0, v.array_ =
nullptr;
105 std::swap(
size_, obj.size_);
106 std::swap(
array_, obj.array_);
172 return *(
begin() + i);
176 return *(
begin() + i);
181 return *(
begin() + i);
185 return *(
begin() + i);
193 std::move(tmp, tmp + std::min(
size_, new_size),
array_);
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);
Simpler non-growing vector without initialization.
static ValueType * create_array(size_t size)
size_type size() const noexcept
return number of items in vector
iterator data() noexcept
return iterator to beginning of vector
const_iterator begin() const noexcept
return constant iterator to first element
void destroy()
deallocate contained array
SimpleVector & operator=(const SimpleVector &)=delete
non-copyable: delete assignment operator
void resize(size_type new_size)
resize the array to contain exactly new_size items
SimpleVector()
allocate empty simple vector
const_iterator end() 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
iterator begin() noexcept
return mutable iterator to first element
const_iterator cend() const noexcept
return constant iterator beyond last element
reference back() noexcept
returns reference to the first element in the container
SimpleVector(const size_type &sz)
allocate vector's memory
void swap(SimpleVector &obj) noexcept
swap vector with another one
reference front() noexcept
returns reference to the last element in the container
const_reference at(size_type i) const noexcept
return constant reference to the i-th position of the vector
reference operator[](size_type i) noexcept
return the i-th position of the vector
const value_type & const_reference
SimpleVector(SimpleVector &&v) noexcept
move-constructor
const_iterator cbegin() const noexcept
return constant iterator to first element
reference at(size_type i) noexcept
return the i-th position of the vector
SimpleVector(const SimpleVector &)=delete
non-copyable: delete copy-constructor
const value_type * const_iterator
~SimpleVector()
delete vector
static void destroy_array(ValueType *array, size_t size)
const_reference front() const noexcept
returns reference to the first element in the container
iterator end() noexcept
return mutable iterator beyond last element
const_reference back() const noexcept
returns reference to the last element in the container
SimpleVectorMode
enum class to select SimpleVector object initialization
SimpleVector< T > simple_vector
make template alias due to similarity with std::vector
@ NoInitNoDestroy
Do not initialize objects at allocation and do not destroy them.
@ Normal
Initialize objects at allocation and destroy on deallocation.
@ NoInitButDestroy
Do not initialize objects at allocation, but destroy on deallocation.