SlideShare ist ein Scribd-Unternehmen logo
1 von 29
Standard Template
        Library




G uided By :-           Submitted By:-
Prof. Shweta Jogleker   Kumar Gaurav
                        Roll no :- 26
Introduction

 Standard Template Library (STL) stands for standard template
  library and is basically a library of many useful containers or
  algorithms.

 In layman terms , it basically is a class template with functions
  already created making life easier as they need to be merely
  called to be used. (Our definition)

 The STL achieves its results through the use of templates. This
  approach is very powerful, delivering compile-time
  polymorphism that is often more efficient than traditional run-
  time polymorphism. Modern C++ compilers are tuned to
  minimize any abstraction penalty arising from heavy use of the
  STL.
Introduction
                 The Three Component of STL
Containers
     A container is a holder object that stores a collection other
objects (its elements). They are implemented as class templates,
which allows a great flexibility in the types supported as elements.
> Iterators
    They are a generalization of pointers: they are objects that point
to other objects. As the name suggests, iterators are often used to
iterate over a range of objects: if an iterator points to one element in a
range, then it is possible to increment it so that it points to the next
element.

> Algorithms
    The header <algorithm> defines a collection of functions
especially designed to be used on ranges of elements.
Introduction
Introduction
The Standard Template Library was created as the first library of
generic algorithms and data structures, with four ideas in mind:
generic programming, abstractness without loss of efficiency, the
Von Neumann computation model, and value semantics


                                      Function Objects

                         Iterators
       Algorithm                         Containers
Introduction
             Algorithms use iterators to interact with objects
          Container       stored in containers             Container

                       Iterator
                                  Algorithm

Objects                                         Iterator

                                   Algorithm
                       Iterator
                                                Iterator


                                  Algorithm
Introduction
• Algorithms
                                       • Separation of concerns
       sort, find, search, copy, …
                                        – Algorithms manipulate
                                          data, but don’t know
                                          about containers
                                        – Containers store data, but
                            iterators     don’t know about
                                          algorithms
                                        – Algorithms and
                                          containers interact
                                          through iterators
•   Containers                              • Each container has its
             vector, list, map, hash_map, … own iterator types


                                                                       8
Containers


 Iterators



 Algorithm
Containers

• Sequence Containers
  – Vectors, Linked Lists, and derivatives
• Container Adaptors
  – Queue, Priority Queue, Stack
• Associative Containers
  – Hash, Map, Set
Containers           (hold sequences in difference ways)
• vector
                          0        1        2       3


• list
(doubly linked)           0             1                       2

• set
                                       6
(a kind of tree)

                              2                         7


                      0            1            5


                                            3               4
                                                                    11
Containers
Standard Library      Description
container class



S u ce C n in
 eq en  o ta ers


vector                rap in
                         id sertio s an d
                                    n    d eletio s at b
                                                 n      ack
                      direct access to an elem t
                                         y     en

deque                 rap in
                         id sertio s an d
                                    n    d eletio s at fro t o b
                                                 n        n r ack
                      direct access to an elem t
                                         y     en

list                  d u ly lin ed list, rap in
                       o b      k            id sertio an d
                                                      n d eletio an w ere
                                                                n y h

A cia
 sso tive C n in
           o ta ers

set                   rap lo k p n d p
                         id o u , o u licates allo ed
                                                  w

multiset              rap lo k p d p
                         id o u , u licates allo ed
                                                w

map                   o e-to n m p g n d p
                       n    -o e ap in , o u licates allo ed rap k
                                                         w ,    id ey-based lo k p
                                                                              o u

multimap              o e-to an m p g d p
                       n    -m y ap in , u licates allo ed rap k -b
                                                       w ,    id ey ased lo k p
                                                                           o u

C n in A a ters
 o ta er d p

stack                 last-in-first-o t (L O
                                     u    IF )

queue                 first-in-first-o t (F O
                                      u    IF )

priority_queue        h h
                       ig est p rity elem t is alw s th first elem t o t
                               rio       en       ay   e          en u
