SlideShare a Scribd company logo
C++ STL
Ms.M.Jancypriya,
Asst. Prof., Dept. of CA,
Bon Secours College for Women,
Thanjavur.
STL – Standard Template Library
• Collections of useful classes for common data structures
• Ability to store objects of any type (template)
• Study of containers
• Containers form the basis for treatment of data structures
• Container – class that stores a collection of data
• STL consists of 10 container classes:
• Sequence containers
• Adapter containers
• Associative containers
What is the STL?
• Standard Template Library
• A collection of classes to make C++ programming more
efficient
• Algorithms, Containers, and Iterators
• Function objects,Allocators, and Adapters
Containers Containers
Function Objects
Iterators
STLAlgorithms
• Accept STL Iterators as arguments
• Sort(begin, end);
• 4 categories
• Non-modifying
For each, Find, Count, Equal, Search, etc.
• Mutating
Copy, Generate, Reverse, Remove, Swap, etc.
• Sorting Related
Sort, Stable sort, Binary search, Merge, etc.
• Numeric
Accumulate, Inner product, Partial sum,
Adjacent difference
STL Containers
• Sequence Container
• Stores data by position in linear order:
• First element, second element , etc:
• Associate Container
• Stores elements by key, such as name, social security number or
part number
• Access an element by its key which may bear no relationship to the
location of the element in the container
• Adapter Container
• Contains another container as its underlying storage structure
STL Containers
 Sequence Container
 Vector
 Deque
 List
 Adapter Containers
 Stack
 Queue
 Priority queue
 Associative Container
 Set, multiset
 Map, multimap
Vector Container
• Generalized array that stores a collection of elements of
the same data type
• Vector – similar to an array
• Vectors allow access to its elements by using an index in the range
from 0 to n-1 where n is the size of the vector
• Vector vs array
• Vector has operations that allow the collection to grow and contract
dynamically at the rear of the sequence``
Vector Container
Example:
#include <vector>
.
.
.
vector<int> scores (100); //100 integer scores
vector<Passenger>passengerList(20); //list of 20
passengers
Vector Container
• Allows direct access to the elements via an index operator
• Indices for the vector elements are in the range from 0 to
size() -1
• Example:
#include <vector>
vector <int> v(20);
v[5]=15;
List Container
• Stores elements by position
• Each item in the list has both a value and a memory
address (pointer) that identifies the next item in the
sequence
• To access a specific data value in the list, one must start
at the first position (front) and follow the pointers from
element to element until data item is located.
• List is not a direct access structure
• Advantage: ability to add and remove items efficiently at
any position in the sequence
Stack Container
• Adapter Container
• These containers restrict how elements enter and leave a
sequence
• Stack
• allows access at only one end of the sequence (top)
• Adds objects to container by pushing the object onto the stack
• Removes objects from container by popping the stack
• LIFO ordering (last end, first out)
Queue Container
• Queue
• Allows access only at the front and rear of the sequence
• Items enter at the rear and exit from the front
• Example: waiting line at a grocery store
• FIFO ordering (first-in first-out )
• push(add object to a queue)
• pop (remove object from queue)
Priority Queue Container
• Priority queue
• Operations are similar to those of a stack or queue
• Elements can enter the priority queue in any order
• Once in the container, a delete operation removes the largest (or
smallest) value
• Example: a filtering system that takes in elements and then
releases them in priority order 8
18 13
3 15
27
Set Container
• Set
• Collection of unique values, called keys or set members
• Contains operations that allow a programmer to:
• determine whether an item is a member of the set
• insert and delete items very efficiently
5 1 3
6 27 15
Buick
Ford
Jeep BMW
Set A Set B
Multi-Set Container
• A multi-set is similar to a set, but the same value can be in
the set more than once
• Multi-set container allows duplicates
Map Container
• Implements a key-value relationship
• Programmer can use a key to access corresponding
values
• Example: key could be a part number such as A24-57
that corresponds to a part: 8.75 price and Martin
manufacturer
A22-56
A23-57
A24-57
A24-57 8.75 Martin
A22-56 12.50 Callowa
y
A23-57 4.95 Mirage
Multi-map Container
• Similar to a map container
• Multi-map container allows duplicates
How to access Components - Iterator
• Iterator is an object that can access a collection of like
objects one object at a time.
• An iterator can traverse the collection of objects.
• Each container class in STL has a corresponding iterator
that functions appropriately for the container
• For example: an iterator in a vector class allows random
access
• An iterator in a list class would not allow random access
(list requires sequential access)
Common Iterator Operations
* Return the item that the iterator currently references
++ Move the iterator to the next item in the list
-- Move the iterator to the previous item in the
list
== Compare two iterators for equality
!= Compare two iterators for inequality
STL List Class
Constructors and assignment
• list <T> v;
• list<T> v(aList);
• l=aList;
Access
• l.front() ----returns 1st element in the list
• l.back()----returns the last element in the list
STL List
Insert and Remove
• l.push_front(value)
• l.push_back(value)
Iterator Delaration
• list<T>::iteratoritr;
Iterator Options
• itr = l.begin() set iterator to beginning of the list
• Itr = l.end() set iterator to after the end of the list
Writing classes that work with the STL
 Classes that will be stored in STL containers should
