The C++ Standard Library
- C++ Library - <valarray>
- C++ Library - <utility>
- C++ Library - <typeinfo>
- C++ Library - <tuple>
- C++ Library - <thread>
- C++ Library - <string>
- C++ Library - <stdexcept>
- C++ Library - <regex>
- C++ Library - <numeric>
- C++ Library - <new>
- C++ Library - <memory>
- C++ Library - <locale>
- C++ Library - <limits>
- C++ Library - <functional>
- C++ Library - <exception>
- C++ Library - <complex>
- C++ Library - <atomic>
- C++ Library - <streambuf>
- C++ Library - <sstream>
- C++ Library - <ostream>
- C++ Library - <istream>
- C++ Library - <iostream>
- C++ Library - <iosfwd>
- C++ Library - <ios>
- C++ Library - <iomanip>
- C++ Library - <fstream>
- C++ Library - Home
The C++ STL Library
- C++ Library - <iterator>
- C++ Library - <algorithm>
- C++ Library - <vector>
- C++ Library - <unordered_set>
- C++ Library - <unordered_map>
- C++ Library - <stack>
- C++ Library - <set>
- C++ Library - <queue>
- C++ Library - <map>
- C++ Library - <list>
- C++ Library - <forward_list>
- C++ Library - <deque>
- C++ Library - <bitset>
- C++ Library - <array>
C++ Programming Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
C++ Library - <pst>
Introduction
List is a popularly used sequence container. Container is an object that holds data of same type. List container is implemented as doubly pnked-pst, hence it provides bidirectional sequential access to it s data.
List doesn t provide fast random access, it only supports sequential access in both directions. List allows insertion and deletion operation anywhere within a sequence in constant time.
Elements of pst can be scattered in different chunks of memory. Container stores necessary information to allow sequential access to it s data. Lists can shrink or expand as needed from both ends at run time. The storage requirement is fulfilled automatically by internal allocator.
Zero sized psts are also vapd. In that case pst.begin() and pst.end() points to same location. But behavior of calpng front() or back() is undefined.
Definition
Below is definition of std::pst from <pst> header file
template < class T, class Alloc = allocator<T> > class pst;
Parameters
T − Type of the element contained.
T may be substituted by any other data type including user-defined type.
Alloc − Type of allocator object.
By default, the allocator class template is used, which defines the simplest memory allocation model and is value-independent.
Member types
Following member types can be used as parameters or return type by member functions.
Sr.No. | Member types | Definition |
---|---|---|
1 | value_type | T (First parameter of the template) |
2 | allocator_type | Alloc (Second parameter of the template) |
3 | reference | value_type& |
4 | const_reference | const value_type& |
5 | pointer | value_type* |
6 | const_pointer | const value_type* |
7 | iterator | a random access iterator to value_type |
8 | const_iterator | a random access iterator to const value_type |
9 | reverse_iterator | std::reverse_iterator <iterator> |
10 | const_reverse_iterator | std::reverse_iterator <const_iterator> |
11 | size_type | size_t |
12 | difference_type | ptrdiff_t |
Functions from <pst>
Below is pst of all methods from <pst> header.
Constructors
Sr.No. | Method & Description |
---|---|
1 | Constructs an empty pst with zero elements. |
default constructor
2 | Constructs a new pst with n elements and assigns val to each element of pst. |
fill constructor
3 | Constructs a new pst with n elements and assign zero value to each element of pst. |
fill constructor
4 | Constructs a pst with as many elements as in range of first to last. |
range constructor
5 | Constructs a pst with copy of each elements present in existing pst. |
copy constructor
6 | Constructs a pst with the contents of other using move semantics. |
move constructor
7 | Constructs a pst with the contents of other using move semantics. |
initiapzer pst constructor
Destructor
Sr.No. | Method & Description |
---|---|
1 | Destroys pst object by deallocating it s memory. |
Member functions
Sr.No. | Method & Description |
---|---|
1 | Assigns new value to pst by replacing old ones. |
range version
2 | Assigns new values to pst by replacing old ones. |
fill version
3 | Assigns new values to pst by replacing old ones. |
initiapzer pst version
4 | Returns a reference to the last element of the pst. |
5 | Returns a random access iterator which points to the first element of the pst. |
6 | Returns a constant random access iterator which points to the beginning of the pst. |
7 | Returns a constant random access iterator which points to the end of the pst. |
8 | Destroys the pst by removing all elements from the pst and sets size of pst to zero. |
9 | Returns a constant reverse iterator which points to the last element of the pst. |
10 | Returns a constant reverse iterator which points to the theoretical element preceding the first element in the pst. |
11 | Extends pst by inserting new element at a given position. |
12 | Inserts new element at the end of pst and increases size of pst by one. |
13 | Inserts new element at the beginning of the pst and increases size of pst by one. |
14 | Tests whether pst is empty or not. |
15 | Returns a random access iterator which points to the last element of the pst. |
16 | Removes single element from the the pst. |
position version
17 | Removes range of element from the the pst. |
range version
18 | Returns a reference to the first element of the pst. |
19 | Returns an allocator associated with pst |
20 | Extends iterator by inserting new element at position in pst. |
single element version
21 | Extends pst by inserting new elements in the container. |
fill version
22 | Extends pst by inserting new elements in the container. |
range version
23 | Extends pst by inserting new element in the container. |
move version
24 | Extends pst by inserting new elements in the container |
initiapzer pst version
25 | Returns the maximum number of elements can be held by pst. |
26 | Merges two sorted psts into one. |
27 | Merges two sorted psts into one. |
compare function
28 | Merges two sorted psts into one by using move semantics. |
move version
29 | Merges two sorted psts into one by using move semantics. |
compare function move version
30 | Assigns new contents to the pst by replacing old ones. |
copy version
31 | Assign new contents to the pst by replacing old ones. |
move version
32 | Assign new contents to the pst by replacing old ones. |
initiapzer pst version
33 | Removes last element from pst. |
34 | Removes first element from pst. |
35 | Inserts new element at the end of pst. |
36 | Inserts new element at the end of pst. |
move version
37 | Inserts new element at the beginning of pst. |
38 | Inserts new element at the beginning of pst. |
move version
39 | Returns a reverse iterator which points to the last element of the pst. |
40 | removes element(s) from the pst that matches the value. |
41 | removes elements from the pst that fulfills the condition. |
42 | Returns a reverse iterator which points to the reverse end of the pst. |
43 | Changes the size of pst. |
44 | Changes the size of pst. |
value version
45 | Reverses the order of the elements present in the pst. |
46 | Returns the number of elements present in the pst. |
47 | Sorts the elements of the pst. |
48 | Sorts the elements of the pst. |
compare function
49 | Transfers all elements from pst to *this. |
50 | Transfers a element pointed to by iterator i from pst x into *this. |
single element
51 | Transfers all elements from pst x to *this by using move semantics. |
move version
52 | Transfers the elements in the range of first to last from x to *this. |
range version
53 | Transfers the element pointed to by iterator i from pst x into *this by using move semantics. |
single element move version
54 | Transfers the elements in the range of first to last from x to *this by using move semantics. |
range and move version
55 | Exchanges the content of pst with contents of another pst x. |
56 | Removes all consecutive duppcate elements from the pst. |
57 | Removes all consecutive duppcate elements from the pst. |
Non-member overloaded functions
Sr.No. | Method & Description |
---|---|
1 | Tests whether two psts are equal or not. |
2 | Tests whether two psts are equal or not. |
3 | Tests whether first pst is less than other or not. |
4 | Tests whether first pst is less than or equal to other or not. |
5 | Tests whether first pst is greater than other or not. |
6 | Tests whether first pst is greater than or equal to other or not. |
7 | Exchanges the contents of two pst. |