Containers


 Iterators



 Algorithm
Iterators
• Iterators are similar to pointers
   – point to first element in a container
   – iterator operators uniform for all containers
       • * dereferences, ++ points to next element
       • begin() returns iterator pointing to first element
       • end() returns iterator pointing to last element
   – use iterators with sequences (ranges)
       • containers
       • input sequences - istream_iterator
       • output sequences - ostream_iterator
Iterators
•   Iterators are pointer-like entities that are used to access individual
    elements in a container.
•   Often they are used to move sequentially from element to element, a
    process called iterating through a container.


               vector<int>
                         17
          array_                              vector<int>::iterator
                         4

                        23                    The iterator corresponding to
                                              the class vector<int> is of
                        12                    the type vector<int>::iterator

          size_          4
Iterators
• The member functions begin() and end() return an
  iterator to the first and past the last element of a
  container


                                 v.begin()
            vector<int>
                      17
       array_
                      4

                     23
                                  v.end()
                     12


       size_          4
Iterators
•   One can have multiple iterators pointing to different or identical
    elements in the container




                vector<int>                             i1
                          17
           array_
                          4
                                                        i2
                         23

                         12

                                                        i3
           size_          4
Iterators
 Types of Iterators
 Containers provide several iterators
      Begin, End, Reverse Begin, Reverse End
  5 categories – each has specific operations
      Input, Output, Forward, Bidirectional, Random



Input Operations: =, ==, !=, *, ->, ++         , No assignment of *i
Output Operations: =, *, ++
Forward Operations: =, ==, !=, *, ->, ++
Bidirectional Operations: =, ==, !=, *, ->, ++, --
Random Operations: =, ==, !=, +=, -=, *, ->, +, ++, -, --, [n], <, <=, >, >=
Iterators
Category        Description

input           Used to read an element from a container. An input iterator
                can move only in the forward direction (i.e., from the
                beginning of the container to the end of the container) one
                element at a time. Input iterators support only one-pass
                algorithms—the same input iterator cannot be used to pass
                through a sequence twice.
output          Used to write an element to a container. An output iterator can
                move only in the forward direction one element at a time.
                Output iterators support only one-pass algorithms—the same
                output iterator cannot be used to pass through a sequence
                twice.
forward         Combines the capabilities of input and output iterators and
                retains their position in the container (as state information).
bidirectional   Combines the capabilities of a forward iterator with the ability
                to move in the backward direction (i.e., from the end of the
                container toward the beginning of the container). Forward
                iterators support multi-pass algorithms.
random access   Combines the capabilities of a bidirectional iterator with the
                ability to directly access any element of the container, i.e., to
                jump forward or backward by an arbitrary number of
                elements.
Iterators
Container                Type of iterator supported

Sequence containers
    vector               random access
    deque                random access
    list                 bidirectional
Associative containers
    set                  bidirectional
    multiset             bidirectional
    map                  bidirectional
    multimap             bidirectional
Container adapters
    stack                no iterators supported
    queue                no iterators supported
                         no iterators supported
priority_queue
Containers


 Iterators



 Algorithm
Algorithm
STL algorithms are not member functions or friends of containers. They are
standalone template functions. To have access to the STL algorithms, we
must include <algorithm> in our program.
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
Algorithm
1. Retrieve or Non-Mutating algorithms:
   Algorithms don’t modify the contents of containers they work on.
   Ex: searching a container for a particular element and returning its position.
   Functions:
   count : The count() function returns the number of elements between start and
   end that match val.
   equal: The equal () function returns true if the elements in two ranges are the
   same. The first range of elements is those between start1 and end1. The second
   range of elements has the same size as the first range but starts at start2.
   find: The find() algorithm looks for an element matching val between start and end.
    If an element matching val is found, the return value Is an iterator that points to
    that element. Otherwise, the return value is an iterator that points to end.
