Codementor Events

The Standard Template Library

Published Jul 29, 2019

The Library includes three types of generic entities :

  • Containers
  • Iterators
  • Algorithms

Algorithms arefrequently used functions that can be applied to different data structures. The application is mediated through the iterators that determine which algorithms can be applied to which type of objects.

Containers

A data structure that holds some objects.

The STL includes following containers :

  • deque
  • list
  • map
  • multimap
  • set
  • multiset
  • stack
  • queue
  • priority_queue
  • vector

The STL containers are implemented as template classes that include member functions specifying what operations can be performed on the elements stored in the data structure.

Iterators

An iterator is an object used to reference an element stored in a container. An iterator allows for accessing information included in a container so that desired operations can be performed on these elements.

No iterators are supported for the stack, queue, priority_queue containers

Iterator operations for classes list, map, multimap, set and multiset are :
i1 and i2 are iterators and n is number

i1++, ++i1, i1--, i2--
i1 = i2
i1 == i2, i1 != i2
*i1

In addition to these operations for classes deque and vectors some more are :

i1 < i2, i1 <= i2, i1 > i2, i1 >= i2
i1 + n, i1 - n
i1 +=n , i1 -= n
i1[n]

Algorithms

The STL provides some 70 generic functions called algorithms that can be applied to STL containers and arrays.
These algorithms are implementing operations that are very frequently used in most programs.
Example :

random_shuffle(c.begin(),c.end());
It randomly reorders all the elements of the container c.
i3 = find(i1,i2,e1);
returns an iterator indicating positon of element e1 between i1 and i2(not including).

The complete list of algorithms can be found here : click

THANK YOU
Ayush Jain

Discover and read more posts from Ayush Jain
get started
post comments1Reply
Siddhartha Jain
5 years ago

👍💖👏👏