SlideShare a Scribd company logo
1 of 10
Standard Template Library
Object Oriented Programming Copyright © 2012 IM
Group. All rights
reserved
Iterators
• STL has containers, algorithms and
Iterators
▫ Containers hold objects, all of a specified type
▫ Generic algorithms act on objects in containers
▫ Iterators provide access to objects in the
containers yet hide the internal structure of the
container
Copyright © 2012 IM
Group. All rights
reserved
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 replicate structures very commonly used in programming:
▫ Dynamic Arrays (vector)
▫ Queues (queue)
▫ Stacks (stack)
▫ Heaps (priority_queue)
▫ Linked lists (list)
▫ Trees (set)
▫ Associative Arrays (map)
Copyright © 2012 IM
Group. All rights
reserved
Common Container Members
• The STL sequential containers each have different
characteristics, but they all support these members:
▫ container( ); // creates empty container
▫ ~container( ); // destroys container, erases all
members
▫ c.empty( ) // true if there are no entries in c
▫ c.size( ) const; // number of entries in container c
▫ c = v; //replace contents of c with contents of v
Copyright © 2012 IM
Group. All rights
reserved
More Common Container Members
• c.swap(other_container); // swaps contents of
// c and other_container.
• c.push_back(item); // appends item to container c
• c.begin( ); // returns an iterator to the first
// element in container c
• c.end( ); // returns an iterator to a position
// beyond the end of the container c.
• c.rbegin( ); // returns an iterator to the last element
// in the container. Serves to as start of
// reverse traversal.
Copyright © 2012 IM
Group. All rights
reserved
More Common Container Members
• c.rend( ); // returns an iterator to a position
// beyond the of the container.
• c.front( ); // returns the first element in the
// container (same as *c.begin( );)
• c.back( ); //returns the last element in the container
// same as *(--c.end( ));
• c.insert(iter, elem); //insert copy of element elem
//before iteIr
• c.erase(iter); //removes element iter points to,
// returns an iterator to element
// following erasure. returns c.end( ) if
// last element is removed.
Copyright © 2012 IM
Group. All rights
reserved
More Common Container Members
• c.clear( ); // makes container c empty
• c1 == c2 // returns true if the sizes equal and
// corresponding elements in c1 and c2
// are equal
• c1 != c2 // returns !(c1==c2)
• c.push_front(elem) // insert element elem at the
// front of container c.
// NOT implemented for vector due to
large
// run-time that results
Copyright © 2012 IM
Group. All rights
reserved
Slide 18-
8
Generic Algorithms
• “Generic Algorithm” are a template functions
that use iterators as template parameters.
• This chapter will use Generic Algorithm,
Generic function, and STL function template to
mean the same thing.
• Function interface specifies task, minimum
strength of iterator arguments, and provides
run-time specification.
Training
• Let’s make the Vector class.
Copyright © 2012 IM
Group. All rights
reserved
Any Questions
Session 7 Copyright © 2012 IM
Group. All rights
reserved

More Related Content

Similar to OOP - STL

standard template library(STL) in C++
standard template library(STL) in C++standard template library(STL) in C++
standard template library(STL) in C++•sreejith •sree
 
Generic Programming & Collection
Generic Programming & CollectionGeneric Programming & Collection
Generic Programming & CollectionArya
 
Generic Programming & Collection
Generic Programming & CollectionGeneric Programming & Collection
Generic Programming & CollectionArya
 
Constructor and Destructor
Constructor and DestructorConstructor and Destructor
Constructor and DestructorSunipa Bera
 
More topics on Java
More topics on JavaMore topics on Java
More topics on JavaAhmed Misbah
 
Data abstraction and object orientation
Data abstraction and object orientationData abstraction and object orientation
Data abstraction and object orientationHoang Nguyen
 
Java tutorials
Java tutorialsJava tutorials
Java tutorialssaryu2011
 
Stl (standard template library)
Stl (standard template library)Stl (standard template library)
Stl (standard template library)Hemant Jain
 
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
 
