CS 403: Programming Languages Lecture 24 Fall 2003 Department of Computer Science University of Alabama Joel Jones.

Slides:



Advertisements
Similar presentations
Chapter 19 Standard Template Library. Copyright © 2006 Pearson Addison-Wesley. All rights reserved Learning Objectives Iterators Constant and mutable.
Advertisements

TEMPLATES Lecture Presented By SHERY KHAN Object Orienting Programming.
CSE 332: C++ Algorithms I The C++ Algorithm Libraries A standard collection of generic algorithms –Applicable to various types and containers E.g., sorting.
C++ Sets and Multisets Set containers automatically sort their elements automatically. Multisets allow duplication of elements whereas sets do not. Usually,
. STL: C++ Standard Library. Main Ideas u General purpose: generic data structures & algorithms, templates u Flexibility: Allows for many combinations.
What is generic programming? The essence of the generic programming approach is concept development: systematic classification of computing components.
COMP 171 Data Structures and Algorithms Tutorial 1 Template and STL.
Concept= a set of abstractions (e.g., types) (Generic Programming) Programming with Concepts defined by a set of requirements {vector, deque, list, set,
C++ Programming: Program Design Including Data Structures, Second Edition Chapter 22: Standard Template Library (STL)
Data Structures Using C++1 Chapter 13 Standard Template Library (STL) II.
. STL: C++ Standard Library. Main Ideas u General purpose: generic data structures & algorithms, templates u Flexibility: Allows for many combinations.
Generic programming starts with algorithms. Lift Minimal requirements: works with maximal family of types Concrete algorithm: requires specific data type.
. STL: C++ Standard Library (continued). STL Iterators u Iterators are allow to traverse sequences u Methods  operator*  operator->  operator++, and.
Rossella Lau Lecture 12, DCO10105, Semester B, DCO10105 Object-Oriented Programming and Design  Lecture 12: An Introduction to the STL  Basic.
CSE 332: C++ templates and generic programming I Motivation for Generic Programming in C++ We’ve looked at procedural programming –Reuse of code by packaging.
Standard Template Library C++ introduced both object-oriented ideas, as well as templates to C Templates are ways to write general code around objects.
Lecture 11 Standard Template Library Stacks, Queue, and Deque Lists Iterators Sets Maps.
Writing Your Own STL Container Ray Lischner
CSIS 123A Lecture 12 Templates. Introduction  C++ templates  Allow very ‘general’ definitions for functions and classes  Type names are ‘parameters’
Spring 2010 Advanced Programming Section 1-STL Computer Engineering Department Faculty of Engineering Cairo University Advanced Programming Spring 2010.
Standard Template Library Programming paradigm: generic programming the decomposition of programs into components which may be developed separately and.
Dr. Yingwu Zhu STL Vector and Iterators. STL (Standard Template Library) 6:14:43 AM 2 A library of class and function templates Components: 1. Containers:
STL Standard Template Library ● Good reference book: – The C++ Standard Library ● A Tutorial and Reference ● by Nicolai M. Josuttis ● 1999 – Addison Wesley.
Data Structures Using C++ 2E
Containers and Iterators CNS 3370 Copyright 2003, Fresh Sources, Inc.
CNS  Sequences  vector,deque,list,(string),forward_list  Container Adapters  queue, stack, priority_queue  Associative Containers  set, unordered_set.
C++ How to Program, 8/e © by Pearson Education, Inc. All Rights Reserved.
PRESENTED BY: RAJKRISHNADEEPAK.VUYYURU SWAMYCHANDAN.DONDAPATI VINESHKUMARREDDY.LANKA RAJSEKHARTIRUMALA KANDURI ALAN.
Generic Programming Using the C++ Standard Template Library.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Standard Template Library (STL)
The C++ Standard Template Library. What is STL A subset of the standard C++ library –The string class is not part of it! 3 major components –Algorithms.
Data Structures Using C++ 2E Chapter 13 Standard Template Library (STL) II.
Review for Final Andy Wang Data Structures, Algorithms, and Generic Programming.
Software Design 1.1 Tapestry classes -> STL l What’s the difference between tvector and vector  Safety and the kitchen sink What happens with t[21] on.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 22: Standard Template Library (STL)
CSE 332: C++ STL containers Review: C++ Standard Template Library (STL) The STL is a collection of related software elements –Containers Data structures:
Templates code reuse - inheritance - template classes template classes - a class that is not data-type specific - eg. a class of Array of any type - intArray,
Standard Template Library The Standard Template Library was recently added to standard C++. –The STL contains generic template classes. –The STL permits.
Introduction to the Standard Template Library (STL) A container class holds a number of similar objects. Examples: –Vector –List –Stack –Queue –Set –Map.
1 Iterators Good reference site:
CS 403, Class 23Slide #1 CS Programming Languages Class 23 November 16, 2000.
 2003 Prentice Hall, Inc. All rights reserved.m ECE 2552 Dr. Këpuska based on Dr. S. Kozaitis Summer Chapter 15 - Class string and String Stream.
Lecture 7 : Intro. to STL (Standard Template Library)
Computer Science and Software Engineering University of Wisconsin - Platteville 11.Standard Template Library Yan Shi CS/SE 2630 Lecture Notes.
Intro to the C++ STL Timmie Smith September 6, 2001.
STL – Standard Template Library L. Grewe. 2 Goals Lots of important algorithms, data structures in CS using Templates. is a software library partially.
STL CSSE 250 Susan Reeder. What is the STL? Standard Template Library Standard C++ Library is an extensible framework which contains components for Language.
Copyright © 2009 – Curt Hill Standard Template Library An Introduction.
Introduction The STL is a complex piece of software engineering that uses some of C++'s most sophisticated features STL provides an incredible amount.
C++ Review STL CONTAINERS.
CSCI 383 Object-Oriented Programming & Design Lecture 25 Martin van Bommel.
CSE 332: C++ STL iterators What is an Iterator? An iterator must be able to do 2 main things –Point to the start of a range of elements (in a container)
Algorithms CNS 3370 Copyright 2003, Fresh Sources, Inc.
Chapter 17 – Templates. Function Templates u Express general form for a function u Example: template for adding two numbers Lesson 17.1 template Type.
Introduction to Templates and Standard Template Library 1.
Object-Oriented Programming (OOP) Lecture No. 42.
Unit VI.  C++ templates are a powerful mechanism for code reuse, as they enable the programmer to write code (classes as well as functions) that behaves.
1 The Standard Template Library The STL is a collection of Container classes These are class templates for containers. A container is an object that stores.
Object-Oriented Programming (OOP) Lecture No. 41
Standard Template Library (STL)
Programming with Concepts
Chapter 22: Standard Template Library (STL)
Miscellaneous Stuff Which there wasn’t enough time to cover
CS212: Object Oriented Analysis and Design
Generic Programming Karl Lieberherr 12/1/2018 Generic Programming.
Standard Template Library
Standard Template Library
Standard Template Library
Presentation transcript:

CS 403: Programming Languages Lecture 24 Fall 2003 Department of Computer Science University of Alabama Joel Jones

Lecture 242 Overview Announcements Talk today Colloquim tomorrow at 11AM in Houser 108, Jiageng Li, University of Alabama, Integrated Authorization for Grid System Environments Review Session next class Study Guide MP3 questions Evaluation Forms The STL from a comparative programming language standpoint

The Computer Science Department, CS Advisory Board, and ACM Student Chapter present Mike Thomas CIO, Gulf States Paper “Computer Science in Heterogenous, Multidimensional Business Environments” 5:00-6:00 PM, Tuesday, Dec. 2 nd, EE 119 Pizza & drinks served.

Lecture 244 Collections Almost all programming languages support aggregations of primitive types in some way C has structs, unions, arrays Pair Up: What way of aggregating does Smalltak have? What way of aggregating does Scheme have ?

Lecture 245 Closures and aggregation Aggregation is just a simple data type mechanism—what else is needed to have concise powerful? A lower syntactic overhead way of specifying new behavior that works over an aggregate data structure Smalltalk: myCollection do: [ code ] Scheme: (map myList (lambda code )) Works because the language provides a way of specifying functions “in-place”

Lecture 246 C++ Templates Parameterized data types Type-safe macros Come in two types Class Templates Function Templates

Lecture 247 Class Templates Can specialize with class (see listing #1) template class Stack… Stack Or any other type Stack

Lecture 248 Class Template Member Functions Method body must be in.h file

Lecture 249 Using a Class Template See listing #2 What is the output?

Lecture 2410 Function Templates Specialize a function to take polymorphic arguments Template T max(T a, T b) But be careful with pointer types… See listing #3 What does it print?

Lecture 2411 Template Function Specialization To fix “problem”, use type-specific version: template<> char* max(char* a, char* b) { return strcmp(a, b) > 0 ? a : b; }

Lecture 2412 Standard Template Library (STL) Good reference at: Generic Programming specify algorithms and data structures that work with any data type Core Components Containers Algorithms Iterators

Lecture 2413 STL: Containers Data structures that manage a set of memory locations Doesn’t contain many member functions Creating, copying, destroying, adding, removing No pointers to elements Algorithms do the “day-to-day” stuff

Lecture 2414 STL: Iterators Used to traverse elements of containers Uniform set/naming across containers Algorithms designed to work with a particular iterator category Random Access Bi-Directional Forward OutputInput

Lecture 2415 STL: Algorithms Decoupled from containers Parameterized by iterator types Algorithm categories: Non-mutating sequence operations Mutating sequence operations Searching and Sorting Set Operations Heap operations Numeric operations Miscellaneous

Lecture 2416 Orthogonal Component Structure So how does this all work together? vector v(3); v[0] = 7; v[1] = v[0] + 3; v[2] = v[0] + v[1]; reverse(v.begin(), v.end()); So what kind of components are v, v.begin(), and reverse? AlgorithmIteratorContainer

Lecture 2417 Example STL: deque Double-Ended QUEue Supports: Random access to elements Constant time insertion & removal of end Linear time insertion and removal of elements in the middle Constant time insertion & removal of beginning What role would the template parameter to deque fulfill?

Lecture 2418 Example STL: deque Use: deque Q; Q.push_back(3); Q.push_front(1); Q.insert(Q.begin() + 1, 2); Q[2] = 0; copy(Q.begin(), Q.end(), ostream_iterator (cout, “ “)); What does this do?

Lecture 2419 Example STL: stack Adaptor that supports restricted subset of Container functionality Insertion, removal, and inspection of element at the top of the stack Does not allow iteration through its elements

Lecture 2420 Example STL: stack Example use: int main() { stack S; S.push(8); S.push(7); S.push(4); assert(S.size() == 3); assert(S.top() == 4); S.pop(); assert(S.top() == 7); S.pop(); assert(S.top() ==8); S.pop(); assert(S.empty()); }

Lecture 2421 Containers Sequences vector, deque, list, slist, bit_vector, Associative Containers set, map, multiset, multimap, hash_set, hash_map, hash_multiset, hash_multimap, hash String package char_traits, basic_string, rope (not STL) Container adaptors stack, queue, priority_queue, bitset

Lecture 2422 Algorithms Non-mutating algorithms for_each, find,, count, mismatch, equal, search Mutating algorithms copy, swap, transform, replace, fill, generate, remove, unique, reverse, rotate, random_shuffle, random_sample, partition, stable_partition, sorting, nth_element, binary search, merge, set operations heap operations, min and max, lexicographical_compare, permutations Generalized numeric algorithms iota, accumulate, inner_product, partial_sum, adjacent_difference, power

Lecture 2423 Iterators Iterator classes istream_iterator ostream_iterator front_insert_iterator back_insert_iterator insert_iterator reverse_iterator reverse_bidirectional_iterator raw_storage_iterator sequence_buffer