explicitly define the following:
◦ Default constructor
◦ Copy constructor
◦ Destructor
◦ operator =
◦ operator==
◦ operator<
 Not all of these are always necessary, but it might be
easier to define them than to figure out which ones
you actually need
 Many STL programming errors can be traced to
omitting or improperly defining these methods

More Related Content

What's hot

Wrapper classes
Wrapper classes Wrapper classes
SQL, Embedded SQL, Dynamic SQL and SQLJ
SQL, Embedded SQL, Dynamic SQL and SQLJSQL, Embedded SQL, Dynamic SQL and SQLJ
SQL, Embedded SQL, Dynamic SQL and SQLJ
Dharita Chokshi
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++
rprajat007
 
Constructor overloading & method overloading
Constructor overloading & method overloadingConstructor overloading & method overloading
Constructor overloading & method overloading
garishma bhatia
 
Java - Collections framework
Java - Collections frameworkJava - Collections framework
Java - Collections framework
Riccardo Cardin
 
Collection Framework in java
Collection Framework in javaCollection Framework in java
Collection Framework in java
CPD INDIA
 
Collections and generics
Collections and genericsCollections and generics
Collections and generics
Muthukumaran Subramanian
 
Delegates and events in C#
Delegates and events in C#Delegates and events in C#
Delegates and events in C#
Dr.Neeraj Kumar Pandey
 
Interface in java
Interface in javaInterface in java
Interface in java
PhD Research Scholar
 
sets and maps
 sets and maps sets and maps
sets and maps
Rajkattamuri
 
Constructor and Destructor
Constructor and DestructorConstructor and Destructor
Constructor and DestructorKamal Acharya
 
Java static keyword
Java static keywordJava static keyword
Java static keyword
Lovely Professional University
 
Templates in c++
Templates in c++Templates in c++
Templates in c++
ThamizhselviKrishnam
 
Abstract Class & Abstract Method in Core Java
Abstract Class & Abstract Method in Core JavaAbstract Class & Abstract Method in Core Java
Abstract Class & Abstract Method in Core Java
MOHIT AGARWAL
 
C++ Standard Template Library
C++ Standard Template LibraryC++ Standard Template Library
C++ Standard Template Library
Ilio Catallo
 
Access modifiers
Access modifiersAccess modifiers
Access modifiers
Jadavsejal
 
Standard Template Library
Standard Template LibraryStandard Template Library
Standard Template Library
Kumar Gaurav
 
Static Data Members and Member Functions
Static Data Members and Member FunctionsStatic Data Members and Member Functions
Static Data Members and Member Functions
MOHIT AGARWAL
 

What's hot (20)

Wrapper classes
Wrapper classes Wrapper classes
Wrapper classes
 
SQL, Embedded SQL, Dynamic SQL and SQLJ
SQL, Embedded SQL, Dynamic SQL and SQLJSQL, Embedded SQL, Dynamic SQL and SQLJ
SQL, Embedded SQL, Dynamic SQL and SQLJ
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++
 
Constructor overloading & method overloading
Constructor overloading & method overloadingConstructor overloading & method overloading
Constructor overloading & method overloading
 
Java - Collections framework
Java - Collections frameworkJava - Collections framework
Java - Collections framework
 
Collection Framework in java
Collection Framework in javaCollection Framework in java
Collection Framework in java
 
Collections and generics
Collections and genericsCollections and generics
Collections and generics
 
Delegates and events in C#
Delegates and events in C#Delegates and events in C#
Delegates and events in C#
 
Interface in java
Interface in javaInterface in java
Interface in java
 
sets and maps
 sets and maps sets and maps
sets and maps
 
Constructor and Destructor
Constructor and DestructorConstructor and Destructor
Constructor and Destructor
 
Java static keyword
Java static keywordJava static keyword
Java static keyword
 
