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<Allocator<ElementType>, 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
295 template <class OtherAllocator>
296 requires isDifferentAllocatorTypeWithSameValueType<OtherAllocator>
297 operator std::vector<ElementType, OtherAllocator>() const
298 {
299 return std::vector<ElementType, OtherAllocator> (Vctr::begin(), Vctr::end());
300 }
301
302 //==============================================================================
303 // Resizing, initialization, and clearing
304 //==============================================================================
309 constexpr void resize (size_t i) { Vctr::storage.resize (i); }
310
315 constexpr void reserve (size_t i) { Vctr::storage.reserve (i); }
316
321 constexpr void shrink_to_fit() { Vctr::storage.shrink_to_fit(); }
322
327 constexpr void init (size_t newSize, const value_type& value)
328 {
329 resize (newSize);
330 Vctr::fill (value);
331 }
332
337 template <is::suitableInitializerFunctionForElementType<ElementType> Fn>
338 constexpr void init (size_t newSize, Fn&& initializerFunction)
339 {
340 resize (newSize);
341 for (size_t i = 0; i < newSize; ++i)
342 Vctr::at (i) = initializerFunction (i);
343 }
344
349 constexpr void clear() noexcept { Vctr::storage.clear(); }
350
351 //==============================================================================
352 // Allocator
353 //==============================================================================
358 constexpr Allocator<ElementType> get_allocator() const noexcept { return Vctr::storage.get_allocator(); }
359
360 //==============================================================================
361 // Size and capacity
362 //==============================================================================
364 constexpr size_t capacity() const noexcept { return Vctr::storage.capacity(); }
365
367 constexpr size_t max_size() const noexcept { return Vctr::storage.max_size(); }
368
369 //==============================================================================
370 // Erasing elements from the Vector
371 //==============================================================================
376 constexpr auto erase (ConstIterator elementToErase)
377 {
378 // Undefined behaviour if elementToErase does not refer to an element in this Vector
379 VCTR_ASSERT (Vctr::contains (elementToErase));
380 return Vctr::storage.erase (elementToErase);
381 }
382
384 constexpr auto erase (size_t idx)
385 {
386 return erase (Vctr::storage.begin() + idx);
387 }
388
396 constexpr auto erase (ConstIterator first, ConstIterator last)
397 {
398 // Undefined behaviour if the range between first and last does not refer to a range in this Vector
399 VCTR_ASSERT (Vctr::contains (first));
400 VCTR_ASSERT (Vctr::contains (last) || last == Vctr::end());
401
402 return Vctr::storage.erase (first, last);
403 }
404
406 constexpr auto erase (size_t startIdx, size_t numElements)
407 {
408 auto it = Vctr::storage.begin() + startIdx;
409 return erase (it, it + numElements);
410 }
411
413 template <std::equality_comparable_with<ElementType> T>
414 constexpr auto eraseFirstOccurrenceOf (const T& value)
415 {
416 auto it = Vctr::find (value);
417 return it != Vctr::end() ? erase (it) : it;
418 }
419
421 template <is::functionWithSignatureOrImplicitlyConvertible<bool (const ElementType&)> Fn>
422 constexpr auto eraseFirstOccurrenceIf (Fn&& predicate)
423 {
424 auto it = Vctr::findIf (std::forward<Fn> (predicate));
425 return it != Vctr::end() ? erase (it) : it;
426 }
427
432 template <std::equality_comparable_with<ElementType> T>
433 constexpr bool eraseAllOccurrencesOf (const T& value)
434 {
435 auto beginOfElementsToRemove = std::remove (Vctr::begin(), Vctr::end(), value);
436 if (beginOfElementsToRemove == Vctr::end())
437 return false;
438
439 erase (beginOfElementsToRemove, Vctr::end());
440 return true;
441 }
442
448 template <is::functionWithSignatureOrImplicitlyConvertible<bool (const ElementType&)> Fn>
449 constexpr bool eraseAllOccurrencesIf (Fn&& predicate)
450 {
451 auto beginOfElementsToRemove = std::remove_if (Vctr::begin(), Vctr::end(), std::forward<Fn> (predicate));
452 if (beginOfElementsToRemove == Vctr::end())
453 return false;
454
455 erase (beginOfElementsToRemove, Vctr::end());
456 return true;
457 }
458
459 //==============================================================================
460 // Adding elements to the Vector
461 //==============================================================================
469 constexpr ElementType& push_back (ElementType&& newElement)
470 {
471 Vctr::storage.push_back (std::move (newElement));
472 return Vctr::storage.back();
473 }
474
482 constexpr ElementType& push_back (const ElementType& newElement)
483 {
484 Vctr::storage.push_back (newElement);
485 return Vctr::storage.back();
486 }
487
493 constexpr ElementType pop_back()
494 {
495 VCTR_ASSERT (! Vctr::empty());
496 auto x = std::move (Vctr::storage.back());
497 Vctr::storage.pop_back();
498 return x;
499 }
500
505 template <class... Args>
506 constexpr void emplace_back (Args&&... args) { Vctr::storage.emplace_back (std::forward<Args> (args)...); }
507
512 constexpr void swap (Vector& other) noexcept { Vctr::storage.swap (other.storage); }
513
515 template <is::anyVctr VctrToAppend>
516 void append (VctrToAppend&& vctrToAppend, bool moveValuesFromSrc = false)
517 {
518 insert (Vctr::end(), std::forward<VctrToAppend> (vctrToAppend), moveValuesFromSrc);
519 }
520
527 auto insert (ConstIterator pos, const ElementType& value)
528 {
529 // Undefined behaviour if pos does not refer to an element in this Vector
530 VCTR_ASSERT (pos == Vctr::end() || Vctr::contains (pos));
531 return Vctr::storage.insert (pos, value);
532 }
533
535 auto insert (size_t idx, const ElementType& value) { return insert (Vctr::begin() + idx, value); }
536
543 auto insert (ConstIterator pos, ElementType&& value)
544 {
545 // Undefined behaviour if pos does not refer to an element in this Vector
546 VCTR_ASSERT (pos == Vctr::end() || Vctr::contains (pos));
547 return Vctr::storage.insert (pos, std::move (value));
548 }
549
551 auto insert (size_t idx, ElementType&& value) { return insert (Vctr::begin() + idx, std::move (value)); }
552
560 auto insert (ConstIterator pos, size_t numCopies, const ElementType& value)
561 {
562 // Undefined behaviour if pos does not refer to an element in this Vector
563 VCTR_ASSERT (pos == Vctr::end() || Vctr::contains (pos));
564 return Vctr::storage.insert (pos, numCopies, value);
565 }
566
568 auto insert (size_t idx, size_t numCopies, const ElementType& value) { return insert (Vctr::begin() + idx, numCopies, value); }
569
578 template <is::inputIteratorToConstructValuesOfType<ElementType> InputIterator>
579 auto insert (ConstIterator pos, InputIterator first, InputIterator last)
580 {
581 // Undefined behaviour if pos does not refer to an element in this Vector
582 VCTR_ASSERT (pos == Vctr::end() || Vctr::contains (pos));
583
585 {
586 // The range between first and last must not be elements of this Vector
587 VCTR_ASSERT (! Vctr::contains (first));
588 VCTR_ASSERT (! Vctr::contains (last));
589 }
590
591 return Vctr::storage.insert (pos, first, last);
592 }
593
599 template <is::inputIteratorToConstructValuesOfType<ElementType> InputIterator>
600 auto insert (size_t idx, InputIterator first, InputIterator last)
601 {
602 return insert (Vctr::begin() + idx, first, last);
603 }
604
612 auto insert (ConstIterator pos, std::initializer_list<ElementType> initList)
613 {
614 // Undefined behaviour if pos does not refer to an element in this Vector
615 VCTR_ASSERT (pos == Vctr::end() || Vctr::contains (pos));
616 return Vctr::storage.insert (pos, initList);
617 }
618
620 auto insert (size_t idx, std::initializer_list<ElementType> initList) { return insert (Vctr::begin() + idx, std::move (initList)); }
621
629 template <is::anyVctr VctrToInsert>
630 auto insert (ConstIterator pos, VctrToInsert&& vctrToInsert, bool moveValuesFromSrc = false)
631 {
632 // Undefined behaviour if pos does not refer to an element in this Vector
633 VCTR_ASSERT (pos == Vctr::end() || Vctr::contains (pos));
634
635 // If it is no view and no reference, the container passed in has no dependencies outside this scope,
636 // so we can safely move its elements in every case
637 if constexpr ((! is::view<VctrToInsert>) &&(! std::is_reference_v<VctrToInsert>) )
638 moveValuesFromSrc = true;
639
640 if (moveValuesFromSrc)
641 return Vctr::storage.insert (pos, std::make_move_iterator (vctrToInsert.begin()), std::make_move_iterator (vctrToInsert.end()));
642
643 return Vctr::storage.insert (pos, vctrToInsert.begin(), vctrToInsert.end());
644 }
645
651 template <is::anyVctr VctrToInsert>
652 auto insert (size_t idx, VctrToInsert&& vctrToInsert, bool moveValuesFromSrc = false)
653 {
654 return insert (Vctr::begin() + idx, std::forward<VctrToInsert> (vctrToInsert), moveValuesFromSrc);
655 }
656};
657
659template <class OwnedElementType>
660class OwnedVector : public Vector<std::unique_ptr<OwnedElementType>>
661{
662private:
664
665public:
666 OwnedVector() = default;
667
669 OwnedVector (std::initializer_list<OwnedElementType*> elementsToOwn)
670 {
671 VectorType::reserve (elementsToOwn.size());
672 for (auto* ptr : elementsToOwn)
674 }
675
677 template <class... Args>
678 OwnedVector (Args&&... args) : VectorType (std::forward<Args> (args)...) {}
679};
680
681//==============================================================================
682// Deduction guides
683//==============================================================================
684
685template <is::triviallyCopyableWithDataAndSize OtherContainer>
686Vector (const OtherContainer& other) -> Vector<ValueType<OtherContainer>>;
687
688template <is::iteratorCopyable OtherContainer>
689Vector (const OtherContainer& other) -> Vector<ValueType<OtherContainer>>;
690
691template <std::input_iterator Iterator, std::sentinel_for<Iterator> Sentinel>
692Vector (Iterator first, Sentinel last) -> Vector<std::iter_value_t<Iterator>>;
693
694template <is::suitableInitializerFunction Fn>
695Vector (size_t size, Fn&& initializerFunction) -> Vector<std::invoke_result_t<Fn, size_t>>;
696
697template <is::expression Expression>
698Vector (Expression&& e) -> Vector<ValueType<Expression>>;
699
700template <is::uniquePtr FirstArg, is::uniquePtr... Args>
701requires (are::same<FirstArg, Args...>)
702OwnedVector (FirstArg&&, Args&&...) -> OwnedVector<typename FirstArg::element_type>;
703
704} // 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:661
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:669
OwnedVector(Args &&... args)
Forwards every other constructor call to the base class constructor.
Definition: Vector.h:678
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:452
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:262
constexpr void copyFrom(const ElementType *otherData, size_t otherSize)
Copies the content from otherData to this instance.
Definition: VctrBase.h:281
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:480
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:299
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:552
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:560
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:338
auto insert(size_t idx, const ElementType &value)
Inserts value at index idx and returns an iterator to the inserted value.
Definition: Vector.h:535
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:612
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:543
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:449
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:527
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:620
constexpr size_t max_size() const noexcept
Returns the maximum number of elements the container is able to hold.
Definition: Vector.h:367
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:516
constexpr auto erase(ConstIterator elementToErase)
Erases the element referenced by elementToErase and returns the iterator to the element behind it.
Definition: Vector.h:376
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:327
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:600
constexpr auto erase(size_t idx)
Erases the element at index idx and returns the iterator to the element behind it.
Definition: Vector.h:384
constexpr void emplace_back(Args &&... args)
Constructs an element in-place at the end of the Vector.
Definition: Vector.h:506
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:568
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:422
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:630
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:493
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:551
constexpr void swap(Vector &other) noexcept
Swaps the underlying memory with the other Vector.
Definition: Vector.h:512
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:364
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:406
constexpr ElementType & push_back(ElementType &&newElement)
Adds an element to the end of the Vector.
Definition: Vector.h:469
constexpr Allocator< ElementType > get_allocator() const noexcept
Returns the allocator associated with the Vector.
Definition: Vector.h:358
constexpr auto eraseFirstOccurrenceOf(const T &value)
Erases the first occurrence of value from this Vector and adjusts its size.
Definition: Vector.h:414
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:482
constexpr void resize(size_t i)
Changes the size of this Vector, potentially allocating memory.
Definition: Vector.h:309
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:579
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:652
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:315
constexpr void clear() noexcept
Erase all elements from the Vector.
Definition: Vector.h:349
constexpr bool eraseAllOccurrencesOf(const T &value)
Removes all occurrences of value from this Vector and adjusts its size.
Definition: Vector.h:433
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:321
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:396
Constrains a type to have a member function begin() or begin() const.
Definition: ContainerAndExpressionConcepts.h:138
Constrains a type to have a member function end() or end() const.
Definition: ContainerAndExpressionConcepts.h:142
Constrains the type to be a contiguous iterator with a value type same as ElementType.
Definition: ContainerAndExpressionConcepts.h:359
Constrains a type to be a view rather than an owning container.
Definition: ContainerAndExpressionConcepts.h:224
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