VCTR
Loading...
Searching...
No Matches
Vector.h
1/*
2 ==============================================================================
3 DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
5 Copyright 2022- by sonible GmbH.
6
7 This file is part of VCTR - Versatile Container Templates Reconceptualized.
8
9 VCTR is free software: you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License version 3
11 only, as published by the Free Software Foundation.
12
13 VCTR is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU Lesser General Public License version 3 for more details.
17
18 You should have received a copy of the GNU Lesser General Public License
19 version 3 along with VCTR. If not, see <https://www.gnu.org/licenses/>.
20 ==============================================================================
21*/
22
23namespace vctr
24{
25
26// clang-format off
28template <class ElementType>
30{
31 using DefaultVectorAllocatorType = std::allocator<ElementType>;
32};
33
35template <is::number ElementType>
36struct DefaultVectorAllocator<ElementType>
37{
39};
40// clang-format on
41
42namespace detail
43{
44
45template <class Allocator>
46struct UnderlyingAllocatorExtractor
47{
48 using Type = Allocator;
49};
50
51template <class ElementType>
52struct UnderlyingAllocatorExtractor<DefaultVectorAllocator<ElementType>>
53{
54 using Type = typename DefaultVectorAllocator<ElementType>::DefaultVectorAllocatorType;
55};
56
57template <class T, template <class> class Allocator>
58struct StdVector
59{
60 using Type = std::vector<T, typename UnderlyingAllocatorExtractor<Allocator<T>>::Type>;
61};
62
63template <template <class> class Allocator>
64struct StdVector<bool, Allocator>
65{
66 using Type = VectorBoolWorkaround<typename UnderlyingAllocatorExtractor<Allocator<std::byte>>::Type>;
67};
68
69template <class T, template <class> class Allocator>
70using StdVectorType = typename StdVector<T, Allocator>::Type;
71
72} // namespace detail
73
97template <is::nonConst ElementType, template <class> class Allocator = DefaultVectorAllocator>
98class Vector : public VctrBase<ElementType, detail::StdVectorType<ElementType, Allocator>, std::dynamic_extent>
99{
100private:
101 using StdVectorType = detail::StdVectorType<ElementType, Allocator>;
103
104 template <class OtherAllocator>
105 static constexpr bool isDifferentAllocatorTypeWithSameValueType = (! std::is_same_v<typename detail::UnderlyingAllocatorExtractor<Allocator<ElementType>>::Type, OtherAllocator>) && std::is_same_v<ElementType, typename OtherAllocator::value_type>;
106
107 using ConstIterator = typename StdVectorType::const_iterator;
108
109public:
110 //==============================================================================
111 using value_type = typename Vctr::value_type;
112
113 //==============================================================================
114 // Constructors
115 //==============================================================================
117 constexpr Vector() = default;
118
120 template <std::convertible_to<Allocator<ElementType>> Alloc>
121 Vector (Alloc&& allocator) : Vctr (StdVectorType (allocator)) {}
122
124 constexpr Vector (size_t size) : Vctr (StdVectorType (size)) {}
125
127 constexpr Vector (size_t size, ElementType initialValue) : Vctr (StdVectorType (size, initialValue)) {}
128
130 constexpr Vector (std::initializer_list<ElementType> il) : Vctr (StdVectorType (il)) {}
131
133 template <is::suitableInitializerForElementType<ElementType> First, std::same_as<First>... Other>
134 requires (sizeof...(Other) > 0) && (! std::convertible_to<First, size_t>)
135 constexpr Vector (First&& first, Other&&... other)
136 {
137 reserve (1 + sizeof...(other));
138 push_back (std::forward<First> (first));
139 (push_back (std::forward<Other> (other)), ...);
140 }
141
143 constexpr Vector (const Vector& other) : Vctr (StdVectorType (other.storage)) {}
144
146 constexpr Vector (Vector&& other) : Vctr (std::move (other.storage)) {}
147
156 template <is::triviallyCopyableWithDataAndSize OtherContainer>
157 requires (! std::same_as<Vector, OtherContainer>)
158 constexpr Vector (const OtherContainer& other)
159 {
160 Vctr::copyFrom (other.data(), other.size());
161 }
162
170 template <is::iteratorCopyable OtherContainer>
171 constexpr Vector (const OtherContainer& other) : Vector (other.begin(), other.end()) {}
172
174 constexpr Vector (const ElementType* data, size_t size)
175 {
177 }
178
180 template <is::inputIteratorToConstructValuesOfType<ElementType> Iterator, std::sentinel_for<Iterator> Sentinel>
181 constexpr Vector (Iterator first, Sentinel last) : Vctr (StdVectorType (first, last)) {}
182
188 template <is::suitableInitializerFunctionForElementType<ElementType> Fn>
189 constexpr Vector (size_t size, Fn&& initializerFunction)
190 {
191 reserve (size);
192 for (size_t i = 0; i < size; ++i)
193 push_back (initializerFunction (i));
194 }
195
197 template <is::expression Expression>
198 constexpr Vector (Expression&& e)
199 {
200 resize (e.size());
201 Vctr::assignExpressionTemplate (std::forward<Expression> (e));
202 }
203
204 //==============================================================================
205 // Operators
206 //==============================================================================
208 template <has::sizeAndDataWithElementType<ElementType> Container>
209 constexpr Vector& operator= (Container&& containerToCopyDataFrom)
210 {
211 if constexpr (has::begin<Container> &&
214 (! std::is_reference_v<Container>))
215 {
216 if constexpr (std::same_as<Container, Vector>)
217 {
218 Vctr::storage = std::move (containerToCopyDataFrom.storage);
219 }
220 else if constexpr (std::same_as<Container, StdVectorType>)
221 {
222 Vctr::storage = std::move (containerToCopyDataFrom);
223 }
224 else
225 {
226 Vctr::storage.assign (std::make_move_iterator (containerToCopyDataFrom.begin()), std::make_move_iterator (containerToCopyDataFrom.end()));
227 }
228 }
229 else
230 {
231 Vctr::copyFrom (containerToCopyDataFrom.data(), containerToCopyDataFrom.size());
232 }
233
234 return *this;
235 }
236
238 constexpr Vector& operator= (const Vector& other)
239 {
240 // Forwards to the generic operator above. This is needed since the compiler does not recognize
241 // the generic implementation as a copy assignment operator.
242 return *this = other.storage;
243 }
244
246 constexpr Vector& operator= (std::initializer_list<ElementType> elementsToAssign)
247 {
248 Vctr::storage.assign (std::move (elementsToAssign));
249 return *this;
250 }
251
256 template <is::expression E>
257 constexpr void operator= (const E& expression)
258 {
259 resize (expression.size());
260 Vctr::assignExpressionTemplate (expression);
261 }
262
263 //==============================================================================
264 // Accessing the underlying vector.
265 //==============================================================================
270 constexpr StdVectorType& getUnderlyingVector() { return Vctr::storage; }
271
276 constexpr const StdVectorType& getUnderlyingVector() const { return Vctr::storage; }
277
282 constexpr StdVectorType&& moveUnderlyingVector() && { return std::move (Vctr::storage); }
283
285 constexpr operator StdVectorType&() { return Vctr::storage; }
286
288 constexpr operator const StdVectorType&() const { return Vctr::storage; }
289
291 constexpr operator StdVectorType() && { return std::move (Vctr::storage); }
292
298 template <class OtherAllocator>
299 requires isDifferentAllocatorTypeWithSameValueType<OtherAllocator>
300 operator std::vector<ElementType, OtherAllocator>() const
301 {
302 return std::vector<ElementType, OtherAllocator> (Vctr::begin(), Vctr::end());
303 }
304
305 //==============================================================================
306 // Resizing, initialization, and clearing
307 //==============================================================================
312 constexpr void resize (size_t i) { Vctr::storage.resize (i); }
313
318 constexpr void reserve (size_t i) { Vctr::storage.reserve (i); }
319
324 constexpr void shrink_to_fit() { Vctr::storage.shrink_to_fit(); }
325
330 constexpr void init (size_t newSize, const value_type& value)
331 {
332 resize (newSize);
333 Vctr::fill (value);
334 }
335
340 template <is::suitableInitializerFunctionForElementType<ElementType> Fn>
341 constexpr void init (size_t newSize, Fn&& initializerFunction)
342 {
343 resize (newSize);
344 for (size_t i = 0; i < newSize; ++i)
345 Vctr::at (i) = initializerFunction (i);
346 }
347
352 constexpr void clear() noexcept { Vctr::storage.clear(); }
353
354 //==============================================================================
355 // Allocator
356 //==============================================================================
361 constexpr Allocator<ElementType> get_allocator() const noexcept { return Vctr::storage.get_allocator(); }
362
363 //==============================================================================
364 // Size and capacity
365 //==============================================================================
367 constexpr size_t capacity() const noexcept { return Vctr::storage.capacity(); }
368
370 constexpr size_t max_size() const noexcept { return Vctr::storage.max_size(); }
371
372 //==============================================================================
373 // Erasing elements from the Vector
374 //==============================================================================
379 constexpr auto erase (ConstIterator elementToErase)
380 {
381 // Undefined behaviour if elementToErase does not refer to an element in this Vector
382 VCTR_ASSERT (Vctr::contains (elementToErase));
383 return Vctr::storage.erase (elementToErase);
384 }
385
387 constexpr auto erase (size_t idx)
388 {
389 return erase (Vctr::storage.begin() + idx);
390 }
391
399 constexpr auto erase (ConstIterator first, ConstIterator last)
400 {
401 // Undefined behaviour if the range between first and last does not refer to a range in this Vector
402 VCTR_ASSERT (Vctr::contains (first));
403 VCTR_ASSERT (Vctr::contains (last) || last == Vctr::end());
404
405 return Vctr::storage.erase (first, last);
406 }
407
409 constexpr auto erase (size_t startIdx, size_t numElements)
410 {
411 auto it = Vctr::storage.begin() + startIdx;
412 return erase (it, it + numElements);
413 }
414
416 template <std::equality_comparable_with<ElementType> T>
417 constexpr auto eraseFirstOccurrenceOf (const T& value)
418 {
419 auto it = Vctr::find (value);
420 return it != Vctr::end() ? erase (it) : it;
421 }
422
424 template <is::functionWithSignatureOrImplicitlyConvertible<bool (const ElementType&)> Fn>
425 constexpr auto eraseFirstOccurrenceIf (Fn&& predicate)
426 {
427 auto it = Vctr::findIf (std::forward<Fn> (predicate));
428 return it != Vctr::end() ? erase (it) : it;
429 }
430
435 template <std::equality_comparable_with<ElementType> T>
436 constexpr bool eraseAllOccurrencesOf (const T& value)
437 {
438 auto beginOfElementsToRemove = std::remove (Vctr::begin(), Vctr::end(), value);
439 if (beginOfElementsToRemove == Vctr::end())
440 return false;
441
442 erase (beginOfElementsToRemove, Vctr::end());
443 return true;
444 }
445
451 template <is::functionWithSignatureOrImplicitlyConvertible<bool (const ElementType&)> Fn>
452 constexpr bool eraseAllOccurrencesIf (Fn&& predicate)
453 {
454 auto beginOfElementsToRemove = std::remove_if (Vctr::begin(), Vctr::end(), std::forward<Fn> (predicate));
455 if (beginOfElementsToRemove == Vctr::end())
456 return false;
457
458 erase (beginOfElementsToRemove, Vctr::end());
459 return true;
460 }
461
462 //==============================================================================
463 // Adding elements to the Vector
464 //==============================================================================
472 constexpr ElementType& push_back (ElementType&& newElement)
473 {
474 Vctr::storage.push_back (std::move (newElement));
475 return Vctr::storage.back();
476 }
477
485 constexpr ElementType& push_back (const ElementType& newElement)
486 {
487 Vctr::storage.push_back (newElement);
488 return Vctr::storage.back();
489 }
490
496 constexpr ElementType pop_back()
497 {
498 VCTR_ASSERT (! Vctr::empty());
499 auto x = std::move (Vctr::storage.back());
500 Vctr::storage.pop_back();
501 return x;
502 }
503
508 template <class... Args>
509 constexpr void emplace_back (Args&&... args) { Vctr::storage.emplace_back (std::forward<Args> (args)...); }
510
515 constexpr void swap (Vector& other) noexcept { Vctr::storage.swap (other.storage); }
516
518 template <is::anyVctr VctrToAppend>
519 void append (VctrToAppend&& vctrToAppend, bool moveValuesFromSrc = false)
520 {
521 insert (Vctr::end(), std::forward<VctrToAppend> (vctrToAppend), moveValuesFromSrc);
522 }
523
530 auto insert (ConstIterator pos, const ElementType& value)
531 {
532 // Undefined behaviour if pos does not refer to an element in this Vector
533 VCTR_ASSERT (pos == Vctr::end() || Vctr::contains (pos));
534 return Vctr::storage.insert (pos, value);
535 }
536
538 auto insert (size_t idx, const ElementType& value) { return insert (Vctr::begin() + idx, value); }
539
546 auto insert (ConstIterator pos, ElementType&& value)
547 {
548 // Undefined behaviour if pos does not refer to an element in this Vector
549 VCTR_ASSERT (pos == Vctr::end() || Vctr::contains (pos));
550 return Vctr::storage.insert (pos, std::move (value));
551 }
552
554 auto insert (size_t idx, ElementType&& value) { return insert (Vctr::begin() + idx, std::move (value)); }
555
563 auto insert (ConstIterator pos, size_t numCopies, const ElementType& value)
564 {
565 // Undefined behaviour if pos does not refer to an element in this Vector
566 VCTR_ASSERT (pos == Vctr::end() || Vctr::contains (pos));
567 return Vctr::storage.insert (pos, numCopies, value);
568 }
569
571 auto insert (size_t idx, size_t numCopies, const ElementType& value) { return insert (Vctr::begin() + idx, numCopies, value); }
572
581 template <is::inputIteratorToConstructValuesOfType<ElementType> InputIterator>
582 auto insert (ConstIterator pos, InputIterator first, InputIterator last)
583 {
584 // Undefined behaviour if pos does not refer to an element in this Vector
585 VCTR_ASSERT (pos == Vctr::end() || Vctr::contains (pos));
586
588 {
589 // The range between first and last must not be elements of this Vector
590 VCTR_ASSERT (! Vctr::contains (first));
591 VCTR_ASSERT (! Vctr::contains (last));
592 }
593
594 return Vctr::storage.insert (pos, first, last);
595 }
596
602 template <is::inputIteratorToConstructValuesOfType<ElementType> InputIterator>
603 auto insert (size_t idx, InputIterator first, InputIterator last)
604 {
605 return insert (Vctr::begin() + idx, first, last);
606 }
607
615 auto insert (ConstIterator pos, std::initializer_list<ElementType> initList)
616 {
617 // Undefined behaviour if pos does not refer to an element in this Vector
618 VCTR_ASSERT (pos == Vctr::end() || Vctr::contains (pos));
619 return Vctr::storage.insert (pos, initList);
620 }
621
623 auto insert (size_t idx, std::initializer_list<ElementType> initList) { return insert (Vctr::begin() + idx, std::move (initList)); }
624
632 template <is::anyVctr VctrToInsert>
633 auto insert (ConstIterator pos, VctrToInsert&& vctrToInsert, bool moveValuesFromSrc = false)
634 {
635 // Undefined behaviour if pos does not refer to an element in this Vector
636 VCTR_ASSERT (pos == Vctr::end() || Vctr::contains (pos));
637
638 // If it is no view and no reference, the container passed in has no dependencies outside this scope,
639 // so we can safely move its elements in every case
640 if constexpr ((! is::view<VctrToInsert>) &&(! std::is_reference_v<VctrToInsert>) )
641 moveValuesFromSrc = true;
642
643 if (moveValuesFromSrc)
644 return Vctr::storage.insert (pos, std::make_move_iterator (vctrToInsert.begin()), std::make_move_iterator (vctrToInsert.end()));
645
646 return Vctr::storage.insert (pos, vctrToInsert.begin(), vctrToInsert.end());
647 }
648
654 template <is::anyVctr VctrToInsert>
655 auto insert (size_t idx, VctrToInsert&& vctrToInsert, bool moveValuesFromSrc = false)
656 {
657 return insert (Vctr::begin() + idx, std::forward<VctrToInsert> (vctrToInsert), moveValuesFromSrc);
658 }
659};
660
662template <class OwnedElementType>
663class OwnedVector : public Vector<std::unique_ptr<OwnedElementType>>
664{
665private:
667
668public:
669 OwnedVector() = default;
670
672 OwnedVector (std::initializer_list<OwnedElementType*> elementsToOwn)
673 {
674 VectorType::reserve (elementsToOwn.size());
675 for (auto* ptr : elementsToOwn)
677 }
678
680 template <class... Args>
681 OwnedVector (Args&&... args) : VectorType (std::forward<Args> (args)...) {}
682
684 constexpr auto eraseOccurrenceOf (const OwnedElementType* address)
685 {
686 auto it = VectorType::findIf ([&] (auto& p) { return p.get() == address; });
687 return it != VectorType::end() ? VectorType::erase (it) : it;
688 }
689};
690
691//==============================================================================
692// Deduction guides
693//==============================================================================
694
695template <is::triviallyCopyableWithDataAndSize OtherContainer>
696Vector (const OtherContainer& other) -> Vector<ValueType<OtherContainer>>;
697
698template <is::iteratorCopyable OtherContainer>
699Vector (const OtherContainer& other) -> Vector<ValueType<OtherContainer>>;
700
701template <std::input_iterator Iterator, std::sentinel_for<Iterator> Sentinel>
702Vector (Iterator first, Sentinel last) -> Vector<std::iter_value_t<Iterator>>;
703
704template <is::suitableInitializerFunction Fn>
705Vector (size_t size, Fn&& initializerFunction) -> Vector<std::invoke_result_t<Fn, size_t>>;
706
707template <is::expression Expression>
708Vector (Expression&& e) -> Vector<ValueType<Expression>>;
709
710template <is::uniquePtr FirstArg, is::uniquePtr... Args>
711requires (are::same<FirstArg, Args...>)
712OwnedVector (FirstArg&&, Args&&...) -> OwnedVector<typename FirstArg::element_type>;
713
714} // namespace vctr
Returns aligned pointers when allocations are requested.
Definition: AlignedAllocator.h:29
A handy shortcut for Vector<std::unique_ptr<OwnedElementType>>.
Definition: Vector.h:664
constexpr auto eraseOccurrenceOf(const OwnedElementType *address)
Erases the occurrence of an owned element with the given address and adjusts its size.
Definition: Vector.h:684
OwnedVector(std::initializer_list< OwnedElementType * > elementsToOwn)
Creates an OwnedVector from an initializer list of raw pointers that will be owned by the Vector.
Definition: Vector.h:672
OwnedVector(Args &&... args)
Forwards every other constructor call to the base class constructor.
Definition: Vector.h:681
The base class to all one dimensional containers and views in the VCTR project.
Definition: VctrBase.h:38
constexpr size_t size() const noexcept
Returns the number of elements.
Definition: VctrBase.h:61
constexpr auto find(const T &valueToLookFor)
Returns an iterator to the first element that equals valueToLookFor or end() if none was found.
Definition: VctrBase.h:456
constexpr auto begin()
Returns an iterator to the begin of the storage.
Definition: VctrBase.h:141
constexpr void assign(std::initializer_list< ElementType > elements)
Assigns elements from the initializer list to this instance.
Definition: VctrBase.h:266
constexpr void copyFrom(const ElementType *otherData, size_t otherSize)
Copies the content from otherData to this instance.
Definition: VctrBase.h:285
VCTR_FORCEDINLINE constexpr auto * data()
Returns a raw pointer to the underlying storage.
Definition: VctrBase.h:123
constexpr auto findIf(Fn &&predicate)
Returns an iterator to the first element in this vector for which predicate returns true or end() if ...
Definition: VctrBase.h:484
constexpr auto && back()
Returns a reference to the last element.
Definition: VctrBase.h:117
constexpr auto & at(size_t i)
Returns a reference to element i.
Definition: VctrBase.h:103
constexpr bool empty() const noexcept
Checks whether the container is empty.
Definition: VctrBase.h:67
constexpr void fill(const value_type &value)
Fills the container with the given value.
Definition: VctrBase.h:303
constexpr auto end()
Returns an iterator to the first element behind the storage.
Definition: VctrBase.h:147
constexpr bool contains(const T &value) const
Returns true if at least one element is equal to value.
Definition: VctrBase.h:556
The heap-allocated container type.
Definition: Vector.h:99
auto insert(ConstIterator pos, size_t numCopies, const ElementType &value)
Inserts numCopies copies of value before the element referenced by pos and returns an iterator to the...
Definition: Vector.h:563
constexpr Vector & operator=(Container &&containerToCopyDataFrom)
Copies or moves the data of the source container to this Vector.
Definition: Vector.h:209
constexpr void init(size_t newSize, Fn &&initializerFunction)
Resizes this vector to newSize and fills it via the given initializerFunction.
Definition: Vector.h:341
auto insert(size_t idx, const ElementType &value)
Inserts value at index idx and returns an iterator to the inserted value.
Definition: Vector.h:538
constexpr Vector(Expression &&e)
Creates a Vector from an expression.
Definition: Vector.h:198
auto insert(ConstIterator pos, std::initializer_list< ElementType > initList)
Inserts a list of values before the element referenced by pos and returns an iterator to the first in...
Definition: Vector.h:615
auto insert(ConstIterator pos, ElementType &&value)
Inserts value before the element referenced by pos and returns an iterator to the inserted value.
Definition: Vector.h:546
constexpr Vector(size_t size)
Creates an uninitialised Vector of the desired size.
Definition: Vector.h:124
constexpr bool eraseAllOccurrencesIf(Fn &&predicate)
Removes all elements inside this Vector for which predicate is true and adjusts its size.
Definition: Vector.h:452
auto insert(ConstIterator pos, const ElementType &value)
Inserts value before the element referenced by pos and returns an iterator to the inserted value.
Definition: Vector.h:530
auto insert(size_t idx, std::initializer_list< ElementType > initList)
Inserts a list of values at index idx and returns an iterator to the first inserted value.
Definition: Vector.h:623
constexpr size_t max_size() const noexcept
Returns the maximum number of elements the container is able to hold.
Definition: Vector.h:370
void append(VctrToAppend &&vctrToAppend, bool moveValuesFromSrc=false)
Appends a Span, Array or Vector to the end of this Vector, optionally by moving elements from the sou...
Definition: Vector.h:519
constexpr auto erase(ConstIterator elementToErase)
Erases the element referenced by elementToErase and returns the iterator to the element behind it.
Definition: Vector.h:379
constexpr void init(size_t newSize, const value_type &value)
Resizes this vector to newSize and fills it with the given value.
Definition: Vector.h:330
auto insert(size_t idx, InputIterator first, InputIterator last)
Inserts a range of values at index idx and returns an iterator to the inserted values.
Definition: Vector.h:603
constexpr auto erase(size_t idx)
Erases the element at index idx and returns the iterator to the element behind it.
Definition: Vector.h:387
constexpr void emplace_back(Args &&... args)
Constructs an element in-place at the end of the Vector.
Definition: Vector.h:509
auto insert(size_t idx, size_t numCopies, const ElementType &value)
Inserts numCopies copies of value at index idx and returns an iterator to the inserted values.
Definition: Vector.h:571
Vector(Alloc &&allocator)
Creates an empty Vector that uses the specified allocator instance.
Definition: Vector.h:121
constexpr Vector()=default
Creates an empty Vector with size = 0.
constexpr auto eraseFirstOccurrenceIf(Fn &&predicate)
Erases the first occurrence for which predicate is true from this Vector and adjusts its size.
Definition: Vector.h:425
auto insert(ConstIterator pos, VctrToInsert &&vctrToInsert, bool moveValuesFromSrc=false)
Inserts a VCTR container before the element referenced by pos and returns an iterator to the first in...
Definition: Vector.h:633
constexpr Vector(std::initializer_list< ElementType > il)
Creates a Vector from an initializer list.
Definition: Vector.h:130
constexpr ElementType pop_back()
Removes the last element in the vector, effectively reducing the container size by one.
Definition: Vector.h:496
constexpr Vector(size_t size, ElementType initialValue)
Creates a Vector with all elements initialised to initialValue of the desired size.
Definition: Vector.h:127
auto insert(size_t idx, ElementType &&value)
Inserts value at index idx and returns an iterator to the inserted value.
Definition: Vector.h:554
constexpr void swap(Vector &other) noexcept
Swaps the underlying memory with the other Vector.
Definition: Vector.h:515
constexpr Vector(const ElementType *data, size_t size)
Copies size elements from the memory location pointed to by data.
Definition: Vector.h:174
constexpr size_t capacity() const noexcept
Returns the number of elements the Vector can currently hold without re-allocation.
Definition: Vector.h:367
constexpr auto erase(size_t startIdx, size_t numElements)
Erases numElements elements starting from index startIdx and returns the iterator to the element behi...
Definition: Vector.h:409
constexpr ElementType & push_back(ElementType &&newElement)
Adds an element to the end of the Vector.
Definition: Vector.h:472
constexpr Allocator< ElementType > get_allocator() const noexcept
Returns the allocator associated with the Vector.
Definition: Vector.h:361
constexpr auto eraseFirstOccurrenceOf(const T &value)
Erases the first occurrence of value from this Vector and adjusts its size.
Definition: Vector.h:417
constexpr const StdVectorType & getUnderlyingVector() const
Returns a reference to the underlying storage.
Definition: Vector.h:276
constexpr ElementType & push_back(const ElementType &newElement)
Adds an element to the end of the Vector.
Definition: Vector.h:485
constexpr void resize(size_t i)
Changes the size of this Vector, potentially allocating memory.
Definition: Vector.h:312
auto insert(ConstIterator pos, InputIterator first, InputIterator last)
Inserts a range of values before the element referenced by pos and returns an iterator to the inserte...
Definition: Vector.h:582
constexpr Vector(const OtherContainer &other)
This constructor will create a Vector instance of the same size as OtherContainer and will copy its v...
Definition: Vector.h:171
constexpr Vector(size_t size, Fn &&initializerFunction)
Creates a Vector of the given size and initialises all elements by calling initializerFunction with t...
Definition: Vector.h:189
auto insert(size_t idx, VctrToInsert &&vctrToInsert, bool moveValuesFromSrc=false)
Inserts a VCTR container at index idx and returns an iterator to the first inserted value.
Definition: Vector.h:655
constexpr Vector(Vector &&other)
Moves the other Vector into this one.
Definition: Vector.h:146
constexpr void reserve(size_t i)
Pre-allocates memory for the given number of elements.
Definition: Vector.h:318
constexpr void clear() noexcept
Erase all elements from the Vector.
Definition: Vector.h:352
constexpr bool eraseAllOccurrencesOf(const T &value)
Removes all occurrences of value from this Vector and adjusts its size.
Definition: Vector.h:436
constexpr Vector(const Vector &other)
Creates a copy of the other Vector.
Definition: Vector.h:143
constexpr StdVectorType & getUnderlyingVector()
Returns a reference to the underlying storage.
Definition: Vector.h:270
constexpr void shrink_to_fit()
Adjusts the allocated memory to the actual number of elements.
Definition: Vector.h:324
constexpr StdVectorType && moveUnderlyingVector() &&
Moves the underlying storage out of this wrapper class.
Definition: Vector.h:282
constexpr Vector(Iterator first, Sentinel last)
Creates an Vector from an iterator and a sentinel by initialising the Vector with the content read fr...
Definition: Vector.h:181
constexpr auto erase(ConstIterator first, ConstIterator last)
Erases the range of elements referenced by it and returns the iterator to the element behind it.
Definition: Vector.h:399
Constrains a type to have a member function begin() or begin() const.
Definition: ContainerAndExpressionConcepts.h:156
Constrains a type to have a member function end() or end() const.
Definition: ContainerAndExpressionConcepts.h:160
Constrains the type to be a contiguous iterator with a value type same as ElementType.
Definition: ContainerAndExpressionConcepts.h:377
Constrains a type to be a view rather than an owning container.
Definition: ContainerAndExpressionConcepts.h:242
The main namespace of the VCTR project.
Definition: Array.h:24
The default allocator choice for non-arithmetic types is a simple std::allocator.
Definition: Vector.h:30