PIP 5.5.3
Platform-Independent Primitives
Files | Classes
Containers

Various standart containers realization. More...

Files

file  picontainers.h
 Base macros for generic containers.
 
file  pideque.h
 Declares PIDeque.
 
file  pimap.h
 Declares PIMap.
 
file  pipair.h
 Declares PIPair.
 
file  piqueue.h
 Declares PIQueue.
 
file  pistack.h
 Declares PIStack.
 
file  pivector.h
 Declares PIVector.
 

Classes

class  PIDeque< T >
 Sequence two-way linear container - dynamic size array of any type. More...
 
class  PIMap< Key, T >
 Associative array. More...
 
class  PIMapIteratorConst< Key, T >
 Java-style iterator for PIMap. More...
 
class  PIMapIteratorConstReverse< Key, T >
 Java-style reverse iterator for PIMap. More...
 
class  PIMapIterator< Key, T >
 Java-style iterator for PIMap. More...
 
class  PIMapIteratorReverse< Key, T >
 Java-style reverse iterator for PIMap. More...
 
class  PIPair< Type0, Type1 >
 Class template that provides a way to store two heterogeneous objects as a single unit. More...
 
class  PIQueue< T >
 A container class inherited from the PIDeque with queue functionality. More...
 
class  PIStack< T >
 A container class inherited from the PIVector with stack functionality. More...
 
class  PIVector< T >
 Sequence linear container - dynamic size array of any type. More...
 

Detailed Description

Various standart containers realization.

Building with CMake

find_package(PIP REQUIRED)
target_link_libraries([target] PIP)

Content

Class Description
PIVector Linear array, fast back insert
PIDeque Linear array, fast back and front insert
PIMap Dictionary container, key/value array
PISet Set container
PIStack Stack
PIQueue Queue
PIPair Pair
PIVector2D Linear 2D rectangle array

STL-Style Iterators

They are compatible with Qt's and STL's generic algorithms and are optimized for speed.

For each container class, there are two STL-style iterator types: one that provides read-only access and one that provides read-write access. Read-only iterators should be used wherever possible because they are faster than read-write iterators. Read-only iterator - const_iterator. Read-write iterator - iterator.

The API of the STL iterators is modelled on pointers in an array. For example, the ++ operator advances the iterator to the next item, and the * operator returns the item that the iterator points to. The iterator type is just a typedef for T *, and the const_iterator type is just a typedef for const T *. STL-style iterators point directly at items. The begin() function of a container returns an iterator that points to the first item in the container. The end() function of a container returns an iterator to the imaginary item one position past the last item in the container. end() marks an invalid position; it must never be dereferenced. It is typically used in a loop's break condition.

Example:

for (PIVector<int>::const_iterator i = v.begin(); i != v.end(); ++i) piCout << *i;
std::for_each(v.begin(), v.end(), [](int n){std::cout << n << ' ';});
Sequence linear container - dynamic size array of any type.
Definition: pivector.h:118
iterator begin()
Iterator to the first element.
Definition: pivector.h:553
#define piCout
Macro used for conditional (piDebug) output to PICout(StdOut)
Definition: picout.h:35

If the list is empty, begin() equals end(), so we never execute the loop.

iterators

The following table summarizes the STL-style iterators' API:

Expression Behavior
*i Returns the current item
++i Advances the iterator to the next item
i += n Advances the iterator by n items
--i Moves the iterator back by one item
i -= n Moves the iterator back by n items
i - j Returns the number of items between iterators i and j

The ++ and -- operators are available both as prefix (++i, --i) and postfix (i++, i--) operators. The prefix versions modify the iterators and return a reference to the modified iterator; the postfix versions take a copy of the iterator before they modify it, and return that copy. In expressions where the return value is ignored, we recommend that you use the prefix operators (++i, --i), as these are slightly faster. For non-const iterator types, the return value of the unary * operator can be used on the left side of the assignment operator.

Ivan Pelipenko peri4.nosp@m.ko@y.nosp@m.andex.nosp@m..ru; Andrey Bychkov work..nosp@m.a.b@.nosp@m.yande.nosp@m.x.ru;