Level up your coding skills with
the C++ Standard Template
Library (STL):
An Introduction to the C++
Standard Library
BY JOYJIT CHOUDHURY
Class
 A class in C++ is a user defined type or
data structure declared with
keyword class that has data and functions
(also called methods) as its members
whose access is governed by the three
access specifiers private, protected or
public (by default access to members of
a class is private).
Class Definition (with int)
Class Definition (with int)
Class Definition (with int, float, char)
Class Definition (with int, float, char)
Template
 Templates are a feature of
the C++ programming language that allows
functions and classes to operate with generic
types. This allows a function or class to work on
many different data types without being
rewritten for each one. It’s a blueprint or formula
for creating a generic class or a function.
Generic Class Definition
Generic Class Definition
C++ Standard Library and STL
 The C++ Standard Library is a collection
of classes and functions, which are written in the core
language and part of the C++ ISO Standard itself.
 The Standard Template Library (STL) is a software library for
the C++ programming language that influenced many parts
of the C++ Standard Library. When the standardisation
happened, the language committee designed parts of the
C++ Standard Library (which is part of the language
standard) to very closely match the STL.
C++ Standard Library and STL
 This part of the C++ Standard Library has been referred
to as by many people – including prominent authors and
cplusplus.com – as the C++ STL.
 The C++ STL (Standard Template Library) is a powerful set
of general-purpose C++ template classes and functions
that implement many popular and commonly used
algorithms and data structures like vectors, lists, queues,
and stacks. It is highly efficient and rigorously tested. It
consists of three well structured components: Containers,
Algorithms and Iterators.
About this course
 In this course we will review some of the powerful
features of the C++ Standard Library (often
referred to as the STL), which is a great tool and
can help save a lot of time in programming
contests. It also makes the code more efficient,
precise and readable.
Containers
 The best way to get familiar with the STL is through
containers.
 A container is a holder object that stores a collection of
other objects (its elements). They are implemented as
class templates, which allows a great flexibility in the
types supported as elements.
 The container manages the storage space for its
elements and provides member functions to access
them, either directly or through iterators (reference
objects with similar properties to pointers).
Containers
 Containers replicate some of the commonly used Data Structures:
Data Structure Container
Linked List list
Stack stack
Queue queue
Dynamic Array vector
Heap Priority_queue
Associative Array Unordered_map, map
…………
pair
 Pair is a struct template that can store two objects of any
type as a single unit
 The individual elements can be accessed through it’s
public members first and second
 Defined in the header <utility>
pair
pair
Why use pair?
 When you have to store two objects of different types as a single unit.
 C++ does not allow returning multiple values from a function, but
allows returning of multiple values enclosed within a structure. In this
case, a pair can be very useful.
 Also, the <, >, == operators are overloaded to compare pairs
lexicographically. What that means is, when comparing two pairs lhs
and rhs, lhs.first and rhs.first are compared first and if both of
them are equal then lhs.second and rhs.second are compared.
Pair : returning a pair of values
Pair : returning a pair of values
Pair: comparison of objects
Pair: comparison of objects
An Introduction to the C++ Standard Library

An Introduction to the C++ Standard Library

  • 1.
    Level up yourcoding skills with the C++ Standard Template Library (STL): An Introduction to the C++ Standard Library BY JOYJIT CHOUDHURY
  • 2.
    Class  A classin C++ is a user defined type or data structure declared with keyword class that has data and functions (also called methods) as its members whose access is governed by the three access specifiers private, protected or public (by default access to members of a class is private).
  • 3.
  • 4.
  • 5.
    Class Definition (withint, float, char)
  • 6.
    Class Definition (withint, float, char)
  • 7.
    Template  Templates area feature of the C++ programming language that allows functions and classes to operate with generic types. This allows a function or class to work on many different data types without being rewritten for each one. It’s a blueprint or formula for creating a generic class or a function.
  • 8.
  • 9.
  • 10.
    C++ Standard Libraryand STL  The C++ Standard Library is a collection of classes and functions, which are written in the core language and part of the C++ ISO Standard itself.  The Standard Template Library (STL) is a software library for the C++ programming language that influenced many parts of the C++ Standard Library. When the standardisation happened, the language committee designed parts of the C++ Standard Library (which is part of the language standard) to very closely match the STL.
  • 11.
    C++ Standard Libraryand STL  This part of the C++ Standard Library has been referred to as by many people – including prominent authors and cplusplus.com – as the C++ STL.  The C++ STL (Standard Template Library) is a powerful set of general-purpose C++ template classes and functions that implement many popular and commonly used algorithms and data structures like vectors, lists, queues, and stacks. It is highly efficient and rigorously tested. It consists of three well structured components: Containers, Algorithms and Iterators.
  • 12.
    About this course In this course we will review some of the powerful features of the C++ Standard Library (often referred to as the STL), which is a great tool and can help save a lot of time in programming contests. It also makes the code more efficient, precise and readable.
  • 13.
    Containers  The bestway to get familiar with the STL is through containers.  A container is a holder object that stores a collection of other objects (its elements). They are implemented as class templates, which allows a great flexibility in the types supported as elements.  The container manages the storage space for its elements and provides member functions to access them, either directly or through iterators (reference objects with similar properties to pointers).
  • 14.
    Containers  Containers replicatesome of the commonly used Data Structures: Data Structure Container Linked List list Stack stack Queue queue Dynamic Array vector Heap Priority_queue Associative Array Unordered_map, map …………
  • 15.
    pair  Pair isa struct template that can store two objects of any type as a single unit  The individual elements can be accessed through it’s public members first and second  Defined in the header <utility>
  • 16.
  • 17.
  • 18.
    Why use pair? When you have to store two objects of different types as a single unit.  C++ does not allow returning multiple values from a function, but allows returning of multiple values enclosed within a structure. In this case, a pair can be very useful.  Also, the <, >, == operators are overloaded to compare pairs lexicographically. What that means is, when comparing two pairs lhs and rhs, lhs.first and rhs.first are compared first and if both of them are equal then lhs.second and rhs.second are compared.
  • 19.
    Pair : returninga pair of values
  • 20.
    Pair : returninga pair of values
  • 21.
  • 22.