Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction The STL is a complex piece of software engineering that uses some of C++'s most sophisticated features STL provides an incredible amount.

Similar presentations


Presentation on theme: "Introduction The STL is a complex piece of software engineering that uses some of C++'s most sophisticated features STL provides an incredible amount."— Presentation transcript:

1

2 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

3 Components of STL Container Classes Generic Algorithms Iterators Function Objects Allocators Adaptors 3Standard Template Library

4 CONTAINERS 4Standard Template Library

5 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

6 Types of Containers 6Standard Template Library

7 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

8 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

9 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

10 10Standard Template Library

11 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

12 Basic Types of Iterators Random Access Iterator Bidirectional Iterator Forward Iterator Input Iterator Output Iterator 12Standard Template Library

13 13Standard Template Library

14 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

15 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

16 16Standard Template Library

17 17


Download ppt "Introduction The STL is a complex piece of software engineering that uses some of C++'s most sophisticated features STL provides an incredible amount."

Similar presentations


Ads by Google