软件设计(II)教学课件:Chapter 14 Introduction to the Standard Template Library.pptVIP

  • 1
  • 0
  • 约9.28千字
  • 约 31页
  • 2021-11-30 发布于安徽
  • 举报

软件设计(II)教学课件:Chapter 14 Introduction to the Standard Template Library.ppt

Customized Function Objects By defining member function operator() in a class * class My { public: int operator()(int a) {return a;} } ; My mo; int x = mo(0); template typename T class greater : binary_function T,T,bool { public: bool operator() (const T x, const T y) const{return xy;} }; class BiggerThan{ public: const int testValue; BiggerThan(int x) : testValue(x) { } bool operator()(int val) const { return val testValue; } }; int my[] = {1, 7, 3, 4, 3, 3, 1, 2}; sort(my, my + 8, Mygreaterint()); BiggerThan bt(10); coutbt(11) bt(9)endl; My m; coutm(4)endl; 1 0 4 A Summary Concepts STL, Container, Iterator, Algorithm Three types of containers Function, Operation, Algorithm Functional object Features of different containers Main functions of containers Features of STL algorithm Use of functional object * Chapter 14 Introduction to the Standard Template Library §14.1 Introduction §14.2 Containers §14.3 Iterators §14.4 Algorithms §14.5 Function Objects §14.1 Introduction Standard Template Library (STL) 标准模板库 A software library included in the C++ Standard Library Purpose To standardize commonly used components History Originally developed by Alexander Stepanov in 1980s Accepted as part of C++ standard in Feb. 1994 * Components of STL Containers(容器) A container object, such as vector, used to store a collection of data, often referred to as elements Algorithms(算法) Functions to manipulate data such as sorting, searching, and comparing elements. Most of them use iterators to access the elements in the container. Iterators(迭代器) Objects that facilitate traversing through the elements in a container Like built-in pointers that provide a convenient way to access and manipulate the elements in a container * Components of STL * Algorithm 3 Algorithm 2 Algorithm 1 Container Object 1 Object 2 Object 3 Iterator 3 Iterator 2 Iterator 1 §14.2 Containers * Containers vector deque list Sequence containers set

文档评论(0)

1亿VIP精品文档

相关文档