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 2Standard Template Library
Components of STL Container Classes Generic Algorithms Iterators Function Objects Allocators Adaptors 3Standard Template Library
CONTAINERS 4Standard 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 5Standard Template Library
Types of Containers 6Standard Template Library
Syntax Standard Sequence Containers Vectors, Lists, De-queue, and Strings template > Where T is the data type to use and A is the storage allocator which defaults to the standard allocator for type T 7Standard 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 vector Here T is the type of the data stored, A is the storage allocator 8Standard Template Library
Template Specification 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 > class list Here T is the type of the data stored in the list and Allocator provides default storage location 9Standard Template Library
10Standard 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 :: 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 11Standard Template Library
Basic Types of Iterators Random Access Iterator Bidirectional Iterator Forward Iterator Input Iterator Output Iterator 12Standard Template Library
13Standard 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. 14Standard Template Library
Basic 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() 15Standard Template Library
16Standard Template Library
17