SlideServe
Menu
Préférences
© SlideServe · v2026

Generic Programming

oscarstevens avatar
19 diapositives · 227 Views · Jan 04, 2020

Generic Programming. Karl Lieberherr. What is it?. Goal: to have libraries of generic or reusable software components reusable means widely adaptable, but still efficient adaptation is done by programming language mechanism rather than manual text editing. What is it?.

Generic Programming - slide 1
01 / 19Generic Programming
1 / 17

Télécharger la présentation

Generic Programming
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. Generic Programming Karl Lieberherr Generic Programming

  2. What is it? • Goal: to have libraries of generic or reusable software components • reusable means widely adaptable, but stillefficient • adaptation is done by programming language mechanism rather than manual text editing. Generic Programming

  3. What is it? • Focus on high degree of adaptability and efficiency • Essential idea: • Generic algorithms, not self-contained, use container access operations • Container classes with iterator classes Generic Programming

  4. What is it? • Expressing algorithms with minimal assumptions about data abstractions, and vice versa, thus making them as interoperable as possible • Lifting of a concrete algorithm to as a general level as possible without losing efficiency Generic Programming

  5. What is it? • Lifting of a concrete algorithm to as a general level as possible without losing efficiency i.e., the most abstract form such that when specialized back to the concrete case the result is just as efficient as the original algorithm. • From Dagstuhl 98 conference on generic programming Generic Programming

  6. What is it? • Generic programming is about making programs more adaptable by making them more general • Embody non-traditional kinds of polymorphism • Parameters of a generic program are rich in structure (programs, types, graphs). • From Workshop on Gen. Prog. Sweden 98 Generic Programming

  7. Overview of STL components • Containers • Sequence containers • Sorted Associative Containers • Generic Algorithms • find, merge, search, copy, count, sort, accumulate • Iterators • Function Objects • Adaptors • Allocators Generic Programming

  8. Function object Container Generic Algorithm List(T) Sort Less(T) Iterator Using STL is about plugging the right components together. Generic Programming

  9. Iterators • Input Iterator: reading • Output Iterator: writing • Forward Iterator: Input Iterator, Output Iterator, traversal in one direction • Bidirectional Iterator: Forward Iterator plus bidirectional traversal • Random Access Iterator: Bidirectional Iterator, constant time access Generic Programming

  10. template <class InputIterator, class T> InputIterator find(InputIterator first, InputIterator last, const T& value) { while (first != last && *first != value) ++ first; return first; } Works with any input iterator since (1) it only applies !=, * and ++ to its iterator parameters (2) it never tries to assign to objects it obtains using * and (3) it is a single pass algorithm. Designing Generic Algorithms Generic Programming

  11. Constant versus Mutable Iterators • Forward, bidirectional and random-access iterators can be mutable or constant. Generic Programming

  12. Iterator categories provided by containers Generic Programming

  13. Generic Algorithms • Basic algorithm organization • in-place: places result into same container • copying: copies result to a different container • Nonmutating Sequence Algorithms • find, adjacent_find, count, for_each,… • Mutating Sequence Algorithms • copy, copy_backward, fill, generate, ... Generic Programming

  14. Generic Algorithms • Sorting-Related Algorithms • sort, partial_sort, nth_element, binary_search, ... • Generalized Numeric Algorithms • accumulate, partial_sum, adjacent_difference, ... Generic Programming

  15. Containers • Sequence containers • vector, deque, list • Sorted associative containers • set, multiset, map and multimap Generic Programming

  16. Container Adaptors • Change interface of another component • Stack Container Adaptor • Queue Container Adaptor • Dequeue Container Adaptor Generic Programming

  17. Iterator Adaptors • Change interface of an iterator • reverse_bidirectional_iterator • reverse_iterator (mutable) • const_iterator (immutable) • Insert Iterators • back_inserter • front_inserter • inserter Generic Programming

  18. Function Adaptors • Negators • Binders (partial evaluation) • Adaptors for Pointers to Functions Generic Programming

  19. Summary • STL does a good job at providing a library of reusable components. • But generic programming can be much more generic than STL indicates. • Parameterize with more complex structures than classes. Generic Programming