Templates. Templates Example: Swap Template Mechanism.

Slides:



Advertisements
Similar presentations
SEG4110 – Advanced Software Design and Reengineering TOPIC J C++ Standard Template Library.
Advertisements

Object Oriented Programming Lect. Dr. Daniel POP Universitatea de Vest din Timişoara Facultatea de Matematică şi Informatică.
Vectors, lists and queues
. STL: C++ Standard Library (continued). STL Iterators u Iterators are allow to traverse sequences u Methods  operator*  operator->  operator++, and.
Exceptions, Templates, And The Standard Template Library (STL) Chapter 16.
Copyright © 2012 Pearson Education, Inc. Chapter 16: Exceptions, Templates, and the Standard Template Library (STL)
Exam Review 2 Chapter 5 – 9 CSC212 RS March 31, 2011, CS Dept, CCNY.
. STL: C++ Standard Library. Main Ideas u General purpose: generic data structures & algorithms, templates u Flexibility: Allows for many combinations.
Standard Containers: Vectors
Standard Template Library. Homework List HW will be posted on webpage Due Nov 15.
1 Lecture 8: Introduction to C++ Templates and Exceptions  C++ Function Templates  C++ Class Templates.
Templates and the STL.
Review for Midterm Chapter 1-9 CSc 212 Data Structures.
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:
Data Structures Using C++ 2E
C++ How to Program, 8/e © by Pearson Education, Inc. All Rights Reserved.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Standard Template Library (STL)
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved ADT Implementations:
Useful Data Structures in C++ and Java. Useful Data Structures in C++ (1) Templates are C++’s mechanism to define abstract objects which can be parameterized.
Templates ©Bruce M. Reynolds & Cliff Green1 C++ Programming Certificate University of Washington Cliff Green.
Data Structures Using C++1 Chapter 4 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.
Templates & STL Stefan Roiser, Lorenzo Moneta CERN PH/SFT.
Copyright 2006, The Ohio State University Introduction to C++ Templates l C++ Function Templates l C++ Class Templates.
Chapter 3 Templates Saurav Karmakar Spring Objective In Chapter 3, we will discuss: The concept of a template Function templates Class templates.
Intro to the C++ STL Timmie Smith September 6, 2001.
Exceptions & Templates
Standard Template Library (STL) - Use Vector and Deque
Chapter 3 Templates. Objective In Chapter 3, we will discuss: The concept of a template Function templates Class templates vector and matrix classes Fancy.
Copyright © 2009 – Curt Hill Standard Template Library An Introduction.
C++ Review STL CONTAINERS.
Exam Review 2 Chapter 5 – 9 CSC212 FG CS Dept, CCNY.
Chapter 1 C++ Templates (Sections 1.6, 1.7). Templates Type-independent patterns that can work with multiple data types. Function Templates  These define.
Chapter 17 – Templates. Function Templates u Express general form for a function u Example: template for adding two numbers Lesson 17.1 template Type.
Copyright © Curt Hill STL Priority Queue A Heap-Like Adaptor Class.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Function Templates 16.2.
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
Programming with ANSI C ++
Standard Template Library
How to be generic Lecture 10
C++ Templates.
Templates.
Exceptions, Templates, and the Standard Template Library (STL)
Exceptions, Templates, and the Standard Template Library (STL)
Data Abstraction & Problem Solving with C++
Starting Out with C++ Early Objects Eighth Edition
Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty
Programming with Concepts
Chapter 5 – 9 CSC212 AB April 03, CS Dept, CCNY
Chapter 5 – 9 CSC212 KL Nov 8, CS Dept, CCNY
ADT Implementations: Templates and Standard Containers
Templates and Standard Containers
Generic Programming Karl Lieberherr 12/1/2018 Generic Programming.
Chapter 5 – 9 CSC212 RS April 08, CS Dept, CCNY
Introduction to Programming
Containers and the Standard Template Library (STL)
Design Patterns Difficult to describe abstractly Elements:
CSE 303 Lecture 25 Loose Ends and Random Topics
Standard Version of Starting Out with C++, 4th Edition
Container classes, ADTs
Exceptions, Templates, and the Standard Template Library (STL)
STL Библиотека стандартных шаблонов
Tenth step for Learning C++ Programming
Lecture 8: Introduction to C++ Templates and Exceptions
For each of these data structures
SPL – PS1 Introduction to C++.
Standard Template Library
Presentation transcript:

Templates

Example: Swap

Template Mechanism

Template Mechanism Comments

Template Use

Template Instantiation

Template Instantiation

Template Instantiation

General Form of Template

Example

Example Continued

Example Continued

Templates with multiple parameters

Templates with multiple parameters

Templates with multiple parameters

Class templates

What’s wrong with typedef?

Type-independent Container

General form of class template

Instantiating class templates

Rules for class templates

Templates with ordinary parameters

STL (Standard Template Library)

STL Containers

vectors

vector inefficiences

STL’s stack container

STL’s stack container

Example: convert base 10 to base 2

Example: convert base 10 to base 2

STL queue container

queue example

queue example

STL deque

STL deque<T> class template

STL algorithms

Supply own comparison operator