Templates in c++
Templates in c++Templates in c++
Templates in c++
 
Constructor
ConstructorConstructor
Constructor
 
Abstract Class & Abstract Method in Core Java
Abstract Class & Abstract Method in Core JavaAbstract Class & Abstract Method in Core Java
Abstract Class & Abstract Method in Core Java
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
 
C++ Standard Template Library
C++ Standard Template LibraryC++ Standard Template Library
C++ Standard Template Library
 
Access modifiers
Access modifiersAccess modifiers
Access modifiers
 
Standard Template Library
Standard Template LibraryStandard Template Library
Standard Template Library
 
Static Data Members and Member Functions
Static Data Members and Member FunctionsStatic Data Members and Member Functions
Static Data Members and Member Functions
 

Similar to Standard template library

How to choose best containers in STL (C++)
How to choose best containers in STL (C++)How to choose best containers in STL (C++)
How to choose best containers in STL (C++)
Sangharsh agarwal
 
oops_final_ppt[1].pptx
oops_final_ppt[1].pptxoops_final_ppt[1].pptx
oops_final_ppt[1].pptx
12KrishnaPrasadH
 
MODULE-2.pptx
MODULE-2.pptxMODULE-2.pptx
MODULE-2.pptx
ASRPANDEY
 
Queues
Queues Queues
Queues
nidhisatija1
 
Collections Training
Collections TrainingCollections Training
Collections Training
Ramindu Deshapriya
 
02._Object-Oriented_Programming_Concepts.ppt
02._Object-Oriented_Programming_Concepts.ppt02._Object-Oriented_Programming_Concepts.ppt
02._Object-Oriented_Programming_Concepts.ppt
Yonas D. Ebren
 
Python programming
Python programmingPython programming
Python programming
sirikeshava
 
STRINGS IN JAVA
STRINGS IN JAVASTRINGS IN JAVA
Data structures and Algorithm analysis_Lecture 2.pptx
Data structures and Algorithm analysis_Lecture 2.pptxData structures and Algorithm analysis_Lecture 2.pptx
Data structures and Algorithm analysis_Lecture 2.pptx
AhmedEldesoky24
 
C# Non generics collection
C# Non generics collectionC# Non generics collection
C# Non generics collection
Prem Kumar Badri
 
Object Oriented Design and Programming Unit-05
Object Oriented Design and Programming Unit-05Object Oriented Design and Programming Unit-05
Object Oriented Design and Programming Unit-05
sivakumarmcs
 
Stack in Sata Structure
Stack in Sata StructureStack in Sata Structure
Stack in Sata Structure
Muhazzab Chouhadry
 
stacks and queues for public
stacks and queues for publicstacks and queues for public
stacks and queues for public
iqbalphy1
 
Standard template library
Standard template libraryStandard template library
Standard template library
ThamizhselviKrishnam
 
Queue
QueueQueue
CMSC 202 - Lec20 - Containers and Iterators(2).pptx
CMSC 202 - Lec20 - Containers and Iterators(2).pptxCMSC 202 - Lec20 - Containers and Iterators(2).pptx
CMSC 202 - Lec20 - Containers and Iterators(2).pptx
deathlyfire321
 
Acm aleppo cpc training seventh session
Acm aleppo cpc training seventh sessionAcm aleppo cpc training seventh session
Acm aleppo cpc training seventh session
Ahmad Bashar Eter
 
Stl Containers
Stl ContainersStl Containers
Stl Containers
ppd1961
 
The Standard Template Library
The Standard Template LibraryThe Standard Template Library
The Standard Template Library
Munazza-Mah-Jabeen
 

Similar to Standard template library (20)

How to choose best containers in STL (C++)
How to choose best containers in STL (C++)How to choose best containers in STL (C++)
How to choose best containers in STL (C++)
 
oops_final_ppt[1].pptx
oops_final_ppt[1].pptxoops_final_ppt[1].pptx
oops_final_ppt[1].pptx
 
MODULE-2.pptx
MODULE-2.pptxMODULE-2.pptx
MODULE-2.pptx
 
Queues
Queues Queues
Queues
 
Collections Training
Collections TrainingCollections Training
Collections Training
 
02._Object-Oriented_Programming_Concepts.ppt
02._Object-Oriented_Programming_Concepts.ppt02._Object-Oriented_Programming_Concepts.ppt
02._Object-Oriented_Programming_Concepts.ppt
 
Python programming
Python programmingPython programming
Python programming
 
