Download presentation
Presentation is loading. Please wait.
1
Introduction to Generic Programming in C++
E81 CSE 532S: Advanced Multi-Paradigm Software Development Introduction to Generic Programming in C++ Chris Gill Department of Computer Science Washington University, St. Louis Title slide
2
Each Paradigm Has a Particular View
“Computer programming is largely a matter of algorithms and data structures.” Austern pp. 3 (Generic Programming Paradigm) Object-based might say “methods and data” OO might say “inheritance and polymorphism” Patterns might say “design forces and contexts” And so forth …
3
What is the STL? An abstract library of concepts
A formal hierarchy of software requirements A library of interchangeable modules Algorithms Containers Iterators Function objects, and much more A flexible and efficient software framework An extensible platform for software development
4
What is Generic Programming?
An abstraction technique for algorithms Argument types are as general as possible Separates algorithm steps & argument properties What GoF design pattern does this resemble? Type requirements can be specified, systematized Can cluster requirements into abstractions Termed “concepts” Concepts can refine other concepts Captures relationships between concepts Analogy to inheritance hierarchies A type that meets a concept’s requirements Is a “model” of the concept Can be plugged in to meet that set of requirements
5
Generic Algorithm Example
STL linear search (based on Austern pp. 13): template <typename Iterator, typename T> Iterator find2 (Iterator first, Iterator last, const T & value) { while (first != last && *first != value) { ++first; } return first; A generic algorithm Searches any one-dimensional sequence of elements, for any type on which the operators work
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.