仿函数(functor),就是使一个类的使用看上去像一个函数.其实现就是类中实现一个operator(),这个类就有了类似函数的行为,就是一个仿函数类了. In computer programming, a function object[a] is a construct allowing an object to be invoked or called as if it were an ordinary function, usually with the same syntax (a…
谓词与函数对象 谓词 predicate C++ 标准定义谓词如下: The Predicate parameter is used whenever an algorithm expects a function object that when applied to the result of dereferencing the corresponding iterator returns a value testable as true. In other words, if an alg…
简单来将,仿函数(functor)就是一个重载了"()"运算符的struct或class,利用对象支持operator()的特性,来达到模拟函数调用效果的技术. 我们平时对一个集合类遍历的时候,例如vector,是这样做的: for(vector<int>::const_iterator iter = ivec.begin(); iter != ivec.end(); ++iter) { //do your whatever you want here } 例如下面的代码:…