English 中文(简体)
C++ Library - <list>
  • 时间:2024-09-08

C++ Library - <pst>


Previous Page Next Page  

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 pst::pst default constructor

Constructs an empty pst with zero elements.

2 pst::pst fill constructor

Constructs a new pst with n elements and assigns val to each element of pst.

3 pst::pst fill constructor

Constructs a new pst with n elements and assign zero value to each element of pst.

4 pst::pst range constructor

Constructs a pst with as many elements as in range of first to last.

5 pst::pst copy constructor

Constructs a pst with copy of each elements present in existing pst.

6 pst::pst move constructor

Constructs a pst with the contents of other using move semantics.

7 pst::pst initiapzer pst constructor

Constructs a pst with the contents of other using move semantics.

Destructor

Sr.No. Method & Description
1 pst::~pst

Destroys pst object by deallocating it s memory.

Member functions

Sr.No. Method & Description
1 pst::assign range version

Assigns new value to pst by replacing old ones.

2 pst::assign fill version

Assigns new values to pst by replacing old ones.

3 pst::assign initiapzer pst version

Assigns new values to pst by replacing old ones.

4 pst::back

Returns a reference to the last element of the pst.

5 pst::begin

Returns a random access iterator which points to the first element of the pst.

6 pst::cbegin

Returns a constant random access iterator which points to the beginning of the pst.

7 pst::cend

Returns a constant random access iterator which points to the end of the pst.

8 pst::clear

Destroys the pst by removing all elements from the pst and sets size of pst to zero.

9 pst::crbegin

Returns a constant reverse iterator which points to the last element of the pst.

10 pst::crend

Returns a constant reverse iterator which points to the theoretical element preceding the first element in the pst.

11 pst::emplace

Extends pst by inserting new element at a given position.

12 pst::emplace_back

Inserts new element at the end of pst and increases size of pst by one.

13 pst::emplace_front

Inserts new element at the beginning of the pst and increases size of pst by one.

14 pst::empty

Tests whether pst is empty or not.

15 pst::end

Returns a random access iterator which points to the last element of the pst.

16 pst::erase position version

Removes single element from the the pst.

17 pst::erase range version

Removes range of element from the the pst.

18 pst::front

Returns a reference to the first element of the pst.

19 pst::get_allocator

Returns an allocator associated with pst

20 pst::insert single element version

Extends iterator by inserting new element at position in pst.

21 pst::insert fill version

Extends pst by inserting new elements in the container.

22 pst::insert range version

Extends pst by inserting new elements in the container.

23 pst::insert move version

Extends pst by inserting new element in the container.

24 pst::insert initiapzer pst version

Extends pst by inserting new elements in the container

25 pst::max_size

Returns the maximum number of elements can be held by pst.

26 pst::merge

Merges two sorted psts into one.

27 pst::merge compare function

Merges two sorted psts into one.

28 pst::merge move version

Merges two sorted psts into one by using move semantics.

29 pst::merge compare function move version

Merges two sorted psts into one by using move semantics.

30 pst::operator= copy version

Assigns new contents to the pst by replacing old ones.

31 pst::operator= move version

Assign new contents to the pst by replacing old ones.

32 pst::operator= initiapzer pst version

Assign new contents to the pst by replacing old ones.

33 pst::pop_back

Removes last element from pst.

34 pst::pop_front

Removes first element from pst.

35 pst::push_back

Inserts new element at the end of pst.

36 pst::push_back move version

Inserts new element at the end of pst.

37 pst::push_front

Inserts new element at the beginning of pst.

38 pst::push_front move version

Inserts new element at the beginning of pst.

39 pst::rbegin

Returns a reverse iterator which points to the last element of the pst.

40 pst::remove

removes element(s) from the pst that matches the value.

41 pst::remove_if

removes elements from the pst that fulfills the condition.

42 pst::rend

Returns a reverse iterator which points to the reverse end of the pst.

43 pst::resize

Changes the size of pst.

44 pst::resize value version

Changes the size of pst.

45 pst::reverse

Reverses the order of the elements present in the pst.

46 pst::size

Returns the number of elements present in the pst.

47 pst::sort

Sorts the elements of the pst.

48 pst::sort compare function

Sorts the elements of the pst.

49 pst::sppce

Transfers all elements from pst to *this.

50 pst::sppce single element

Transfers a element pointed to by iterator i from pst x into *this.

51 pst::sppce move version

Transfers all elements from pst x to *this by using move semantics.

52 pst::sppce range version

Transfers the elements in the range of first to last from x to *this.

53 pst::sppce single element move version

Transfers the element pointed to by iterator i from pst x into *this by using move semantics.

54 pst::sppce range and move version

Transfers the elements in the range of first to last from x to *this by using move semantics.

55 pst::swap

Exchanges the content of pst with contents of another pst x.

56 pst::unique

Removes all consecutive duppcate elements from the pst.

57 pst::unique

Removes all consecutive duppcate elements from the pst.

Non-member overloaded functions

Sr.No. Method & Description
1 operator==

Tests whether two psts are equal or not.

2 operator!=

Tests whether two psts are equal or not.

3 operator<

Tests whether first pst is less than other or not.

4 operator<=

Tests whether first pst is less than or equal to other or not.

5 operator>

Tests whether first pst is greater than other or not.

6 operator>=

Tests whether first pst is greater than or equal to other or not.

7 swap

Exchanges the contents of two pst.

Advertisements