仿函数(functor)

Posted zzfx

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了仿函数(functor)相关的知识,希望对你有一定的参考价值。

仿函数(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 function parameter that can also be a function). Function objects are often called functors.

 

A typical use of a function object is in writing callback functions. A callback in procedural languages, such as C, may be performed by using function pointers.[2] However it can be difficult or awkward to pass a state into or out of the callback function. This restriction also inhibits more dynamic behavior of the function. A function object solves those problems since the function is really a fa?ade for a full object, carrying its own state.

以上是关于仿函数(functor)的主要内容,如果未能解决你的问题,请参考以下文章

SGI STL functors(仿函数) 12

c++仿函数 functor

STL——容器(Set & multiset)之 仿函数(函数对象)functor 的用法

STL——容器(Set & multiset)之 仿函数(函数对象)functor 的用法

函数对象(仿函数)

仿函数及其应用