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_;
155 return *(begin() + i);
159 return *(begin() + i);
165 value_type* tmp = array_;
166 array_ = create_array(new_size);
167 std::move(tmp, tmp +
std::min(size_, new_size), array_);
168 destroy_array(tmp, size_);
172 array_ = create_array(new_size);
179 destroy_array(array_, size_);
185 void fill(
const value_type& v = value_type()) noexcept {
186 std::fill(array_, array_ + size_, v);
195 return new value_type[size];
199 return static_cast<ValueType*
>(
200 operator new (size *
sizeof(ValueType)));
214 for (
size_t i = 0; i < size; ++i)
215 array[i].~ValueType();
216 operator delete (array);
220 operator delete (array);
228 template <
typename T>
235 #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.
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
static void destroy_array(ValueType *array, size_t size)
Simpler non-growing vector without initialization.
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
iterator begin() noexcept
return mutable iterator to first element
void swap(CountingPtr< A, D > &a1, CountingPtr< A, D > &a2) noexcept
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
static uint_pair min()
return an uint_pair instance containing the smallest value possible
void destroy()
deallocate contained array
~SimpleVector()
delete vector
SimpleVectorMode
enum class to select SimpleVector object initialization
size_type size_
size of allocated memory
SimpleVector()
allocate empty simple vector