STRINGS IN JAVA
STRINGS IN JAVASTRINGS IN JAVA
STRINGS IN JAVA
 
Data structures and Algorithm analysis_Lecture 2.pptx
Data structures and Algorithm analysis_Lecture 2.pptxData structures and Algorithm analysis_Lecture 2.pptx
Data structures and Algorithm analysis_Lecture 2.pptx
 
C# Non generics collection
C# Non generics collectionC# Non generics collection
C# Non generics collection
 
Object Oriented Design and Programming Unit-05
Object Oriented Design and Programming Unit-05Object Oriented Design and Programming Unit-05
Object Oriented Design and Programming Unit-05
 
Stack in Sata Structure
Stack in Sata StructureStack in Sata Structure
Stack in Sata Structure
 
stacks and queues for public
stacks and queues for publicstacks and queues for public
stacks and queues for public
 
Standard template library
Standard template libraryStandard template library
Standard template library
 
Queue
QueueQueue
Queue
 
CMSC 202 - Lec20 - Containers and Iterators(2).pptx
CMSC 202 - Lec20 - Containers and Iterators(2).pptxCMSC 202 - Lec20 - Containers and Iterators(2).pptx
CMSC 202 - Lec20 - Containers and Iterators(2).pptx
 
Acm aleppo cpc training seventh session
Acm aleppo cpc training seventh sessionAcm aleppo cpc training seventh session
Acm aleppo cpc training seventh session
 
Javasession7
Javasession7Javasession7
Javasession7
 
Stl Containers
Stl ContainersStl Containers
Stl Containers
 
The Standard Template Library
The Standard Template LibraryThe Standard Template Library
The Standard Template Library
 

More from Jancypriya M

Introduction to computer
Introduction to computerIntroduction to computer
Introduction to computer
Jancypriya M
 
Library automation software
Library automation softwareLibrary automation software
Library automation software
Jancypriya M
 
Packages in java
Packages in javaPackages in java
Packages in java
Jancypriya M
 
Flip Flop and Its Types
Flip Flop and Its TypesFlip Flop and Its Types
Flip Flop and Its Types
Jancypriya M
 
Corel draw tools
Corel draw toolsCorel draw tools
Corel draw tools
Jancypriya M
 
Applet in java
Applet in javaApplet in java
Applet in java
Jancypriya M
 
Introduction to pagemaker
Introduction to pagemakerIntroduction to pagemaker
Introduction to pagemaker
Jancypriya M
 
Manipulating strings
Manipulating stringsManipulating strings
Manipulating strings
Jancypriya M
 
Strings
StringsStrings
Strings
Jancypriya M
 
Manipulation of Strings
Manipulation of StringsManipulation of Strings
Manipulation of Strings
Jancypriya M
 

More from Jancypriya M (10)

Introduction to computer
Introduction to computerIntroduction to computer
Introduction to computer
 
Library automation software
Library automation softwareLibrary automation software
Library automation software
 
Packages in java
Packages in javaPackages in java
Packages in java
 
Flip Flop and Its Types
Flip Flop and Its TypesFlip Flop and Its Types
Flip Flop and Its Types
 
Corel draw tools
Corel draw toolsCorel draw tools
Corel draw tools
 
Applet in java
Applet in javaApplet in java
Applet in java
 
Introduction to pagemaker
Introduction to pagemakerIntroduction to pagemaker
Introduction to pagemaker
 
Manipulating strings
Manipulating stringsManipulating strings
Manipulating strings
 
Strings
StringsStrings
Strings
 
Manipulation of Strings
Manipulation of StringsManipulation of Strings
Manipulation of Strings
 

Recently uploaded

FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 

Recently uploaded (20)

FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 

