Generic Programming Karl Lieberherr 12/1/2018 Generic Programming.

Slides:



Advertisements
Similar presentations
M The University Of Michigan Andrew M. Morgan EECS Lecture 22 Savitch Ch. 16 Intro To Standard Template Library STL Container Classes STL Iterators.
Advertisements

Copyright © 2002 Pearson Education, Inc. Slide 1.
Chapter 19 Standard Template Library. Copyright © 2006 Pearson Addison-Wesley. All rights reserved Learning Objectives Iterators Constant and mutable.
SEG4110 – Advanced Software Design and Reengineering TOPIC J C++ Standard Template Library.
. STL: C++ Standard Library (continued). STL Iterators u Iterators are allow to traverse sequences u Methods  operator*  operator->  operator++, and.
TEMPLATES Lecture Presented By SHERY KHAN Object Orienting Programming.
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.
. The Standard C++ Library. 2 Main Ideas Purpose Flexibility Efficiency Simple & Uniform Interface.
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)
Standard Template Library (STL) Overview – Part 1 Yngvi Bjornsson.
CMSC 202 Lesson 24 Iterators and STL Containers. Warmup Write the class definition for the templated Bag class – A bag has: Random insertion Random removal.
Data Structures Using C++1 Chapter 13 Standard Template Library (STL) II.
Basic C++ Sequential Container Features
Generic programming starts with algorithms. Lift Minimal requirements: works with maximal family of types Concrete algorithm: requires specific data type.
Rossella Lau Lecture 12, DCO10105, Semester B, DCO10105 Object-Oriented Programming and Design  Lecture 12: An Introduction to the STL  Basic.
Lecture 23 Today Standard Template Library Programs in: programs/p19 Bibliography: Textbook p.252,
Writing Your Own STL Container Ray Lischner
Spring 2010 Advanced Programming Section 1-STL Computer Engineering Department Faculty of Engineering Cairo University Advanced Programming Spring 2010.
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.
Object Oriented Programming Elhanan Borenstein Lecture #11 copyrights © Elhanan Borenstein.
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.
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)
Standard Template Library The Standard Template Library was recently added to standard C++. –The STL contains generic template classes. –The STL permits.
1 Iterators Good reference site:
CS 403, Class 23Slide #1 CS Programming Languages Class 23 November 16, 2000.
Chapter 22 STL Containers §22.1 STL Basics §22.2 STL Iterators §22.3 Sequence Containers §22.4 Associative Containers §22.5 Container Adapters.
Computer Science and Software Engineering University of Wisconsin - Platteville 11.Standard Template Library Yan Shi CS/SE 2630 Lecture Notes.
CS 403: Programming Languages Lecture 24 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
Intro to the C++ STL Timmie Smith September 6, 2001.
Standard Template Library (STL) - Use Vector and Deque
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.
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)
Programming in C++ Michal Brabec Petr Malý. Standard Template Library Containers - vector, map, set, deque, list Algorithms - copy, replace, sort, find.
Chapter 17 – Templates. Function Templates u Express general form for a function u Example: template for adding two numbers Lesson 17.1 template Type.
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.
Final Exam Review COP4530.
CS212: Object Oriented Analysis and Design
Programming with ANSI C ++
Standard Template Library
Standard Template Library (STL)
Starting Out with C++ Early Objects Eighth Edition
Prof. Michael Neary Lecture 7: The STL Prof. Michael Neary
Programming with Concepts
Chapter 22: Standard Template Library (STL)
CS212: Object Oriented Analysis and Design
Final Exam Review COP4530.
Containers, Iterators, Algorithms, Thrust
Design Patterns Difficult to describe abstractly Elements:
Standard Template Library
Standard Template Library
Standard Template Library
Some Definitions vector, string, deque, and list are standard sequence containers. set, multiset, map, multimap, unordered_set, unordered_multiset, unordered_map.
Standard Template Library
Presentation transcript:

Generic Programming Karl Lieberherr 12/1/2018 Generic Programming

What is it? Goal: to have libraries of generic or reusable software components reusable means widely adaptable, but still efficient adaptation is done by programming language mechanism rather than manual text editing. 12/1/2018 Generic Programming

What is it? Focus on high degree of adaptability and efficiency Essential idea: Generic algorithms, not self-contained, use container access operations Container classes with iterator classes 12/1/2018 Generic Programming

What is it? Expressing algorithms with minimal assumptions about data abstractions, and vice versa, thus making them as interoperable as possible Lifting of a concrete algorithm to as a general level as possible without losing efficiency 12/1/2018 Generic Programming

What is it? From Dagstuhl 98 conference on generic programming Lifting of a concrete algorithm to as a general level as possible without losing efficiency i.e., the most abstract form such that when specialized back to the concrete case the result is just as efficient as the original algorithm. From Dagstuhl 98 conference on generic programming 12/1/2018 Generic Programming

What is it? Generic programming is about making programs more adaptable by making them more general Embody non-traditional kinds of polymorphism Parameters of a generic program are rich in structure (programs, types, graphs). From Workshop on Gen. Prog. Sweden 98 12/1/2018 Generic Programming

Overview of STL components Containers Sequence containers Sorted Associative Containers Generic Algorithms find, merge, search, copy, count, sort, accumulate Iterators Function Objects Adaptors Allocators 12/1/2018 Generic Programming

Using STL is about plugging the right components together. Function object Container Generic Algorithm List(T) Sort Less(T) Iterator Using STL is about plugging the right components together. 12/1/2018 Generic Programming

Iterators Input Iterator: reading Output Iterator: writing Forward Iterator: Input Iterator, Output Iterator, traversal in one direction Bidirectional Iterator: Forward Iterator plus bidirectional traversal Random Access Iterator: Bidirectional Iterator, constant time access 12/1/2018 Generic Programming

template <class InputIterator, class T> InputIterator find(InputIterator first, InputIterator last, const T& value) { while (first != last && *first != value) ++ first; return first; } Works with any input iterator since (1) it only applies !=, * and ++ to its iterator parameters (2) it never tries to assign to objects it obtains using * and (3) it is a single pass algorithm. Designing Generic Algorithms 12/1/2018 Generic Programming

Constant versus Mutable Iterators Forward, bidirectional and random-access iterators can be mutable or constant. 12/1/2018 Generic Programming

Iterator categories provided by containers 12/1/2018 Generic Programming

Generic Algorithms Basic algorithm organization in-place: places result into same container copying: copies result to a different container Nonmutating Sequence Algorithms find, adjacent_find, count, for_each,… Mutating Sequence Algorithms copy, copy_backward, fill, generate, ... 12/1/2018 Generic Programming

Generic Algorithms Sorting-Related Algorithms sort, partial_sort, nth_element, binary_search, ... Generalized Numeric Algorithms accumulate, partial_sum, adjacent_difference, ... 12/1/2018 Generic Programming

Containers Sequence containers Sorted associative containers vector, deque, list Sorted associative containers set, multiset, map and multimap 12/1/2018 Generic Programming

Container Adaptors Change interface of another component Stack Container Adaptor Queue Container Adaptor Dequeue Container Adaptor 12/1/2018 Generic Programming

Iterator Adaptors Change interface of an iterator reverse_bidirectional_iterator reverse_iterator (mutable) const_iterator (immutable) Insert Iterators back_inserter front_inserter inserter 12/1/2018 Generic Programming

Function Adaptors Negators Binders (partial evaluation) Adaptors for Pointers to Functions 12/1/2018 Generic Programming

Summary STL does a good job at providing a library of reusable components. But generic programming can be much more generic than STL indicates. Parameterize with more complex structures than classes. 12/1/2018 Generic Programming