Algorithm
2.   Mutating algorithms
     Allows modifying the contents of the containers they work on.
     Ex: Reversing the contents of containers.
     copy: The copy() function copies the elements between start and end to dest. In
     other words, after copy() has run,

     copy_backward: copy_backward() is similar to (C++ Strings) copy(), in that
     both functions copy elements from start to end to dest. The copy_backward()
     function , however, starts depositing elements at dest and then works
     backwards, such that:

     fill : The function fill() assigns val to all of the elements between start and end.

     generate: The generate() function runs the Generator function object g a
     number of times, saving the result of each execution in the range [start,end).
     Replaces all elements with the result of an operations
Algorithm
Sorting algorithms
Include general sorting, merges, dictionary comparisons, and binary search
Operations.Requires random access iterators.
  Functions
binary_search : The binary_search() function searches from start to end for val.
The elements between start and end that are searched should be in ascending order
as defined by the < operator. Note that a binary search will not work unless the
elements being searched are in order.
If val is found, binary_search() returns true, otherwise false. If the function f is
specified, then it is used to compare elements.

 merge : The merge() function combines two sorted ranges [start1,end1) and
 [start2,end2) into a single sorted range, stored starting at result. The return value of
 this function is an iterator to the end of the merged range.
 If the strict weak ordering function object cmp is given, then it is used in place of
 the < operator to perform comparisons between elements.
Algorithm
Numeric Algorithms:
accumulate : The accummulate() function computes the sum of val and all of the
elements in the range [start,end).
adjacent_difference: The adjacent_difference() function calculates the differences
between adjacent elements in the range [start,end) and stores the result starting at
result.
partial_sum: The partial_sum() function calculates the partial sum of a range
defined by [start,end), storing the output at result.
Summary
 The standard template library (STL) is the C++ library that
  provides generic programming for many standard data
  structures and algorithms.


 Containers come in two major families: sequence (are ordered)
  and associative (have keys for looking up elements).


 Iterators can be thought of as an enhanced pointer type.


 The algorithms use iterators to access containers.




                                                                  27
Success Story

• Millions of copies out
• Everybody (Microsoft, IBM, Sun …) ships it
• A dozen books

• Very few extensions
• No language progress
• No effect on software engineering

                                               28
Standard Template Library

Weitere ähnliche Inhalte

Was ist angesagt?

Inheritance in JAVA PPT
Inheritance  in JAVA PPTInheritance  in JAVA PPT
Inheritance in JAVA PPTPooja Jaiswal
 
Static Data Members and Member Functions
Static Data Members and Member FunctionsStatic Data Members and Member Functions
Static Data Members and Member FunctionsMOHIT AGARWAL
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handlingkamal kotecha
 
Passing an Array to a Function (ICT Programming)
Passing an Array to a Function (ICT Programming)Passing an Array to a Function (ICT Programming)
Passing an Array to a Function (ICT Programming)Fatima Kate Tanay
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator OverloadingNilesh Dalvi
 
Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVAAbhilash Nair
 
Datatype in c++ unit 3 -topic 2
Datatype in c++ unit 3 -topic 2Datatype in c++ unit 3 -topic 2
Datatype in c++ unit 3 -topic 2MOHIT TOMAR
 
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
 
Polymorphism presentation in java
Polymorphism presentation in javaPolymorphism presentation in java
Polymorphism presentation in javaAhsan Raja
 
[OOP - Lec 19] Static Member Functions
[OOP - Lec 19] Static Member Functions[OOP - Lec 19] Static Member Functions
[OOP - Lec 19] Static Member FunctionsMuhammad Hammad Waseem
 
Introduction to class in java
Introduction to class in javaIntroduction to class in java
Introduction to class in javakamal kotecha
 
Operators and Expressions in Java
Operators and Expressions in JavaOperators and Expressions in Java
Operators and Expressions in JavaAbhilash Nair
 

Was ist angesagt? (20)

Inheritance in JAVA PPT
Inheritance  in JAVA PPTInheritance  in JAVA PPT
Inheritance in JAVA PPT
 