Standard template library

  • 1. C++ STL Ms.M.Jancypriya, Asst. Prof., Dept. of CA, Bon Secours College for Women, Thanjavur.
  • 2. STL – Standard Template Library • Collections of useful classes for common data structures • Ability to store objects of any type (template) • Study of containers • Containers form the basis for treatment of data structures • Container – class that stores a collection of data • STL consists of 10 container classes: • Sequence containers • Adapter containers • Associative containers
  • 3. What is the STL? • Standard Template Library • A collection of classes to make C++ programming more efficient • Algorithms, Containers, and Iterators • Function objects,Allocators, and Adapters Containers Containers Function Objects Iterators
  • 4. STLAlgorithms • Accept STL Iterators as arguments • Sort(begin, end); • 4 categories • Non-modifying For each, Find, Count, Equal, Search, etc. • Mutating Copy, Generate, Reverse, Remove, Swap, etc. • Sorting Related Sort, Stable sort, Binary search, Merge, etc. • Numeric Accumulate, Inner product, Partial sum, Adjacent difference
  • 5. STL Containers • Sequence Container • Stores data by position in linear order: • First element, second element , etc: • Associate Container • Stores elements by key, such as name, social security number or part number • Access an element by its key which may bear no relationship to the location of the element in the container • Adapter Container • Contains another container as its underlying storage structure
  • 6. STL Containers  Sequence Container  Vector  Deque  List  Adapter Containers  Stack  Queue  Priority queue  Associative Container  Set, multiset  Map, multimap
  • 7. Vector Container • Generalized array that stores a collection of elements of the same data type • Vector – similar to an array • Vectors allow access to its elements by using an index in the range from 0 to n-1 where n is the size of the vector • Vector vs array • Vector has operations that allow the collection to grow and contract dynamically at the rear of the sequence``
  • 8. Vector Container Example: #include <vector> . . . vector<int> scores (100); //100 integer scores vector<Passenger>passengerList(20); //list of 20 passengers
  • 9. Vector Container • Allows direct access to the elements via an index operator • Indices for the vector elements are in the range from 0 to size() -1 • Example: #include <vector> vector <int> v(20); v[5]=15;
  • 10. List Container • Stores elements by position • Each item in the list has both a value and a memory address (pointer) that identifies the next item in the sequence • To access a specific data value in the list, one must start at the first position (front) and follow the pointers from element to element until data item is located. • List is not a direct access structure • Advantage: ability to add and remove items efficiently at any position in the sequence
  • 11. Stack Container • Adapter Container • These containers restrict how elements enter and leave a sequence • Stack • allows access at only one end of the sequence (top) • Adds objects to container by pushing the object onto the stack • Removes objects from container by popping the stack • LIFO ordering (last end, first out)
  • 12. Queue Container • Queue • Allows access only at the front and rear of the sequence • Items enter at the rear and exit from the front • Example: waiting line at a grocery store • FIFO ordering (first-in first-out ) • push(add object to a queue) • pop (remove object from queue)
  • 13. Priority Queue Container • Priority queue • Operations are similar to those of a stack or queue • Elements can enter the priority queue in any order • Once in the container, a delete operation removes the largest (or smallest) value • Example: a filtering system that takes in elements and then releases them in priority order 8 18 13 3 15 27
  • 14. Set Container • Set • Collection of unique values, called keys or set members • Contains operations that allow a programmer to: • determine whether an item is a member of the set • insert and delete items very efficiently 5 1 3 6 27 15 Buick Ford Jeep BMW Set A Set B
  • 15. Multi-Set Container • A multi-set is similar to a set, but the same value can be in the set more than once • Multi-set container allows duplicates
  • 16. Map Container • Implements a key-value relationship • Programmer can use a key to access corresponding values • Example: key could be a part number such as A24-57 that corresponds to a part: 8.75 price and Martin manufacturer A22-56 A23-57 A24-57 A24-57 8.75 Martin A22-56 12.50 Callowa y A23-57 4.95 Mirage
  • 17. Multi-map Container • Similar to a map container • Multi-map container allows duplicates
  • 18. How to access Components - Iterator • Iterator is an object that can access a collection of like objects one object at a time. • An iterator can traverse the collection of objects. • Each container class in STL has a corresponding iterator that functions appropriately for the container • For example: an iterator in a vector class allows random access • An iterator in a list class would not allow random access (list requires sequential access)
  • 19. Common Iterator Operations * Return the item that the iterator currently references ++ Move the iterator to the next item in the list -- Move the iterator to the previous item in the list == Compare two iterators for equality != Compare two iterators for inequality
  • 20. STL List Class Constructors and assignment • list <T> v; • list<T> v(aList); • l=aList; Access • l.front() ----returns 1st element in the list • l.back()----returns the last element in the list
  • 21. STL List Insert and Remove • l.push_front(value) • l.push_back(value) Iterator Delaration • list<T>::iteratoritr; Iterator Options • itr = l.begin() set iterator to beginning of the list • Itr = l.end() set iterator to after the end of the list
  • 22. Writing classes that work with the STL  Classes that will be stored in STL containers should explicitly define the following: ◦ Default constructor ◦ Copy constructor ◦ Destructor ◦ operator = ◦ operator== ◦ operator<  Not all of these are always necessary, but it might be easier to define them than to figure out which ones you actually need  Many STL programming errors can be traced to omitting or improperly defining these methods