SlideShare a Scribd company logo
Standard Template Library
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

More Related Content

PDF
Managing I/O in c++
PPTX
Graph traversals in Data Structures
PDF
C++ Files and Streams
PDF
Algebraic Structure
PDF
Python list
DOCX
DAA Lab File C Programs
PDF
Python set
PDF
Java I/o streams
Managing I/O in c++
Graph traversals in Data Structures
C++ Files and Streams
Algebraic Structure
Python list
DAA Lab File C Programs
Python set
Java I/o streams

What's hot (20)

PPTX
Priority Queue in Data Structure
PPTX
Types of grammer - TOC
PPTX
Lexical analyzer generator lex
PPSX
PPT
Time complexity
PPTX
class and objects
PPTX
Vector class in C++
PPT
Static and Dynamic polymorphism in C++
PPTX
PDF
Standard template library
PPTX
1.9. minimization of dfa
PPTX
Queue Implementation Using Array & Linked List
PPTX
Disjoint sets union, find
PPTX
Constructor in java
PPTX
Transaction management DBMS
PPTX
Data Structure - Elementary Data Organization
PPTX
Python-Encapsulation.pptx
PDF
Symbol table in compiler Design
PPTX
Chapter 05 classes and objects
PPT
Extensible hashing
Priority Queue in Data Structure
Types of grammer - TOC
Lexical analyzer generator lex
Time complexity
class and objects
Vector class in C++
Static and Dynamic polymorphism in C++
Standard template library
1.9. minimization of dfa
Queue Implementation Using Array & Linked List
Disjoint sets union, find
Constructor in java
Transaction management DBMS
Data Structure - Elementary Data Organization
Python-Encapsulation.pptx
Symbol table in compiler Design
Chapter 05 classes and objects
Extensible hashing
Ad

Viewers also liked (20)

PDF
STL in C++
PPT
standard template library(STL) in C++
PDF
C++ Standard Template Library
PPT
Stl (standard template library)
PPTX
Standard template library
ODP
C++ STL 概觀
PDF
Programming in c++
PPTX
Managing console input and output
PDF
An Introduction to Part of C++ STL
PPTX
How to choose best containers in STL (C++)
PPT
Templates exception handling
PPTX
New Ways of Working Fleur Bothwick, OBE, EMEIA Director of Diversity and Incl...
PPTX
Templates presentation
PPTX
Lecture11 standard template-library
PPTX
inheritance c++
PPT
FUNCTIONS IN c++ PPT
PPT
Functions in C++
PPT
Stl Containers
PPTX
Templates in C++
PPT
Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...
STL in C++
standard template library(STL) in C++
C++ Standard Template Library
Stl (standard template library)
Standard template library
C++ STL 概觀
Programming in c++
Managing console input and output
An Introduction to Part of C++ STL
How to choose best containers in STL (C++)
Templates exception handling
New Ways of Working Fleur Bothwick, OBE, EMEIA Director of Diversity and Incl...
Templates presentation
Lecture11 standard template-library
inheritance c++
FUNCTIONS IN c++ PPT
Functions in C++
Stl Containers
Templates in C++
Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...
Ad

Similar to Standard Template Library (20)

PPTX
oops_final_ppt[1].pptx
PDF
Effective stl notes
PDF
Container and algorithms(C++)
PDF
Sppu University|BE|Computer Engineering|OOPs|unit 6 notes|ppt
PPTX
Advanced oops using c and c++.Pptx in Srm
PPTX
Object Oriented Programming Using C++: C++ STL Programming.pptx
PPT
Savitch Ch 18
PPT
C++ STL standard template librairy in OOPs.ppt
PPTX
Standard template library
PDF
Dimitry Solovyov - The imminent threat of functional programming
PDF
Data Structures and Algorithms
PPTX
C++ STL (quickest way to learn, even for absolute beginners).pptx
PPTX
C++ STL (quickest way to learn, even for absolute beginners).pptx
PPTX
Standard Template Library
ODP
Sysprog 9
PPT
Savitch ch 18
PPT
Standard Template Library (STL) in Object Oriented Programming
PDF
The STL
PPTX
Object Oriented Design and Programming Unit-05
oops_final_ppt[1].pptx
Effective stl notes
Container and algorithms(C++)
Sppu University|BE|Computer Engineering|OOPs|unit 6 notes|ppt
Advanced oops using c and c++.Pptx in Srm
Object Oriented Programming Using C++: C++ STL Programming.pptx
Savitch Ch 18
C++ STL standard template librairy in OOPs.ppt
Standard template library
Dimitry Solovyov - The imminent threat of functional programming
Data Structures and Algorithms
C++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptx
Standard Template Library
Sysprog 9
Savitch ch 18
Standard Template Library (STL) in Object Oriented Programming
The STL
Object Oriented Design and Programming Unit-05

More from Kumar Gaurav (6)

PPT
Numerical method
DOC
Cellular network History
PPTX
Cellular networks
PPTX
Polymorphism
PPTX
PPT
Python
Numerical method
Cellular network History
Cellular networks
Polymorphism
Python

Recently uploaded (20)

PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
Spectroscopy.pptx food analysis technology
PDF
Machine learning based COVID-19 study performance prediction
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Electronic commerce courselecture one. Pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Digital-Transformation-Roadmap-for-Companies.pptx
Spectroscopy.pptx food analysis technology
Machine learning based COVID-19 study performance prediction
Diabetes mellitus diagnosis method based random forest with bat algorithm
Spectral efficient network and resource selection model in 5G networks
Electronic commerce courselecture one. Pdf
The AUB Centre for AI in Media Proposal.docx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
“AI and Expert System Decision Support & Business Intelligence Systems”
MIND Revenue Release Quarter 2 2025 Press Release
NewMind AI Weekly Chronicles - August'25 Week I
The Rise and Fall of 3GPP – Time for a Sabbatical?
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
MYSQL Presentation for SQL database connectivity
Reach Out and Touch Someone: Haptics and Empathic Computing
Review of recent advances in non-invasive hemoglobin estimation
Mobile App Security Testing_ A Comprehensive Guide.pdf
Unlocking AI with Model Context Protocol (MCP)
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...

Standard Template Library

  • 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