Boost logo

Boost Users :

From: Jeff Flinn (TriumphSprint2000_at_[hidden])
Date: 2004-12-28 10:48:20


David Abrahams wrote:
> Hossein Haeri wrote:
>> Dave,
>>
...
>>>> can't do that for a functor. Is that right?
>>>
>>> That's because function object types (what you're
>>> calling functors)
>>
>> It's not me, AFAIK. That's another common name of
>> them. Isn't that?
>
> Yes, but it's frowned upon by many because it's a completely invented
> meaning for a term that already had a well-established meaning in
> mathematics and computing. If you read Stroustrup or almost any other
> author who's also on the committee you'll see the term "function
> object" and not "functor."

I had copied this description from a letter from the editor in either CUJ or
C++ Report some years back.

----------
Here's the low-down, to which any mathematician would attest:

A function is a transformation that maps an element to an element.
A functional is a transformation that maps a function to an element.
A functor is a transformation that maps a function to a function. (The truth
functions in propositional logic are also sometimes called functors.)

Simple, isn't it? We seem to use the first one correctly, but not the other
two. What people commonly call a functor (thanks to Dr. Coplien, shame!) is
what the C++ Standard calls a function object. It seems some people like to
use "functional" to mean the same thing. Shame again! A function object is
simply that, an instance of a class that behaves like a function by virtue
of its operator(). Some function objects, like bind2nd, do behave like
functors, in that they take a function object as input and return a function
object as output. Only these deserve the functor moniker, although you may
prefer "function object adaptor" (or is it spelled "adapter" :-), as denoted
in the C++ Standard.
----------

Jeff


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net