+ All Categories
Home > Software > An Introduction to the C++ Standard Library

An Introduction to the C++ Standard Library

Date post: 05-Apr-2017
Category:
Upload: joyjit-choudhury
View: 75 times
Download: 0 times
Share this document with a friend
23
Level up your coding skills with the C++ Standard Template Library (STL): An Introduction to the C++ Standard Library BY JOYJIT CHOUDHURY
Transcript
Page 1: An Introduction to the C++ Standard Library

Level up your coding skills with

the C++ Standard Template

Library (STL):

An Introduction to the C++ Standard Library

BY JOYJIT CHOUDHURY

Page 2: An Introduction to the C++ Standard Library

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).

Page 3: An Introduction to the C++ Standard Library

Class Definition (with int)

Page 4: An Introduction to the C++ Standard Library

Class Definition (with int)

Page 5: An Introduction to the C++ Standard Library

Class Definition (with int, float, char)

Page 6: An Introduction to the C++ Standard Library

Class Definition (with int, float, char)

Page 7: An Introduction to the C++ Standard Library

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.

Page 8: An Introduction to the C++ Standard Library

Generic Class Definition

Page 9: An Introduction to the C++ Standard Library

Generic Class Definition

Page 10: An Introduction to the C++ Standard Library

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.

Page 11: An Introduction to the C++ Standard Library

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.

Page 12: An Introduction to the C++ Standard Library

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.

Page 13: An Introduction to the C++ Standard Library

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).

Page 14: An Introduction to the C++ Standard Library

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

…………

Page 15: An Introduction to the C++ Standard Library

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>

Page 16: An Introduction to the C++ Standard Library

pair

Page 17: An Introduction to the C++ Standard Library

pair

Page 18: An Introduction to the C++ Standard Library

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 lhsand rhs, lhs.first and rhs.first are compared first and if both of

them are equal then lhs.second and rhs.second are compared.

Page 19: An Introduction to the C++ Standard Library

Pair : returning a pair of values

Page 20: An Introduction to the C++ Standard Library

Pair : returning a pair of values

Page 21: An Introduction to the C++ Standard Library

Pair: comparison of objects

Page 22: An Introduction to the C++ Standard Library

Pair: comparison of objects

Page 23: An Introduction to the C++ Standard Library

Recommended