Static Data Members and Member Functions
Static Data Members and Member FunctionsStatic Data Members and Member Functions
Static Data Members and Member Functions
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
 
Passing an Array to a Function (ICT Programming)
Passing an Array to a Function (ICT Programming)Passing an Array to a Function (ICT Programming)
Passing an Array to a Function (ICT Programming)
 
Packages in java
Packages in javaPackages in java
Packages in java
 
[OOP - Lec 07] Access Specifiers
[OOP - Lec 07] Access Specifiers[OOP - Lec 07] Access Specifiers
[OOP - Lec 07] Access Specifiers
 
Abstract class in java
Abstract class in javaAbstract class in java
Abstract class in java
 
OOP java
OOP javaOOP java
OOP java
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator Overloading
 
Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVA
 
Datatype in c++ unit 3 -topic 2
Datatype in c++ unit 3 -topic 2Datatype in c++ unit 3 -topic 2
Datatype in c++ unit 3 -topic 2
 
standard template library(STL) in C++
standard template library(STL) in C++standard template library(STL) in C++
standard template library(STL) in C++
 
Polymorphism presentation in java
Polymorphism presentation in javaPolymorphism presentation in java
Polymorphism presentation in java
 
[OOP - Lec 19] Static Member Functions
[OOP - Lec 19] Static Member Functions[OOP - Lec 19] Static Member Functions
[OOP - Lec 19] Static Member Functions
 
Shift reduce parser
Shift reduce parserShift reduce parser
Shift reduce parser
 
Chapter 07 inheritance
Chapter 07 inheritanceChapter 07 inheritance
Chapter 07 inheritance
 
Final keyword in java
Final keyword in javaFinal keyword in java
Final keyword in java
 
Introduction to class in java
Introduction to class in javaIntroduction to class in java
Introduction to class in java
 
Operators and Expressions in Java
Operators and Expressions in JavaOperators and Expressions in Java
Operators and Expressions in Java
 
This pointer
This pointerThis pointer
This pointer
 

Andere mochten auch

C++ Standard Template Library
C++ Standard Template LibraryC++ Standard Template Library
C++ Standard Template LibraryIlio Catallo
 
Stl (standard template library)
Stl (standard template library)Stl (standard template library)
Stl (standard template library)Hemant Jain
 
Standard template library
Standard template libraryStandard template library
Standard template librarySukriti Singh
 
Programming in c++
Programming in c++Programming in c++
Programming in c++Baljit Saini
 
Managing console input and output
Managing console input and outputManaging console input and output
Managing console input and outputgourav kottawar
 
An Introduction to Part of C++ STL
An Introduction to Part of C++ STLAn Introduction to Part of C++ STL
An Introduction to Part of C++ STL乐群 陈
 
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
 
Templates exception handling
Templates exception handlingTemplates exception handling
Templates exception handlingsanya6900
 
New Ways of Working Fleur Bothwick, OBE, EMEIA Director of Diversity and Incl...
New Ways of Working Fleur Bothwick, OBE, EMEIA Director of Diversity and Incl...New Ways of Working Fleur Bothwick, OBE, EMEIA Director of Diversity and Incl...
New Ways of Working Fleur Bothwick, OBE, EMEIA Director of Diversity and Incl...TALiNT Partners
 
Templates presentation
Templates presentationTemplates presentation
Templates presentationmalaybpramanik
 
Lecture11 standard template-library
Lecture11 standard template-libraryLecture11 standard template-library
Lecture11 standard template-libraryHariz Mustafa
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT03062679929
 
Stl Containers
Stl ContainersStl Containers
Stl Containersppd1961
 
Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...
Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...
Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...cprogrammings
 
file handling c++
file handling c++file handling c++
file handling c++Guddu Spy
 
Inheritance in C++
Inheritance in C++Inheritance in C++
Inheritance in C++Laxman Puri
 

Andere mochten auch (20)

STL in C++
STL in C++STL in C++
STL in C++
 
