# PIP: PIVector< T > Class Template Reference

PIVector< T > Class Template Reference

Dynamic array of any type. More...

Inherited by PIQueue< T >, and PIStack< T >.

## Public Member Functions

| PIVector ()
size_t | size () const
| Elements count.
ssize_t | size_s () const
| Elements count.
bool | isEmpty () const
| Return `"true"` if vector is empty, i.e. size = 0.
T & | back ()
| Last element of the vector.
const T & | back () const
| Last element of the vector.
T & | front ()
| First element of the vector.
const T & | front () const
| First element of the vector.
bool | operator== (const PIVector< T > &t) const
| Compare with vector "t".
bool | operator!= (const PIVector< T > &t) const
| Compare with vector "t".
bool | contains (const T &v) const
| Return `"true"` if vector has at least one element equal "t".
int | etries (const T &v) const
| Return how many times element "t" appears in vector.
PIVector< T > & | clear ()
| Clear vector. Equivalent to call `"resize(0)"`
PIVector< T > & | fill (const T &f=T())
| Fill vector with elements "t" leave size is unchanged and return reference to vector. More...
PIVector< T > & | resize (size_t new_size, const T &f=T())
| Resize vector to size "size". More...
PIVector< T > & | remove (size_t index, size_t count=1)
| Remove one element by index "index" and return reference to vector. More...
PIVector< T > & | sort (CompareFunc compare=compare_func)
| Sort vector using quick sort algorithm and standard compare function. More...
PIVector< T > & | enlarge (llong piv_size)
| Increase vector size with "size" elements.
PIVector< T > & | removeOne (const T &v)
| Remove no more than one element equal "v" and return reference to vector. More...
PIVector< T > & | removeAll (const T &v)
| Remove all elements equal "v" and return reference to vector. More...
PIVector< T > & | push_back (const T &v)
| Add new element "t" at the end of vector and return reference to vector.
PIVector< T > & | operator<< (const PIVector< T > &other)
| Add vector "t" at the end of vector and return reference to vector.
PIVector< T > & | push_front (const T &v)
| Add new element "t" at the beginning of vector and return reference to vector.
PIVector< T > & | pop_back ()
| Remove one element from the end of vector and return reference to vector.
PIVector< T > & | pop_front ()
| Remove one element from the beginning of vector and return reference to vector.
T | take_back ()
| Remove one element from the end of vector and return it.
T | take_front ()
| Remove one element from the beginning of vector and return it.

## Static Public Member Functions

static int | compare_func (const T *t0, const T *t1)
| Standard compare function for type "Type". Return 0 if t0 = t1, -1 if t0 < t1 and 1 if t0 > t1.

## Detailed Description

### template<typename T>
class PIVector< T >

Dynamic array of any type.

This class used to store dynamic array of any type of data. In memory data stored linear. You can insert item in any place of remove some items from any place. For quick add elements this is stream operator <<.

## Constructor & Destructor Documentation

template<typename T>

PIVector< T >::PIVector | ( |  | ) |

inline

Contructs an empty vector

## Member Function Documentation

template<typename T>

PIVector< T > & PIVector< T >::fill | ( | const T & | f = `T()` | ) |

inline

Fill vector with elements "t" leave size is unchanged and return reference to vector.

Example:

PIVector<char> vec;
vec << '1' << '2' << '3' << '4' << '5';
vec.fill('0');
piForeachC (char i, vec)
cout << i << ", ";
// 0, 0, 0, 0, 0,
template<typename T>

void PIVector< T >::resize | ( | size_t | new_size,
|  | const T & | f = `T()`
| ) |  |

inline

Resize vector to size "size".

Elements removed from end of vector if new size < old size, or added new elements = "new_type" if new size > old size.
Example:

PIVector<int> vec;
vec << 1 << 2;
vec.resize(4);
piForeachC (int & i, vec)
cout << i << ", ";
// 1, 2, 0, 0,
vec.resize(3);
piForeachC (int & i, vec)
cout << i << ", ";
// 1, 2, 0,

See also
  size(), clear()

template<typename T>

PIVector< T > & PIVector< T >::remove | ( | size_t | index,
|  | size_t | count = `1`
| ) |  |

inline

Remove one element by index "index" and return reference to vector.

Remove "count" elements by first index "index" and return reference to vector.

Example:

PIVector<char> vec;
vec << '1' << '2' << '3' << '4' << '5';
vec.remove(1);
piForeachC (char i, vec)
cout << i << ", ";
// 1, 3, 4, 5,

See also
  removeOne(), removeAll()

Example:

PIVector<char> vec;
vec << '1' << '2' << '3' << '4' << '5';
vec.remove(2, 2);
piForeachC (char i, vec)
cout << i << ", ";
// 1, 2, 5,

See also
  removeOne(), removeAll()

template<typename T>

PIVector< T > & PIVector< T >::sort | ( | CompareFunc | compare = `compare_func` | ) |

inline

Sort vector using quick sort algorithm and standard compare function.

Example:

PIVector<int> vec;
vec << 3 << 2 << 5 << 1 << 4;
vec.sort();
piForeachC (int & i, vec)
cout << i << ", ";
// 1, 2, 3, 4, 5,

With custom compare function:

static int mycomp(const int * v0, const int * v1) {
if (*v0 == *v1) return 0;
return *v0 < *v1 ? 1 : -1;
}
PIVector<int> vec;
vec << 3 << 2 << 5 << 1 << 4;
vec.sort(mycomp);
piForeachC (int & i, vec)
cout << i << ", ";
// 5, 4, 3, 2, 1,
template<typename T>

PIVector< T > & PIVector< T >::removeOne | ( | const T & | v | ) |

inline

Remove no more than one element equal "v" and return reference to vector.

Example:

PIVector<char> vec;
vec << '1' << '2' << '3' << '2' << '1';
vec.removeOne('2');
piForeachC (char i, vec)
cout << i << ", ";
// 1, 3, 2, 1,

See also
  remove(), removeAll()

template<typename T>

PIVector< T > & PIVector< T >::removeAll | ( | const T & | v | ) |

inline

Remove all elements equal "v" and return reference to vector.

Example:

PIVector<char> vec;
vec << '1' << '2' << '3' << '2' << '1';
vec.removeAll('2');
piForeachC (char i, vec)
cout << i << ", ";
// 1, 3, 1,

See also
  remove(), removeOne()