50 likes | 179 Vues
This presentation delves into the advanced concepts of multi-paradigm software development, with a specific focus on generic programming in C++. It highlights the significance of the Standard Template Library (STL) as a flexible and efficient framework, incorporating algorithms, containers, and iterators. By emphasizing abstraction techniques for algorithms, the session covers how generic programming allows for argument types to be as general as possible, separating algorithm steps from argument properties. Participants will gain insights into type requirements, concepts, and their relationships, illustrated through practical examples.
E N D
E81 CSE 532S: Advanced Multi-Paradigm Software Development Introduction to Generic Programming in C++ Chris Gill Department of Computer Science Washington University, St. Louis cdgill@cs.wustl.edu
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 …
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
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
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