Synapseindia reviews.odp.
Synapseindia reviews.odp.Synapseindia reviews.odp.
Synapseindia reviews.odp.Tarunsingh198
 
Objective-C Is Not Java
Objective-C Is Not JavaObjective-C Is Not Java
Objective-C Is Not JavaChris Adamson
 
Unit3 part3-packages and interfaces
Unit3 part3-packages and interfacesUnit3 part3-packages and interfaces
Unit3 part3-packages and interfacesDevaKumari Vijay
 

Similar to OOP - STL (20)

standard template library(STL) in C++
standard template library(STL) in C++standard template library(STL) in C++
standard template library(STL) in C++
 
Generic Programming & Collection
Generic Programming & CollectionGeneric Programming & Collection
Generic Programming & Collection
 
Generic Programming & Collection
Generic Programming & CollectionGeneric Programming & Collection
Generic Programming & Collection
 
Constructor and Destructor
Constructor and DestructorConstructor and Destructor
Constructor and Destructor
 
More topics on Java
More topics on JavaMore topics on Java
More topics on Java
 
oop 3.pptx
oop 3.pptxoop 3.pptx
oop 3.pptx
 
Savitch Ch 18
Savitch Ch 18Savitch Ch 18
Savitch Ch 18
 
Data abstraction and object orientation
Data abstraction and object orientationData abstraction and object orientation
Data abstraction and object orientation
 
2CPP16 - STL
2CPP16 - STL2CPP16 - STL
2CPP16 - STL
 
Bjarne essencegn13
Bjarne essencegn13Bjarne essencegn13
Bjarne essencegn13
 
Java tutorials
Java tutorialsJava tutorials
Java tutorials
 
Stl (standard template library)
Stl (standard template library)Stl (standard template library)
Stl (standard template library)
 
java training faridabad
java training faridabadjava training faridabad
java training faridabad
 
Java Tutorials
Java Tutorials Java Tutorials
Java Tutorials
 
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++)
 
C++
C++C++
C++
 
C++
C++C++
C++
 
Synapseindia reviews.odp.
Synapseindia reviews.odp.Synapseindia reviews.odp.
Synapseindia reviews.odp.
 
Objective-C Is Not Java
Objective-C Is Not JavaObjective-C Is Not Java
Objective-C Is Not Java
 
Unit3 part3-packages and interfaces
Unit3 part3-packages and interfacesUnit3 part3-packages and interfaces
Unit3 part3-packages and interfaces
 

More from Mohammad Shaker

Android Development - Session 5
Android Development - Session 5Android Development - Session 5
Android Development - Session 5Mohammad Shaker
 
Android Development - Session 4
Android Development - Session 4Android Development - Session 4
Android Development - Session 4Mohammad Shaker
 
Android Development - Session 2
Android Development - Session 2Android Development - Session 2
Android Development - Session 2Mohammad Shaker
 
Android Development - Session 1
Android Development - Session 1Android Development - Session 1
Android Development - Session 1Mohammad Shaker
 
OOP - Introduction to Inheritance
OOP - Introduction to InheritanceOOP - Introduction to Inheritance
OOP - Introduction to InheritanceMohammad Shaker
 
NoSQL - A Closer Look to Couchbase
NoSQL - A Closer Look to CouchbaseNoSQL - A Closer Look to Couchbase
NoSQL - A Closer Look to CouchbaseMohammad Shaker
 
Introduction to Couchbase
Introduction to CouchbaseIntroduction to Couchbase
Introduction to CouchbaseMohammad Shaker
 

More from Mohammad Shaker (11)

Android Development - Session 5
Android Development - Session 5Android Development - Session 5
Android Development - Session 5
 
Android Development - Session 4
Android Development - Session 4Android Development - Session 4
Android Development - Session 4
 
Android Development - Session 2
Android Development - Session 2Android Development - Session 2
Android Development - Session 2
 