C++ Standard Template Library
C++ Standard Template LibraryC++ Standard Template Library
C++ Standard Template Library
 
Stl (standard template library)
Stl (standard template library)Stl (standard template library)
Stl (standard template library)
 
Standard template library
Standard template libraryStandard template library
Standard template library
 
C++ STL 概觀
C++ STL 概觀C++ STL 概觀
C++ STL 概觀
 
Programming in c++
Programming in c++Programming in c++
Programming in c++
 
Managing console input and output
Managing console input and outputManaging console input and output
Managing console input and output
 
An Introduction to Part of C++ STL
An Introduction to Part of C++ STLAn Introduction to Part of C++ STL
An Introduction to Part of C++ STL
 
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++)
 
Templates exception handling
Templates exception handlingTemplates exception handling
Templates exception handling
 
New Ways of Working Fleur Bothwick, OBE, EMEIA Director of Diversity and Incl...
New Ways of Working Fleur Bothwick, OBE, EMEIA Director of Diversity and Incl...New Ways of Working Fleur Bothwick, OBE, EMEIA Director of Diversity and Incl...
New Ways of Working Fleur Bothwick, OBE, EMEIA Director of Diversity and Incl...
 
Templates presentation
Templates presentationTemplates presentation
Templates presentation
 
Lecture11 standard template-library
Lecture11 standard template-libraryLecture11 standard template-library
Lecture11 standard template-library
 
inheritance c++
inheritance c++inheritance c++
inheritance c++
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
Stl Containers
Stl ContainersStl Containers
Stl Containers
 
Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...
Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...
Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...
 
file handling c++
file handling c++file handling c++
file handling c++
 
Inheritance in C++
Inheritance in C++Inheritance in C++
Inheritance in C++
 

Ähnlich wie Standard Template Library

Lecture20 vector
Lecture20 vectorLecture20 vector
Lecture20 vectornurkhaledah
 
L9 wrapper classes
L9 wrapper classesL9 wrapper classes
L9 wrapper classesteach4uin
 
Spl to the Rescue - Zendcon 09
Spl to the Rescue - Zendcon 09Spl to the Rescue - Zendcon 09
Spl to the Rescue - Zendcon 09Elizabeth Smith
 
SPL to the Rescue - Tek 09
SPL to the Rescue - Tek 09SPL to the Rescue - Tek 09
SPL to the Rescue - Tek 09Elizabeth Smith
 
Python Programming | JNTUK | UNIT 1 | Lecture 4
Python Programming | JNTUK | UNIT 1 | Lecture 4Python Programming | JNTUK | UNIT 1 | Lecture 4
Python Programming | JNTUK | UNIT 1 | Lecture 4FabMinds
 
03 expressions.ppt
03 expressions.ppt03 expressions.ppt
03 expressions.pptBusiness man
 
Learning core java
Learning core javaLearning core java
Learning core javaAbhay Bharti
 
Hive Object Model
Hive Object ModelHive Object Model
Hive Object ModelZheng Shao
 
Processing data with Python, using standard library modules you (probably) ne...
Processing data with Python, using standard library modules you (probably) ne...Processing data with Python, using standard library modules you (probably) ne...
Processing data with Python, using standard library modules you (probably) ne...gjcross
 
Java 103 intro to java data structures
Java 103   intro to java data structuresJava 103   intro to java data structures
Java 103 intro to java data structuresagorolabs
 
Demystifying NLP Transformers: Understanding the Power and Architecture behin...
Demystifying NLP Transformers: Understanding the Power and Architecture behin...Demystifying NLP Transformers: Understanding the Power and Architecture behin...
Demystifying NLP Transformers: Understanding the Power and Architecture behin...NILESH VERMA
 
Fundamental classes in java
Fundamental classes in javaFundamental classes in java
Fundamental classes in javaGaruda Trainings
 
Iterator - a powerful but underappreciated design pattern
Iterator - a powerful but underappreciated design patternIterator - a powerful but underappreciated design pattern
Iterator - a powerful but underappreciated design patternNitin Bhide
 

