180 likes | 204 Vues
Standard Template Library. Batch 2 Pradeep Kumar Voorukonda (17039877) Vinay Gunreddy (17033050) Rangarao Ponugoti (17033049). Module : Object Orientated Methods. Introduction. The STL is a complex piece of software engineering that uses some of C++'s most sophisticated features
E N D
Standard Template Library Batch 2 Pradeep Kumar Voorukonda (17039877) Vinay Gunreddy (17033050) RangaraoPonugoti(17033049) Module : Object Orientated Methods
Introduction • 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 Standard Template Library
Components of STL • Container Classes • Generic Algorithms • Iterators • Function Objects • Allocators • Adaptors Standard Template Library
CONTAINERS Standard Template Library
Introduction 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 Standard Template Library
Types of Containers Standard Template Library
StandardSequenceContainers • Vectors, • Lists, • De-queue, and • Strings Syntax template <class T, class A= allocator<T> > Where • Tis the data type to use and • A is the storage allocator which defaults to the standard allocator for type T Standard Template Library
Vectors • 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 <class T, class A=allocator<T>> class vector Here T is the type of the data stored, A is the storage allocator Standard Template Library
Lists • 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 <class T, class Allocator=allocator<T>> class list Here T is the type of the data stored in the list and Allocator provides default storage location Standard Template Library
ITERATORS Standard Template Library
Introduction • 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 std::class_name<template_parameters>:: 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 Standard Template Library
Basic Types of Iterators • Random Access Iterator • Bidirectional Iterator • Forward Iterator • Input Iterator • Output Iterator Standard Template Library
ALGORITHMS Standard Template Library
Introduction • 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. Standard Template Library
Basic Types of Algorithms • Mutating Sequence Algorithms likecopy(), 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() Standard Template Library
Thank You Standard Template Library
Queries? Standard Template Library