L4_stl_types - 1 Introduction to the C++ Standard Library....

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 1 Introduction to the C++ Standard Library. For : COP 3330. Object oriented Programming (Using C++) http://www.compgeom.com/~piyush/teach/3330 Piyush Kumar The C++ Standard Library | Provides the ability to use: z String Types z Data Structures (linked list, dynamic arrays, priority queues, binary trees etc) z Algorithms (Sorting and Searching…) z IO z Classes for internationalization support. The C++ Standard Library | Not very homogeneous: z String classes are safe and convenient to use (almost self explanatory). z The Standard Template Library (STL) optimizes for performance and is not required to check for errors. To use it well, you need to understand the concepts and apply them carefully. C++ Standard Library | Containers z Objects that hold/contain other objects. z Examples: vector, string | Algorithms z Work on the containers z Examples: sort, search | Iterators z Provide pointer like interface to containers. Other components | Allocators: Provide memory management for containers. Can be customized. | Adaptors: A mechanism to make one thing act like another. Example: Stack. | Function objects: A function object or a functor , is a construct allowing an object to be invoked or called as if it were an ordinary function , Containers | Of course: Contain objects/built in types. z More powerful than arrays. z Grow (and shrink?) dynamically z Manage their own memory z Keep track of their size z Allow optimal algorithmic operations like scan, sorts etc. 2 Containers | Standard STL sequence Containers: z vector, string , deque and list | Standard non-STL containers: z bitset , valarray, priority_queue, queue. Containers | Prefer sequential containers to arrays. | Use vector by default | Use list when there are a lot of insertions/deletions in the middle of the sequence. | Use deque when there is a lot of insertion at the beginning or the end of the sequence. What is a vector? | A contiguous array of elements | The first “size” elements are constructed (initialized) | The last “capacity - size” elements are uninitialized | Four data members z data pointer z size z capacity z allocator data size capacity allocator or equivalent data size capacity allocator Sample data layout: Internals. Vector Interface template <class T, class Al ocator = al ocator<T> > class vector { public: ... explicit vector(const Al ocator& = Al ocator()); explicit vector(size_type n, const T& value = T(), const Al ocator& = Al ocator()); ... void reserve(size_type n); ... void resize(size_type sz, const T& c = T()); ... void push_back(const T& x); void pop_back(); ... iterator insert(iterator position, const T& x); void insert(iterator position, size_type n, const T& x); ......
View Full Document

This note was uploaded on 02/27/2012 for the course CS 251 taught by Professor Staff during the Fall '08 term at Purdue University.

Page1 / 10

L4_stl_types - 1 Introduction to the C++ Standard Library....

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online