Ähnlich wie Standard Template Library (20)

Lecture20 vector
Lecture20 vectorLecture20 vector
Lecture20 vector
 
L9 wrapper classes
L9 wrapper classesL9 wrapper classes
L9 wrapper classes
 
chapter 5.ppt
chapter 5.pptchapter 5.ppt
chapter 5.ppt
 
Spl to the Rescue - Zendcon 09
Spl to the Rescue - Zendcon 09Spl to the Rescue - Zendcon 09
Spl to the Rescue - Zendcon 09
 
Java Unit 2(Part 1)
Java Unit 2(Part 1)Java Unit 2(Part 1)
Java Unit 2(Part 1)
 
SPL to the Rescue - Tek 09
SPL to the Rescue - Tek 09SPL to the Rescue - Tek 09
SPL to the Rescue - Tek 09
 
Lesson 19
Lesson 19Lesson 19
Lesson 19
 
AI Lesson 19
AI Lesson 19AI Lesson 19
AI Lesson 19
 
Java tutorial part 3
Java tutorial part 3Java tutorial part 3
Java tutorial part 3
 
Python Programming | JNTUK | UNIT 1 | Lecture 4
Python Programming | JNTUK | UNIT 1 | Lecture 4Python Programming | JNTUK | UNIT 1 | Lecture 4
Python Programming | JNTUK | UNIT 1 | Lecture 4
 
03 expressions.ppt
03 expressions.ppt03 expressions.ppt
03 expressions.ppt
 
Learning core java
Learning core javaLearning core java
Learning core java
 
Java
JavaJava
Java
 
Hive Object Model
Hive Object ModelHive Object Model
Hive Object Model
 
About Python
About PythonAbout Python
About Python
 
Processing data with Python, using standard library modules you (probably) ne...
Processing data with Python, using standard library modules you (probably) ne...Processing data with Python, using standard library modules you (probably) ne...
Processing data with Python, using standard library modules you (probably) ne...
 
Java 103 intro to java data structures
Java 103   intro to java data structuresJava 103   intro to java data structures
Java 103 intro to java data structures
 
Demystifying NLP Transformers: Understanding the Power and Architecture behin...
Demystifying NLP Transformers: Understanding the Power and Architecture behin...Demystifying NLP Transformers: Understanding the Power and Architecture behin...
Demystifying NLP Transformers: Understanding the Power and Architecture behin...
 
Fundamental classes in java
Fundamental classes in javaFundamental classes in java
Fundamental classes in java
 
Iterator - a powerful but underappreciated design pattern
Iterator - a powerful but underappreciated design patternIterator - a powerful but underappreciated design pattern
Iterator - a powerful but underappreciated design pattern
 

Mehr von Kumar Gaurav

Mehr von Kumar Gaurav (6)

Numerical method
Numerical methodNumerical method
Numerical method
 
Cellular network History
Cellular network HistoryCellular network History
Cellular network History
 
Cellular networks
Cellular networksCellular networks
Cellular networks
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
J2ME
J2MEJ2ME
J2ME
 
Python
PythonPython
Python
 

Kürzlich hochgeladen

DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 

Kürzlich hochgeladen (20)

DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 

