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













SourceForge.net Logo

BiVector

 

template <class T>

class BiVector : private MoveableAndDeepCopyOption< BiVector<T> > 

T

Type of elements stored in the BiVector. T is required to be moveable and must have either deep copy constructor, pick constructor or default constructor.

 

Vector flavor of bidirectional container. Allows adding elements at both sides of sequence in constant amortized time.

 

Like any other NTL container, BiVector is a moveable type with pick and optional deep copy transfer semantics. Calling methods of picked a BiVector is logic error with the exceptions of:

void operator=(pick_ Vector& v)

void operator<<=(const Vector& v) (defined using DeepCopyOptionTemplate)

void Clear()

bool IsPicked() const

 

Optional deep copy is implemented through DeepCopyOptionTemplate macro.

 

 

Constructor Detail

 

BiVector()

Default constructor. Creates an empty BiVector.

 


 

BiVector(BiVector&& src)

Pick constructor. Transfers source BiVector src in low constant time, but destroys it by picking.

 


 

void operator=(BiVector&& src)

Pick assignment. Transfers source BiVector src in low constant time, but destroys it by picking.

 


 

BiVector(const BiVector& src, int)

Optional deep copy constructor. Creates a deep copy of src.

 


 

BiVector(std::initializer_list<Tinit)

C++11 initialization.

 


 

~BiVector()

Default destructor. Invokes the destructor of every element in the BiVector.

 

 

Public Method List

 

T& AddHead()

Adds a new default constructed element at the head of the BiVector. The new element will be at position 0. Returns reference to the newly added default constructed element.

Requires T to have default constructor.

Invalidates iterators and references to the BiVector.

 


 

T& AddTail()

Adds a new default constructed element at the tail of the BiVector. The new element will be at position GetCount() - 1. Returns reference to the newly added default constructed element.

Requires T to have default constructor.

Invalidates iterators and references to the BiVector.

 


 

void AddHead(const T& x)

Adds a new element with the specified value x at the head of the BiVector. The new element will be at position 0.

Requires T to have deep copy constructor.

Invalidates iterators and references to the BiVector.

 


 

void AddTail(const T& x)

Adds a new element with the specified value x at the tail of the BiVector. The new element will be at position GetCount() - 1.

Requires T to have deep copy constructor.

Invalidates iterators and references to the BiVector.

 


 

void AddHeadPick(T&& x)

Adds a new element at the head of the BiVector and picks value of the parameter x. The new element will be at position 0.

Requires T to have pick constructor.

Invalidates iterators and references to the BiVector.

 


 

void AddTailPick(T&& x)

Adds a new element at the tail of the BiVector and picks value of the parameter x. The new element will be at position GetCount() - 1.

Requires T to have pick constructor.

Invalidates iterators and references to the BiVector.

 


 

T& Head()

Returns a reference to the head of the BiVector . Same as operator[](0).

 


 

T& Tail()

Returns a reference to the tail of the BiVector . Same as operator[](GetCount() - 1).

 


 

const T& Head() const

Returns a const reference to the head of the BiVector . Same as operator[](0).

 


 

const T& Tail() const

Returns a const reference to the tail of the BiVector . Same as operator[](GetCount() - 1).

 


 

void DropHead()

Removes the element at the head of the BiVector.

Invalidates iterators and references to the BiVector.

 


 

void DropTail()

Removes the element at the tail of the BiVector.

Invalidates iterators and references to the BiVector.

 


 

T& operator[](int i)

Returns a reference to the element at the specified position i.

 


 

const T& operator[](int iconst

Returns a const reference to the element at the specified position i.

 


 

int GetCount() const

Returns the number of elements in the BiVector.

 


 

bool IsEmpty() const

Tests whether the BiVector is empty. Same as GetCount() == 0.

 


 

void Clear()

Removes all elements from the BiVector.

 


 

void Shrink()

Minimizes memory consumption of the BiVector by minimizing capacity.

 


 

void Reserve(int n)

Reserves capacity. If required capacity n is greater than the current capacity, capacity is increased to the required value.

 


 

int GetAlloc() const

Returns current capacity of the BiVector.

 


 

void Serialize(Stream& s)

Serializes content of the BiVector to/from the Stream s.

Requires T to have serialization operator defined.

 


 

bool IsPicked()

Returns true if BiVector has been picked, false otherwise.

 


 

void operator=(pick_ BiVector& src)

Pick operator. Transfers source BiVector src in low constant time, but destroys it by picking.

 


 

typedef T ValueType

Typedef of T for use in templated algorithms.

 


 

typedef IIterator<BiVector> Iterator

Iterator type.

 


 

typedef ConstIIterator<BiVector> ConstIterator

Constant iterator type.

 


 

ConstIterator Begin() const

Returns a constant iterator to the first element in the BiVector.

 


 

ConstIterator End() const

Returns a constant iterator to the position just beyond the last element in the BiVector.

 


 

ConstIterator GetIter(int posconst

Returns a constant iterator to the element at the specified position pos. Same as Begin() + pos. The benefit of this method is that pos is range checked in debug mode.

 


 

Iterator Begin()

Returns a non-constant iterator to the first element in the BiVector.

 


 

Iterator End()

Returns non-constant iterator to the position just beyond the last element in the BiVector.

 


 

Iterator GetIter(int pos)

Returns a non-constant iterator to the element at the specified position. Same as Begin() + pos. The benefit of this method is that pos is range checked in debug mode.

 


 

friend void Swap(BiVector& a, BiVector& b)

Specialization of the generic Swap for BiVectors. Swaps BiVectors in low constant time operation.

 

 

Global Operators

 

friend BiVector& operator<<(BiVector& b, const T& x)

Operator replacement of void AddTail(const T&x). By returning a reference to the BiVector it allows adding more elements in a single expression, thus e.g. allowing to construct a temporary BiVector as part of an expression like Foo(BiVector<int>() << 1 << 2 << 4).

Requires T to have deep copy constructor.

Invalidates iterators and references to the BiVector.

 


 

friend BiVector& operator>>(const T& x, BiVector& b)

Operator replacement of void AddHead(const T&x). By returning a reference to the BiVector it allows adding more elements in a single expression, thus e.g. allowing to construct a temporary BiVector as part of an expression like Foo(1 >> (2 >> BiVector<int>())).

Requires T to have deep copy constructor.

Invalidates iterators and references to the BiVector.

 

 

Last edit by klugier on 06/12/2016. Do you want to contribute?. T++