Standard Template Library

Slides:



Advertisements
Similar presentations
Overloading Operators Overloading operators Unary operators Binary operators Member, non-member operators Friend functions and classes Function templates.
Advertisements

I NTRODUCING O PERATOR O VERLOADING Chapter 6 Department of CSE, BUET 1.
Chapter 8. Operator Overloading Operator overloading gives the opportunity to redefine C++ Operator overloading refers to redefine C++ operators such.
1 STL Algorithms Several STL algorithms require a functional argument. Consider an employee database. We may want to remove all employees who satisfy the.
CSE 332: C++ Classes From Procedural to Object-oriented Programming Procedural programming –Functions have been the main focus so far Function parameters.
CSE 332: C++ Algorithms II From Last Time: Search with Generic Iterators Third generalization: separate iterator type parameter We arrive at the find algorithm.
Data Structures Using C++1 Chapter 2 Object-Oriented Design (OOD) and C++
1 CSC241: Object Oriented Programming Lecture No 27.
STL Standard Template Library ● Good reference book: – The C++ Standard Library ● A Tutorial and Reference ● by Nicolai M. Josuttis ● 1999 – Addison Wesley.
CSE 332: C++ STL functors STL Functors: Functions vs. Function Objects STL Functors support function call syntax Algorithms invoke functions and operators.
11 COS220 Concepts of PLs AUBG, COS dept Lecture 36 OOP The STL Standard Template Library Reference: MS Developer Studio, Visual C++, Lafore, Chap 15 STL,
Operatorsand Operators Overloading. Introduction C++ allows operators to be overloaded specifically for a user-defined class. Operator overloading offers.
Generic Programming in C++. Generic Parameters Function for squaring a number: Function for squaring a number: sqrt(x) { return x * x; } C version: C.
Templates Class Templates Used to specify generic class types where class members data types can be specified as parameters, e.g. here is a generic List.
Iterator for linked-list traversal, Template & STL COMP171 Fall 2005.
CSE 332: C++ STL functors STL Functors: Functions vs. Function Objects STL Functors support function call syntax Algorithms invoke functions and operators.
Lecture 8-3 : STL Algorithms. STL Algorithms The Standard Template Library not only contains container classes, but also algorithms that operate on sequence.
Overview of C++ Templates
CS212: Object Oriented Analysis and Design Lecture 28: Functors.
Intro to the C++ STL Timmie Smith September 6, 2001.
C++ Programming: From Problem Analysis to Program Design, Second Edition Chapter 14: Overloading and Templates Overloading will not be covered.
Operator overloading: Overloading a unary operator is similar to overloading a binary operator except that there is one Operand to deal with. When you.
Programming in C++ Michal Brabec Petr Malý. Class / Struct Class / Struct consists of: data members function members constructors destructor copy constructor.
2/26/ Customization Points and Polymorphism Functional Programming Boost.Lambda.
1.What are the differences between composition(“has a” relationship) and inheritance(“is a” relationship)? 2.What is a base class? 3.How to declare a derived.
Algorithms CNS 3370 Copyright 2003, Fresh Sources, Inc.
1 Chapter 1 C++ Templates Readings: Sections 1.6 and 1.7.
Chapter 17 – Templates. Function Templates u Express general form for a function u Example: template for adding two numbers Lesson 17.1 template Type.
Overview of STL Function Objects
Lecture 5 – Function (Part 2) FTMK, UTeM – Sem /2014.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Function Templates 16.2.
Generic Programming in C++ Giuseppe Attardi Università di Pisa.
Washington WASHINGTON UNIVERSITY IN ST LOUIS More on the STL: Function Objects and Generic Algorithms in the STL Fred Kuhns Computer Science and Engineering.
Lecture 36 OOP The STL Standard Template Library
Motivation for Generic Programming in C++
Templates.
Lecture 7-2 : STL Iterators
CSE687 - Object Oriented Design class notes Survey of the C++ Programming Language Jim Fawcett Spring 2004.
Object-Oriented Design (OOD) and C++
Vectors Holds a set of elements, like an array
Programmer-Defined Functions, Call-by-Value, Multiple Files Lab 5
Jim Fawcett Copyright ©
Template Policies and Traits By Example
A Doubly Linked List There’s the need to access a list in reverse order prev next data dnode header 1.
Starting Out with C++ Early Objects Eighth Edition
18 – Sequential Containers
Lecture 7-2 : STL Iterators
ADT Implementations: Templates and Standard Containers
Today’s Learning Objective
C++ Functions, Classes, and Templates
priority_queue<T>
CS212: Object Oriented Analysis and Design
Templates Class Templates
Introduction to Programming
Operator Overloading.
Standard Template Library (STL)
COP 3330 Object-oriented Programming in C++
Lecture 8-2 : STL Iterators and Algorithms
Standard Template Library
Class: Special Topics Overloading (methods) Copy Constructors
Jim Fawcett CSE687 – Object Oriented Design Spring 2002
Template Policies and Traits By Example
Jim Fawcett CSE687 – Object Oriented Design Spring 2002
C++ data types.
Some Definitions vector, string, deque, and list are standard sequence containers. set, multiset, map, multimap, unordered_set, unordered_multiset, unordered_map.
Jim Fawcett Copyright ©
Object-Oriented Programming and class Design
Standard Template Library
Presentation transcript:

Standard Template Library CSE687 - Object Oriented Design Standard Template Library Jim Fawcett Spring 2000 Standard Template Library

STL Header Files for Containers Standard Template Library

Standard Template Library Other STL Header Files Standard Template Library

Standard Template Library STL Iterators Standard Template Library

Standard Template Library STL Functions unary and binary functions: take single argument of the template type // unary function void printElem(int val) { cout << “value is: “ << val << endl; } void main( ) { list<int> li; : // unary function used in algorithm for_each(li.begin(), li.end(), printElem); } Standard Template Library

Standard Template Library STL Functions predicate: function taking a template type and returning bool // predicate bool positive(T val) { return (val > 0); } void main( ) { list<int> li; : // return location of first positive value list<int>::iterator = find_if(li.begin(), li.end(), positive); } Standard Template Library

Standard Template Library STL Function Adapters negators: not1 takes unary predicate and negates it not2 takes binary predicate and negates it // predicate bool positive(T val) { return (val > 0); } void main( ) { list<int> li; : // return location of first non-positive value list<int>::iterator = find_if(li.begin(), li.end(), not1(positive)); } Standard Template Library

Standard Template Library STL Function Adapters binders: bind1 binds value to first argument of a binary_function bind2 binds value to second argument of binary_function void main( ) { list<int> li; : // return location of first value greater than 5 list<int>::iterator = find_if(li.begin(), li.end(), bind2(greater<int>(),5)); } Standard Template Library

Standard Template Library STL Function Objects Function objects: class with constructor and single member operator() template <class T> class myFunc { public: myFunc( /*arguments save needed state info */) { } T operator()(/* args for func obj */) { /* call some useful function with saved state info and args as its parameters */ } private: /* state info here */ } Standard Template Library

Standard Template Library STL Function Objects Standard Template Library

Standard Template Library Algorithms by Type Standard Template Library

Algorithms by Type (continued) Standard Template Library