Android Development - Session 1
Android Development - Session 1Android Development - Session 1
Android Development - Session 1
 
Introduction to Qt
Introduction to QtIntroduction to Qt
Introduction to Qt
 
OOP - Templates
OOP - TemplatesOOP - Templates
OOP - Templates
 
OOP - Introduction to Inheritance
OOP - Introduction to InheritanceOOP - Introduction to Inheritance
OOP - Introduction to Inheritance
 
OOP - Friend Functions
OOP - Friend FunctionsOOP - Friend Functions
OOP - Friend Functions
 
OOP - Introduction
OOP - IntroductionOOP - Introduction
OOP - Introduction
 
NoSQL - A Closer Look to Couchbase
NoSQL - A Closer Look to CouchbaseNoSQL - A Closer Look to Couchbase
NoSQL - A Closer Look to Couchbase
 
Introduction to Couchbase
Introduction to CouchbaseIntroduction to Couchbase
Introduction to Couchbase
 

Recently uploaded

DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfCionsystems
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 

Recently uploaded (20)

DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdf
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 

OOP - STL

  • 1. Standard Template Library Object Oriented Programming Copyright © 2012 IM Group. All rights reserved
  • 2. Iterators • STL has containers, algorithms and Iterators ▫ Containers hold objects, all of a specified type ▫ Generic algorithms act on objects in containers ▫ Iterators provide access to objects in the containers yet hide the internal structure of the container Copyright © 2012 IM Group. All rights reserved
  • 3. 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 replicate structures very commonly used in programming: ▫ Dynamic Arrays (vector) ▫ Queues (queue) ▫ Stacks (stack) ▫ Heaps (priority_queue) ▫ Linked lists (list) ▫ Trees (set) ▫ Associative Arrays (map) Copyright © 2012 IM Group. All rights reserved
  • 4. Common Container Members • The STL sequential containers each have different characteristics, but they all support these members: ▫ container( ); // creates empty container ▫ ~container( ); // destroys container, erases all members ▫ c.empty( ) // true if there are no entries in c ▫ c.size( ) const; // number of entries in container c ▫ c = v; //replace contents of c with contents of v Copyright © 2012 IM Group. All rights reserved
  • 5. More Common Container Members • c.swap(other_container); // swaps contents of // c and other_container. • c.push_back(item); // appends item to container c • c.begin( ); // returns an iterator to the first // element in container c • c.end( ); // returns an iterator to a position // beyond the end of the container c. • c.rbegin( ); // returns an iterator to the last element // in the container. Serves to as start of // reverse traversal. Copyright © 2012 IM Group. All rights reserved
  • 6. More Common Container Members • c.rend( ); // returns an iterator to a position // beyond the of the container. • c.front( ); // returns the first element in the // container (same as *c.begin( );) • c.back( ); //returns the last element in the container // same as *(--c.end( )); • c.insert(iter, elem); //insert copy of element elem //before iteIr • c.erase(iter); //removes element iter points to, // returns an iterator to element // following erasure. returns c.end( ) if // last element is removed. Copyright © 2012 IM Group. All rights reserved
  • 7. More Common Container Members • c.clear( ); // makes container c empty • c1 == c2 // returns true if the sizes equal and // corresponding elements in c1 and c2 // are equal • c1 != c2 // returns !(c1==c2) • c.push_front(elem) // insert element elem at the // front of container c. // NOT implemented for vector due to large // run-time that results Copyright © 2012 IM Group. All rights reserved
  • 8. Slide 18- 8 Generic Algorithms • “Generic Algorithm” are a template functions that use iterators as template parameters. • This chapter will use Generic Algorithm, Generic function, and STL function template to mean the same thing. • Function interface specifies task, minimum strength of iterator arguments, and provides run-time specification.
  • 9. Training • Let’s make the Vector class. Copyright © 2012 IM Group. All rights reserved
  • 10. Any Questions Session 7 Copyright © 2012 IM Group. All rights reserved