Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
UppHub
Status & Roadmap
FAQ
Authors & License
Forums
Funding U++
Search on this site











SourceForge.net Logo

SourceForge.net Logo

GitHub Logo

Discord Logo

InArray

 

template <class T>

class InArray : public MoveableAndDeepCopyOptionInVector<T> > 

InArray is an Array flavor of InVector. Unlike InVector, it does not require to elements to be Moveable and even allows storing elements derived from T.

Generally, any method that changes the number of elements in InVector (plus Shrink method) invalidates any iterators to InVector but, unlike InVector, DOES NOT invalidate references to elements in InVector.

InVector has default pick transfer semantics with optional deep-copy. It is Moveable.

 

Public Method List

 

T& Insert(int i, T *newt)

Inserts a new element. Element is specified by pointer to an object created using operator new. InArray takes over ownership of this object. This variant allows the use of InArray as a polymorphic container, because the type of the added element can be either T or a type derived from T. No constructor is applied. Invalidates iterators.

 


 

T& Insert(int i)

Inserts a default constructed element at i. Invalidates iterators.

 


 

T& Insert(int i, const T& x)

Inserts a copy of x at i. Invalidates iterators.

 


 

template <class TT, class... ArgsTT& InsertCreate(int i, Args&&... args)

Creates a in-place constructed element (with args as constructor parameters) of type TT and inserts it at i. Invalidates iterators.

 


 

void InsertN(int i, int count)

Inserts count default constructed elements at i. Invalidates iterators.

 


 

void Remove(int i, int count = 1)

Removes count elements starting at i. Invalidates iterators.

 


 

const T& operator[](int iconst

T& operator[](int i)

Returns an element at i.

 


 

T& Add()

Same as Insert(GetCount()). Invalidates iterators.

 


 

T& Add(const T& x)

Same as Insert(GetCount(), x). Invalidates iterators.

 


 

void AddN(int n)

Same as InsertN(GetCount(), n). Invalidates iterators.

 


 

T& Add(T *newt)

Same as Insert(GetCount(), newt). Invalidates iterators.

 


 

template <class TT, class... ArgsTT& Create(Args&&... args)

Same as InsertCreate<TT>(GetCount(), args...). Invalidates iterators.

 


 

int GetCount() const

Returns the number of elements.

 


 

bool IsEmpty() const

Same as GetCount() == 0.

 


 

void Trim(int n)

Same as Remove(n, GetCount() - n). Invalidates iterators.

 


 

void SetCount(int n)

Sets the number of elements to be n either removing surplus elements or using AddN to extend the InArray. Invalidates iterators.

 


 

void Clear()

Same as Remove(0, GetCount()). Invalidates iterators.

 


 

T& At(int i)

If i >= GetCount, performs SetCount(i + 1) to make sure element at i exists. elements. In all cases, returns a reference to element at i. Invalidates iterators.

 


 

void Shrink()

Miminizes the heap memory allocated by InVector. Invalidates iterators.

 


 

void Set(int i, const T& x, int count)

Sets the value of count elements starting at i to x.

 


 

T& Set(int i, const T& x)

Sets the value of element at i to x.

 


 

void Swap(int i1, int i2)

Swaps elements at position i1 and i2.

 


 

void Drop(int n = 1)

Removes n elements at the end of InArray.

 


 

T& Top()

const T& Top() const

Returns a reference to the last element.

 


 

T Pop()

Returns a copy to the last element and removes it.

 


 

template <class Lint FindUpperBound(const T& val, const L& lessconst

int FindUpperBound(const T& valconst

Finds the upper bound for val using less / StdLess<T> as comparison predicate. InArray should be sorted using the same predicate.

 


 

template <class Lint FindLowerBound(const T& val, const L& lessconst

int FindLowerBound(const T& valconst

Finds the lower bound for val using less / StdLess<T> as comparison predicate. InArray must be sorted using the same predicate.

 


 

template <class Lint InsertUpperBound(const T& val, const L& lss)

int InsertUpperBound(const T& val)

Inserts the element at posiotion found using FindUpperBound (but the whole operation is optimized relative to FindUpperBound/Insert pair). InArray must be sorted using the same predicate.

 


 

template <class Lint Find(const T& val, const L& lessconst

int Find(const T& valconst

Finds the position of val in InVector sorted using less / StdLess<T>. If not found, returns negative value.

 


 

ConstIterator Begin() const

ConstIterator End() const

ConstIterator GetIter(int posconst

Iterator Begin()

Iterator End()

Iterator GetIter(int pos)

Returns constant/nonconstant iterator to the begin/end/pos.

 


 

bool IsPicked() const

Returns constant/nonconstant iterator to the begin/end/pos.

 


 

InArray()

Default constructor.

 


 

InArray(InArray&& v)

Pick constructor.

 


 

InArray& operator=(InArray&& v)

Pick assignment.

 


 

InArray(const InArray& v, int)

Deep copy constructor.

 


 

InArray(std::initializer_list<Tinit)

C++ 11 initialization.

 


 

void Swap(InArray& b)

Swaps InArray with b.

 

Do you want to contribute?