This slide brushes up on the concepts of class and templates in C++. It introduces the different sections of the C++ Standard Library and talks about std::pair in further details.
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
An Introduction to the C++ Standard Library
1. Level up your coding skills with
the C++ Standard Template
Library (STL):
An Introduction to the C++
Standard Library
BY JOYJIT CHOUDHURY
2. 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).
7. 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.
10. 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.
11. 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.
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 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).
14. 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
…………
15. 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>
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.