CSE 303 Lecture 25 Loose Ends and Random Topics

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.
Hold data and provide access to it. Random-access containers: -Allow accessing any element by index -arrays, vectors Sequential containers: -Allow accessing.
1 CSE 331 Enumerated types ( enum ) slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer, Wikipedia
Java for C++ Programmers Second Night. Overview First Night –Basics –Classes and Objects Second Night –Enumerations –Exceptions –Input/Output –Templates.
SEG4110 – Advanced Software Design and Reengineering TOPIC J C++ Standard Template Library.
Brown Bag #2 Advanced C++. Topics  Templates  Standard Template Library (STL)  Pointers and Smart Pointers  Exceptions  Lambda Expressions  Tips.
Vectors, lists and queues
C++ Templates. What is a template? Templates are type-generic versions of functions and/or classes Template functions and template classes can be used.
Cmput Lecture 8 Department of Computing Science University of Alberta ©Duane Szafron 2000 Revised 1/26/00 The Java Memory Model.
STL. What is STL? Standard Templates Library Templates are best used for –Defining containers for storing data –Some kinds of algorithms that work the.
COMP 171 Data Structures and Algorithms Tutorial 1 Template and STL.
More on the STL vector list stack queue priority_queue.
Main Index Contents 11 Main Index Contents Container Types Container Types Sequence Containers Sequence Containers Associative Containers Associative Containers.
Templates & STL Instructor: 小黑. Templates  Template serves as a class outline, from which specific classes are generated at compile time.  One template.
Starting Out with C++: Early Objects 5/e © 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5 th Edition Chapter 16 Exceptions,
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.
Templates and the STL.
CSE 332: C++ Algorithms II From Last Time: Search with Generic Iterators Third generalization: separate iterator type parameter We arrive at the find algorithm.
CSIS 123A Lecture 12 Templates. Introduction  C++ templates  Allow very ‘general’ definitions for functions and classes  Type names are ‘parameters’
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:
Data Structures Using C++ 2E
CSE 332: C++ Type Programming: Associated Types, Typedefs and Traits A General Look at Type Programming in C++ Associated types (the idea) –Let you associate.
CSE 332: C++ STL algorithms C++ STL Algorithms Generic algorithms –Apply to a wide range of types E.g., sorting integers (long) or intervals (long, long)‏
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Standard Template Library (STL)
CSE 303 Concepts and Tools for Software Development Richard C. Davis UW CSE – 12/6/2006 Lecture 24 – Profilers.
CSE 332: C++ STL containers Review: C++ Standard Template Library (STL) The STL is a collection of related software elements –Containers Data structures:
Standard Template Library The Standard Template Library was recently added to standard C++. –The STL contains generic template classes. –The STL permits.
Iterator for linked-list traversal, Template & STL COMP171 Fall 2005.
CSE 332: C++ template examples Concepts and Models Templates impose requirements on type parameters –Types that are plugged in must meet those requirements.
CS 403, Class 23Slide #1 CS Programming Languages Class 23 November 16, 2000.
Lecture 8-3 : STL Algorithms. STL Algorithms The Standard Template Library not only contains container classes, but also algorithms that operate on sequence.
Lecture 11 Standard Template Library Lists Iterators Sets Maps.
C++ / G4MICE Course Session 2 Basic C++ types. Control and Looping Functions in C Function/method signatures and scope.
This recitation 1 An interesting point about A3: Using previous methods to avoid work in programming and debugging. How much time did you spend writing.
Lecture 7 : Intro. to STL (Standard Template Library)
Intro to the C++ STL Timmie Smith September 6, 2001.
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++ template examples Today: Using Class and Function Templates Two examples –Function template for printing different types –Class template for.
1 Chapter 3 Lists, Stacks, and Queues Reading: Sections 3.1, 3.2, 3.3, 3.4 Abstract Data Types (ADT) Iterators Implementation of Vector.
1 The Standard Template Library Drozdek Section 3.7.
Glenn Stevenson CSIS 113A MSJC CSIS 123A Lecture 3 Vectors.
Lecture 7.  There are 2 types of libraries used by standard C++ The C standard library (math.h) and C++ The C++ standard template library  Allows us.
CSE202: Lecture 5The Ohio State University1 Selection Structures.
Copyright © Curt Hill STL Priority Queue A Heap-Like Adaptor Class.
CSE 332: C++ templates and generic programming II Review: Concepts and Models Templates impose requirements on type parameters –Types that are plugged.
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
C++ Standard Template Library
Regarding homework 9 Many low grades
Programming with ANSI C ++
Standard Template Library
Collections Intro What is the STL? Templates, collections, & iterators
Prof. Michael Neary Lecture 7: The STL Prof. Michael Neary
Abstract Data Types Iterators Vector ADT Sections 3.1, 3.2, 3.3, 3.4
STL: Traversing a Vector
Control Structures Part 3
Lesson 25 Miscellaneous Topics
Collections Intro What is the STL? Templates, collections, & iterators
SPL – PS1 Introduction to C++.
Presentation transcript:

CSE 303 Lecture 25 Loose Ends and Random Topics slides created by Marty Stepp http://www.cs.washington.edu/303/

Enumerations (enum) enum: A type that consists entirely of a set of constant values. Useful for creating a simple constrained type with only a few values in C/C++, an enum silently converts to/from int type (0-based) enum Name {value0, value1, ..., valueN}; enum Suit {CLUBS, DIAMONDS, HEARTS, SPADES}; ... Suit s = CLUBS; if (s != DIAMONDS) { ... }

Ternary operator ? : test ? value1 : value2 ternary operator: one that involves 3 operands if test is true, evaluates to value1; evaluates to value2 similar to an if/else statement, but at the expression level (rather than a block of statements) Example: int min(int a, int b) { return (a < b) ? a : b; }

Templates template: A function or class that accepts a type as a parameter allows it to work with many different data types // defining a template function template <class Name> returntype name(parameters) { statements; } // calling a template function name<TypeName>(parameters); Example: // Returns the lesser of two values. If equal, returns B. template <class T> T min(T a, T b) { return (a < b) ? a : b; Date sooner = min<Date>(date1, date2);

STL Standard Template Library (STL): a library of C++ data structures vector, list, stack, queue, priority queue, set, bit set, map, multi-map equivalent to Java Collections API; strives for flexibility and speed STL also includes: Iterators: iterate over objects in containers Algorithms: do something to each object in a containers (sort, etc.) Other stuff: function objects, smart "auto" pointers, etc. flaws / potential drawbacks STL collections store copies of elements instead of references STL produces long/terrible compiler error messages

STL code example #include <vector> using namespace std; vector<Point> v; v.push_back(Point(3, 5)); v.push_back(Point(4, 7)); ... for (vector<Point>::iterator iter = v.begin(); iter != v.end(); ++iter) { Point& p = *iter; cout << p; }