|
@@ -46,62 +46,48 @@ public:
|
|
|
SmallVector(const SmallVector<T, X> &other) : std::vector<T>(other)
|
|
|
{
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Assignment.
|
|
|
* @param other The other vector to assign.
|
|
|
*/
|
|
|
SmallVector &operator=(const SmallVector &other) = default;
|
|
|
|
|
|
/**
|
|
|
* Generic assignment.
|
|
|
* @param other The other vector to assign.
|
|
|
*/
|
|
|
template <uint X>
|
|
|
SmallVector &operator=(const SmallVector<T, X> &other)
|
|
|
{
|
|
|
std::vector<T>::operator=(other);
|
|
|
return *this;
|
|
|
}
|
|
|
|
|
|
~SmallVector() = default;
|
|
|
|
|
|
/**
|
|
|
* Insert a new item at a specific position into the vector, moving all following items.
|
|
|
* @param item Position at which the new item should be inserted
|
|
|
* @return pointer to the new item
|
|
|
*/
|
|
|
inline T *Insert(T *item)
|
|
|
{
|
|
|
assert(item >= this->Begin() && item <= this->End());
|
|
|
|
|
|
size_t start = item - this->Begin();
|
|
|
std::vector<T>::insert(std::vector<T>::begin() + start);
|
|
|
return this->Begin() + start;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Search for the first occurrence of an item.
|
|
|
* The '!=' operator of T is used for comparison.
|
|
|
* @param item Item to search for
|
|
|
* @return The position of the item, or -1 when not present
|
|
|
*/
|
|
|
inline int FindIndex(const T &item) const
|
|
|
{
|
|
|
auto const it = std::find(std::vector<T>::begin(), std::vector<T>::end(), item);
|
|
|
return it == std::vector<T>::end() ? -1 : it - std::vector<T>::begin();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Tests whether a item is present in the vector, and appends it to the end if not.
|
|
|
* The '!=' operator of T is used for comparison.
|
|
|
* @param item Item to test for
|
|
|
* @return true iff the item is was already present
|
|
|
*/
|
|
|
inline bool Include(const T &item)
|
|
|
{
|
|
|
bool is_member = std::find(std::vector<T>::begin(), std::vector<T>::end(), item) != std::vector<T>::end();
|
|
|
if (!is_member) std::vector<T>::emplace_back(item);
|
|
|
return is_member;
|
|
|
}
|
|
|
|