Title: Standard Template Library
1Standard Template Library
Module Object Orientated Methods
- Batch 2
- Pradeep Kumar Voorukonda (17039877)
- Vinay Gunreddy (17033050)
- Rangarao Ponugoti(17033049)
2Introduction
- The STL is a complex piece of software
engineering that uses some of C's most
sophisticated features - STL provides an incredible amount of generic
programming power - It provides general purpose, templatized classes
and functions - The STL is mainly composed of generic container
class templates and a set of many efficient
template algorithms
3Components of STL
- Container Classes
- Generic Algorithms
- Iterators
- Function Objects
- Allocators
- Adaptors
4CONTAINERS
5Introduction to Containers
- Container is an object that holds another object
- More powerful and flexible than arrays
- It will grow or shrink dynamically and manage
their own memory - keep track of how many objects they hold
6Types of Containers
7Standard Sequence Containers
- Vectors,
- Lists,
- De-queue, and
- Strings
Syntax
- template ltclass T, class A allocatorltTgt gt
- Where
- T is the data type to use and
- A is the storage allocator which defaults to the
standard allocator for type T
8Vectors
- It is the type of sequence container that should
be used by default - It can change size dynamically
- It provides best random access performance
- It permits insertions and deletions at the back
Template Specification
The template specification for vector is shown
here template ltclass T, class AallocatorltTgtgt
class vector Here T is the type of the data
stored, A is the storage allocator
9Lists
- The list container implements a doubly linked
list - It supports a bidirectional, i.e. they may be
accessed front to back or back to front - Unlike a vector, which supports random access, a
list can be accessed sequentially only. - It provides insertions and deletions anywhere in
the list
Template Specification
template ltclass T, class AllocatorallocatorltTgtgt
class list Here T is the type of the data stored
in the list and Allocator provides default
storage location
10ITERATORS
11Introduction
- An iterator is an extension to the pointer
- It implements the standard pointer operators
- It gives you the ability to cycle through the
contents of the container like a pointer to
cycle through an array - Iterators used by the algorithms to move through
the containers
Syntax
stdclass_namelttemplate_parametersgt iterator
name where name - name of the iterator,
class_name - name of the STL container,
template_parameters - parameters to the template,
and finally, std - namespace having collection of
STL classes
12Basic Types of Iterators
- Random Access Iterator
- Bidirectional Iterator
- Forward Iterator
- Input Iterator
- Output Iterator
13ALGORITHMS
14Introduction
- Used generically across a variety of containers.
- STL provides many algorithms to manipulate
containers. - STL provides approximately 70 standard algorithms
that operate on container elements only
indirectly through iterators. - Many algorithms operate on sequence of elements
defined by pairs of iterators - It is possible to create new algorithms that
operate in a similar fashion so they can be used
with the STL containers and iterators.
15Basic Types of Algorithms
- Mutating Sequence Algorithms
- like copy(), remove(), replace(), fill(),
swap(), etc., - Non Modifying sequence Algorithms
- like find(), count(),search(), mismatch(), and
equal() - Numerical Algorithms
- accumulate(), partial_sum(), inner_product(),
and adjacent_difference()
16Thank You
17Queries?