9#include <initializer_list>
34template <
typename T,
typename Allocator = PrimitiveAllocator>
45 enum class PushDecide :
char {
92 for (; size_ < capacity_; ++size_) {
115 template <InputIterator Iter>
148 : alloc_(
other.alloc_) {
155 , capacity_(
other.capacity_)
160 other.arr_ =
nullptr;
197 swap(
a.capacity_,
b.capacity_);
254 template <
typename...
Args>
267 if (size_ == capacity_) {
271 pushingRealloc(
new_cap, PushDecide::kDoPush,
304 throw std::logic_error(
305 "Try to remove the last "
306 "element of the empty Vector");
319 for (
size_t i = 0;
i < size_; ++
i) {
432 void rangeCheck(
size_t index)
const {
433 if (index >= size_)
throw std::out_of_range(
"Vector index out of range.");
454 template <InputIterator Iter>
456 using iter_category = IteratorTraits<Iter>::iterator_category;
467 template <InputIterator Iter>
476 for (; size_ < capacity_; ++size_, ++
first) {
486 template <InputIterator Iter>
517 template <
typename...
Args>
542 if (
do_push == PushDecide::kDoPush) {
549 for (; index < size_; ++index) {
589 size_t capacity_ = 0;
596template <InputIterator Iter,
typename Allocator = PrimitiveAllocator>
Unifined interface for allocators.
Definition allocator.h:69
static void deallocate(Alloc &alloc, T *ptr, size_t n)
Deallocates memory under ptr through allocator.
Definition allocator.h:140
static void destroy(Alloc &alloc, T *ptr)
Destroys object throgh alloctor if destroy method is present. Otherwise calls ~T()
Definition allocator.h:107
static void construct(Alloc &alloc, T *ptr, Args &&... args)
Forwards given arguments to allocator's construct method if present. Otherwise uses placement new.
Definition allocator.h:85
AllocatorAware dynamic array structure.
Definition vector.h:37
detail::BaseVectorIter< T, true > const_iterator
Definition vector.h:59
~Vector()
Definition vector.h:178
pointer getRawData() noexcept
Definition vector.h:342
bool isEmpty() const noexcept
Checks whether Vector has elements.
Definition vector.h:205
size_t capacity() const noexcept
Definition vector.h:337
void boundPopBack()
Destroyes the last object in the array.
Definition vector.h:302
const value_type & const_reference
Definition vector.h:53
Allocator allocator_type
Definition vector.h:57
const_reference operator[](size_t n) const noexcept
Definition vector.h:359
const_pointer getRawData() const noexcept
Definition vector.h:347
const_iterator cbegin() const noexcept
Definition vector.h:411
size_t size() const noexcept
Definition vector.h:332
void reserve(size_t new_capacity)
Preallocates 'new_capacity' memory.
Definition vector.h:223
reference front() noexcept
Definition vector.h:383
const value_type * const_pointer
Definition vector.h:55
auto operator<=>(const Vector &other) const
Definition vector.h:421
size_t size_type
Definition vector.h:56
iterator end() noexcept
Definition vector.h:406
const_reference back() const noexcept
Definition vector.h:401
reference emplaceBack(Args &&... args)
Constructs new element from given args.
Definition vector.h:255
Vector(const Allocator &alloc)
Definition vector.h:63
detail::BaseVectorIter< T, false > iterator
Definition vector.h:58
const_reference front() const noexcept
Definition vector.h:389
const_iterator end() const noexcept
Definition vector.h:409
void popBack() noexcept
Destroyes the last object in the array.
Definition vector.h:290
bool operator==(const Vector &other) const
Definition vector.h:416
Vector(Iter first, Iter last, const Allocator &alloc=Allocator())
Initialize Vector with the given range.
Definition vector.h:116
Vector & operator=(Vector other)
Copy and Move assignment operator.
Definition vector.h:173
Vector(std::initializer_list< value_type > init_list, const Allocator &alloc=Allocator())
Initialize Vector with the given initializer_list.
Definition vector.h:134
reference back() noexcept
Definition vector.h:395
const_iterator cend() const noexcept
Definition vector.h:412
value_type & reference
Definition vector.h:52
reference at(size_t n)
Definition vector.h:365
const_iterator begin() const noexcept
Definition vector.h:408
iterator begin() noexcept
Definition vector.h:405
reference operator[](size_t n) noexcept
Definition vector.h:353
Vector(Vector &&other) noexcept(noexcept(Allocator(move(other.alloc_))))
Definition vector.h:152
Vector(size_t count, const value_type &value=value_type(), const Allocator &alloc=Allocator())
Constructs count elements with given value.
Definition vector.h:80
value_type * pointer
Definition vector.h:54
Vector(const Vector &other)
Copy constructor.
Definition vector.h:147
friend void swap(Vector &a, Vector &b)
Efficiently swaps data of the Vectors.
Definition vector.h:191
Vector() noexcept(noexcept(Allocator()))
Definition vector.h:61
void pushBack(value_type value)
Wrapper for emplaceBack. See docs for emplaceBack.
Definition vector.h:228
void clear() noexcept
Empties the Vector.
Definition vector.h:318
const_reference at(size_t n) const
Definition vector.h:374
T value_type
Definition vector.h:51
contiguous iterator for Vector. Trivial iterator-wrapper for pointer to array(aka T*)
Definition vector_iterator.h:22
Definition algo_base.h:14
constexpr remove_ref_t< T > && move(T &&value) noexcept
Convert a value to xvalue.
Definition move.h:19
bool equal(Iter1 first1, Iter1 last1, Iter2 first2, Pred pred=Pred())
Checks whether given ranges are equal.
Definition algo_base.h:77
auto distance(Iter first, Iter last) -> IteratorTraits< Iter >::difference_type
Returns the number of elements in [first, last).
Definition iterators.h:135
constexpr T && forward(remove_ref_t< T > &value) noexcept
Forward a lvalue.
Definition move.h:33
auto lexicographical_compare_three_way(Iter1 first1, Iter1 last1, Iter2 first2, Iter2 last2, Cmp cmp=Cmp())
Compares ranges lexicographically using C++20 three-way comparation.
Definition algo_base.h:37