STL概述¶
STL(Standard Template Library,标准模板库)是C++标准库中的一个重要组成部分,提供了一系列的容器、算法和迭代器,用于解决常见的数据结构和算法问题。
STL主要由以下几个部分组成:
-
Containers(容器): How do we store groups of things?
-
Iterators(迭代器): How do we traverse containers?
-
Functors(函数对象/函子): How can we represent functions as objects?
-
Algorithms(算法): How do we transform and modify containers in a generic way?
容器¶
迭代器¶
函数对象/函子¶
函子(Functor)是C++中的一种对象,可以像函数一样被调用,因此也叫函数对象。
Definition1
A functor is any object that defines an operator().
In English: an object that acts like a function.
函子通常用于实现回调函数、事件处理等。