11#include <initializer_list>
47 using Data =
typename std::vector<T>;
50 using Iterator =
typename std::vector<T>::iterator;
56 using RevIterator =
typename std::vector<T>::reverse_iterator;
103 d = std::move(
other.d);
247 const T &
at(
size_t index)
const {
342 return d.insert(pos,
value);
352 return d.insert(pos, std::move(
value));
383 return d.emplace(pos, std::forward<Args>(
args)...);
394 return d.emplace(
constBegin() + pos, std::forward<Args>(
args)...);
413 return d.erase(first, last);
422 return d.erase(d.begin() + index);
430 d.erase(std::remove_if(d.begin(), d.end(), func), d.end());
465 d.insert(d.end(),
list.d.begin(),
list.d.end());
474 d.push_back(std::move(
value));
483 d.insert(d.end(), std::make_move_iterator(
list.d.begin()), std::make_move_iterator(
list.d.end()));
494 return d.emplace_back(std::forward<Args>(
args)...);
542 if(index >=
size())
return false;
582 template <
typename Func>
584 for(
const auto &
item : d) func(
item);
594 for(
const auto &
item : d) {
606 for(
size_t i = 0;
i < d.size(); ++
i) {
619 if(d[
static_cast<size_t>(
i)] ==
value)
return i;
631 for(
const auto &
item : d) {
645 size_t end = pos + length;
646 if(
end > d.size())
end = d.size();
647 if(pos >= d.size())
return ret;
Dynamic array container wrapping std::vector.
Definition list.h:40
bool contains(const T &val) const
Returns true if the list contains the given value.
Definition list.h:593
List(size_t size, const T &defaultValue)
Constructs a list with a given number of copies of a value.
Definition list.h:78
void shrink()
Releases unused memory by shrinking capacity to fit the current size.
Definition list.h:324
RevIterator revBegin() noexcept
Returns a mutable reverse iterator to the last element.
Definition list.h:183
ConstRevIterator crbegin() const noexcept
Returns a const reverse iterator to the last element.
Definition list.h:188
ConstIterator end() const noexcept
Returns a const iterator to one past the last element.
Definition list.h:203
ConstIterator constEnd() const noexcept
Returns a const iterator to one past the last element.
Definition list.h:213
friend bool operator>=(const List< T > &lhs, const List< T > &rhs)
Lexicographic greater-than-or-equal comparison.
Definition list.h:679
ConstIterator cend() const noexcept
Returns a const iterator to one past the last element.
Definition list.h:208
size_t maxSize() const noexcept
Returns the maximum number of elements the list can theoretically hold.
Definition list.h:306
Iterator erase(ConstIterator first, ConstIterator last)
Removes elements in the range [first, last).
Definition list.h:412
ConstRevIterator constRevBegin() const noexcept
Returns a const reverse iterator to the last element.
Definition list.h:193
ConstIterator constBegin() const noexcept
Returns a const iterator to the first element.
Definition list.h:173
List & operator=(std::initializer_list< T > initList)
Assigns from an initializer list, replacing all contents.
Definition list.h:112
friend bool operator<(const List< T > &lhs, const List< T > &rhs)
Lexicographic less-than comparison.
Definition list.h:664
Iterator insert(ConstIterator pos, T &&value)
Inserts a value before the position given by an iterator (move overload).
Definition list.h:351
Iterator remove(size_t index)
Removes the element at the given index.
Definition list.h:421
List & operator=(List &&other) noexcept
Move assignment operator.
Definition list.h:102
Iterator remove(ConstIterator pos)
Removes the element at the given iterator position.
Definition list.h:402
const T * data() const noexcept
Returns a pointer to the underlying contiguous storage.
Definition list.h:291
void pushToBack(T &&value)
Moves an item onto the back of the list.
Definition list.h:473
void reserve(size_t newCapacity)
Pre-allocates storage for at least newCapacity elements.
Definition list.h:314
List(const List &other)
Copy constructor.
Definition list.h:81
List< T > reverse() const
Returns a reversed copy of this list.
Definition list.h:561
ConstRevIterator crend() const noexcept
Returns a const reverse iterator to one before the first element.
Definition list.h:228
RevIterator rbegin() noexcept
Returns a mutable reverse iterator to the last element.
Definition list.h:178
ssize_t indexOf(const T &value) const
Returns the index of the first occurrence of value.
Definition list.h:605
void popFromBack()
Removes the last element from the list.
Definition list.h:498
friend bool operator<=(const List< T > &lhs, const List< T > &rhs)
Lexicographic less-than-or-equal comparison.
Definition list.h:674
Iterator begin() noexcept
Returns a mutable iterator to the first element.
Definition list.h:158
Iterator emplace(ConstIterator pos, Args &&...args)
Emplaces an object right before the given position.
Definition list.h:382
typename std::vector< T >::iterator Iterator
Mutable forward iterator.
Definition list.h:50
ConstRevIterator constRevEnd() const noexcept
Returns a const reverse iterator to one before the first element.
Definition list.h:233
ssize_t lastIndexOf(const T &value) const
Returns the index of the last occurrence of value.
Definition list.h:617
ConstIterator cbegin() const noexcept
Returns a const iterator to the first element.
Definition list.h:168
List()=default
Default constructor. Creates an empty list.
List & operator+=(List &&list)
Appends all items from another list (move overload).
Definition list.h:152
friend bool operator!=(const List< T > &lhs, const List< T > &rhs)
Returns true if the lists differ.
Definition list.h:659
void swap(List< T > &other) noexcept
Swaps the list data with another list of the same type.
Definition list.h:530
size_t size() const noexcept
Returns the number of elements in the list.
Definition list.h:301
List(List &&other) noexcept
Move constructor.
Definition list.h:84
friend bool operator==(const List< T > &lhs, const List< T > &rhs)
Returns true if both lists have identical contents.
Definition list.h:654
bool removeFirst(const T &value)
Removes the first instance of value from the list.
Definition list.h:439
List & operator+=(T &&item)
Appends a single item to the back of the list (move overload).
Definition list.h:132
List(std::initializer_list< T > initList)
Constructs a list from an initializer list.
Definition list.h:90
Iterator emplace(size_t pos, Args &&...args)
Emplaces an object right before the given index.
Definition list.h:393
T * data() noexcept
Returns a pointer to the underlying contiguous storage.
Definition list.h:286
std::function< bool(const T &)> TestFunc
Predicate function type used by removeIf().
Definition list.h:62
ConstIterator begin() const noexcept
Returns a const iterator to the first element.
Definition list.h:163
typename std::vector< T >::reverse_iterator RevIterator
Mutable reverse iterator.
Definition list.h:56
void clear() noexcept
Removes all elements from the list.
Definition list.h:330
void pushToBack(List< T > &&list)
Moves all items from another list to the back of this list.
Definition list.h:482
friend bool operator>(const List< T > &lhs, const List< T > &rhs)
Lexicographic greater-than comparison.
Definition list.h:669
Iterator end() noexcept
Returns a mutable iterator to one past the last element.
Definition list.h:198
size_t count(const T &value) const
Returns the number of occurrences of value.
Definition list.h:629
typename std::vector< T >::const_iterator ConstIterator
Const forward iterator.
Definition list.h:53
Iterator insert(size_t pos, T &&value)
Inserts a value before the given index (move overload).
Definition list.h:371
void forEach(Func &&func) const
Calls func for every element.
Definition list.h:583
const T & front() const
Returns a reference to the first element.
Definition list.h:271
const T & at(size_t index) const
Returns a reference to the element at index with bounds checking.
Definition list.h:247
List< T > mid(size_t pos, size_t length) const
Returns a sublist starting at pos with length elements.
Definition list.h:643
List< T > unique()
Returns a list of all the unique items in this list.
Definition list.h:571
List & operator+=(const List &list)
Appends all items from another list to the back of this list.
Definition list.h:142
bool set(size_t index, const T &val)
Sets an item in the list by index.
Definition list.h:541
typename std::vector< T >::const_reverse_iterator ConstRevIterator
Const reverse iterator.
Definition list.h:59
void resize(size_t newSize)
Resizes the list.
Definition list.h:511
const T & operator[](size_t index) const
Returns a reference to the element at index without bounds checking.
Definition list.h:261
RevIterator rend() noexcept
Returns a mutable reverse iterator to one before the first element.
Definition list.h:218
Iterator insert(ConstIterator pos, const T &value)
Inserts a value before the position given by an iterator.
Definition list.h:341
~List()=default
Destructor.
T & front()
Returns a reference to the first element.
Definition list.h:266
T & operator[](size_t index)
Returns a reference to the element at index without bounds checking.
Definition list.h:256
List< T > sort() const
Returns a sorted copy of this list.
Definition list.h:551
RevIterator revEnd() noexcept
Returns a mutable reverse iterator to one before the first element.
Definition list.h:223
List(size_t size)
Constructs a list with a given number of default-constructed elements.
Definition list.h:71
List & operator+=(const T &item)
Appends a single item to the back of the list.
Definition list.h:122
T & back()
Returns a reference to the last element.
Definition list.h:276
void resize(size_t newSize, const T &value)
Resizes the list, constructs any new items with the given value.
Definition list.h:521
void pushToBack(const T &value)
Pushes an item onto the back of the list.
Definition list.h:455
const T & back() const
Returns a reference to the last element.
Definition list.h:281
Iterator insert(size_t pos, const T &value)
Inserts a value before the given index.
Definition list.h:361
typename std::vector< T > Data
Underlying std::vector storage type.
Definition list.h:47
List & operator=(const List &other)
Copy assignment operator.
Definition list.h:96
void removeIf(TestFunc func)
Runs a test function on all the items and removes them if it returns true.
Definition list.h:429
T & at(size_t index)
Returns a reference to the element at index with bounds checking.
Definition list.h:242
T & emplaceToBack(Args &&...args)
Emplaces an object on the back of the list.
Definition list.h:493
bool isEmpty() const noexcept
Returns true if the list has no elements.
Definition list.h:296
void pushToBack(const List< T > &list)
Pushes all items from another list to the back of this list.
Definition list.h:464
size_t capacity() const noexcept
Returns the number of elements the list can hold without reallocating.
Definition list.h:319
#define PROMEKI_NAMESPACE_BEGIN
Starts a promeki namespace block.
Definition namespace.h:14
#define PROMEKI_NAMESPACE_END
Ends a promeki namespace block.
Definition namespace.h:19
const T & value(const Result< T > &r)
Returns the value from a Result.
Definition result.h:56
#define PROMEKI_SHARED_FINAL(TYPE)
Macro for non-polymorphic native shared objects.
Definition sharedptr.h:88