Standard Template Library

  • 1.
  • 2. Standard Template Library G uided By :- Submitted By:- Prof. Shweta Jogleker Kumar Gaurav Roll no :- 26
  • 3. Introduction  Standard Template Library (STL) stands for standard template library and is basically a library of many useful containers or algorithms.  In layman terms , it basically is a class template with functions already created making life easier as they need to be merely called to be used. (Our definition)  The STL achieves its results through the use of templates. This approach is very powerful, delivering compile-time polymorphism that is often more efficient than traditional run- time polymorphism. Modern C++ compilers are tuned to minimize any abstraction penalty arising from heavy use of the STL.
  • 4. Introduction The Three Component of STL Containers A container is a holder object that stores a collection other objects (its elements). They are implemented as class templates, which allows a great flexibility in the types supported as elements. > Iterators They are a generalization of pointers: they are objects that point to other objects. As the name suggests, iterators are often used to iterate over a range of objects: if an iterator points to one element in a range, then it is possible to increment it so that it points to the next element. > Algorithms The header <algorithm> defines a collection of functions especially designed to be used on ranges of elements.
  • 6. Introduction The Standard Template Library was created as the first library of generic algorithms and data structures, with four ideas in mind: generic programming, abstractness without loss of efficiency, the Von Neumann computation model, and value semantics Function Objects Iterators Algorithm Containers
  • 7. Introduction Algorithms use iterators to interact with objects Container stored in containers Container Iterator Algorithm Objects Iterator Algorithm Iterator Iterator Algorithm
  • 8. Introduction • Algorithms • Separation of concerns sort, find, search, copy, … – Algorithms manipulate data, but don’t know about containers – Containers store data, but iterators don’t know about algorithms – Algorithms and containers interact through iterators • Containers • Each container has its vector, list, map, hash_map, … own iterator types 8
  • 10. Containers • Sequence Containers – Vectors, Linked Lists, and derivatives • Container Adaptors – Queue, Priority Queue, Stack • Associative Containers – Hash, Map, Set
  • 11. Containers (hold sequences in difference ways) • vector 0 1 2 3 • list (doubly linked) 0 1 2 • set 6 (a kind of tree) 2 7 0 1 5 3 4 11
  • 12. Containers Standard Library Description container class S u ce C n in eq en o ta ers vector rap in id sertio s an d n d eletio s at b n ack direct access to an elem t y en deque rap in id sertio s an d n d eletio s at fro t o b n n r ack direct access to an elem t y en list d u ly lin ed list, rap in o b k id sertio an d n d eletio an w ere n y h A cia sso tive C n in o ta ers set rap lo k p n d p id o u , o u licates allo ed w multiset rap lo k p d p id o u , u licates allo ed w map o e-to n m p g n d p n -o e ap in , o u licates allo ed rap k w , id ey-based lo k p o u multimap o e-to an m p g d p n -m y ap in , u licates allo ed rap k -b w , id ey ased lo k p o u C n in A a ters o ta er d p stack last-in-first-o t (L O u IF ) queue first-in-first-o t (F O u IF ) priority_queue h h ig est p rity elem t is alw s th first elem t o t rio en ay e en u
  • 14. Iterators • Iterators are similar to pointers – point to first element in a container – iterator operators uniform for all containers • * dereferences, ++ points to next element • begin() returns iterator pointing to first element • end() returns iterator pointing to last element – use iterators with sequences (ranges) • containers • input sequences - istream_iterator • output sequences - ostream_iterator
  • 15. Iterators • Iterators are pointer-like entities that are used to access individual elements in a container. • Often they are used to move sequentially from element to element, a process called iterating through a container. vector<int> 17 array_ vector<int>::iterator 4 23 The iterator corresponding to the class vector<int> is of 12 the type vector<int>::iterator size_ 4
  • 16. Iterators • The member functions begin() and end() return an iterator to the first and past the last element of a container v.begin() vector<int> 17 array_ 4 23 v.end() 12 size_ 4
  • 17. Iterators • One can have multiple iterators pointing to different or identical elements in the container vector<int> i1 17 array_ 4 i2 23 12 i3 size_ 4
  • 18. Iterators Types of Iterators Containers provide several iterators Begin, End, Reverse Begin, Reverse End 5 categories – each has specific operations Input, Output, Forward, Bidirectional, Random Input Operations: =, ==, !=, *, ->, ++ , No assignment of *i Output Operations: =, *, ++ Forward Operations: =, ==, !=, *, ->, ++ Bidirectional Operations: =, ==, !=, *, ->, ++, -- Random Operations: =, ==, !=, +=, -=, *, ->, +, ++, -, --, [n], <, <=, >, >=
  • 19. Iterators Category Description input Used to read an element from a container. An input iterator can move only in the forward direction (i.e., from the beginning of the container to the end of the container) one element at a time. Input iterators support only one-pass algorithms—the same input iterator cannot be used to pass through a sequence twice. output Used to write an element to a container. An output iterator can move only in the forward direction one element at a time. Output iterators support only one-pass algorithms—the same output iterator cannot be used to pass through a sequence twice. forward Combines the capabilities of input and output iterators and retains their position in the container (as state information). bidirectional Combines the capabilities of a forward iterator with the ability to move in the backward direction (i.e., from the end of the container toward the beginning of the container). Forward iterators support multi-pass algorithms. random access Combines the capabilities of a bidirectional iterator with the ability to directly access any element of the container, i.e., to jump forward or backward by an arbitrary number of elements.
  • 20. Iterators Container Type of iterator supported Sequence containers vector random access deque random access list bidirectional Associative containers set bidirectional multiset bidirectional map bidirectional multimap bidirectional Container adapters stack no iterators supported queue no iterators supported no iterators supported priority_queue
  • 22. Algorithm STL algorithms are not member functions or friends of containers. They are standalone template functions. To have access to the STL algorithms, we must include <algorithm> in our program. 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
  • 23. Algorithm 1. Retrieve or Non-Mutating algorithms: Algorithms don’t modify the contents of containers they work on. Ex: searching a container for a particular element and returning its position. Functions: count : The count() function returns the number of elements between start and end that match val. equal: The equal () function returns true if the elements in two ranges are the same. The first range of elements is those between start1 and end1. The second range of elements has the same size as the first range but starts at start2. find: The find() algorithm looks for an element matching val between start and end. If an element matching val is found, the return value Is an iterator that points to that element. Otherwise, the return value is an iterator that points to end.
  • 24. Algorithm 2. Mutating algorithms Allows modifying the contents of the containers they work on. Ex: Reversing the contents of containers. copy: The copy() function copies the elements between start and end to dest. In other words, after copy() has run, copy_backward: copy_backward() is similar to (C++ Strings) copy(), in that both functions copy elements from start to end to dest. The copy_backward() function , however, starts depositing elements at dest and then works backwards, such that: fill : The function fill() assigns val to all of the elements between start and end. generate: The generate() function runs the Generator function object g a number of times, saving the result of each execution in the range [start,end). Replaces all elements with the result of an operations
  • 25. Algorithm Sorting algorithms Include general sorting, merges, dictionary comparisons, and binary search Operations.Requires random access iterators. Functions binary_search : The binary_search() function searches from start to end for val. The elements between start and end that are searched should be in ascending order as defined by the < operator. Note that a binary search will not work unless the elements being searched are in order. If val is found, binary_search() returns true, otherwise false. If the function f is specified, then it is used to compare elements. merge : The merge() function combines two sorted ranges [start1,end1) and [start2,end2) into a single sorted range, stored starting at result. The return value of this function is an iterator to the end of the merged range. If the strict weak ordering function object cmp is given, then it is used in place of the < operator to perform comparisons between elements.
  • 26. Algorithm Numeric Algorithms: accumulate : The accummulate() function computes the sum of val and all of the elements in the range [start,end). adjacent_difference: The adjacent_difference() function calculates the differences between adjacent elements in the range [start,end) and stores the result starting at result. partial_sum: The partial_sum() function calculates the partial sum of a range defined by [start,end), storing the output at result.
  • 27. Summary  The standard template library (STL) is the C++ library that provides generic programming for many standard data structures and algorithms.  Containers come in two major families: sequence (are ordered) and associative (have keys for looking up elements).  Iterators can be thought of as an enhanced pointer type.  The algorithms use iterators to access containers. 27
  • 28. Success Story • Millions of copies out • Everybody (Microsoft, IBM, Sun …) ships it • A dozen books • Very few extensions • No language progress • No effect on software engineering 28