r/cpp • • Jan 26 '17

Stop calling "Function Objects" "Functors"

http://jackieokay.com/2017/01/26/functors.html
0 Upvotes

23 comments sorted by

View all comments

38

u/STL MSVC STL Dev Jan 26 '17

When I say function object, I’m referring to any type with a defined operator().

Actually, that isn't the Standard's formal definition, where a function object is anything that can be called with parentheses. This includes function pointers, classes with overloaded operator(), lambdas (special case of the previous one), and classes that are implicitly convertible to function pointers.

Granted, the latter basically never comes up except in <functional> unit tests.

Most C++ programmers can probably agree that C++11 lambda functions changed their lives.

On the other hand, "lambda function" drives me nuts. Lambdas aren't functions (or std::functions), but such terminology encourages confusion.

Formally, a functor is a mapping between categories that preserves identity morphisms and compositions of morphisms.

No, that's math. Programming is different. Mathematicians consider a "vector" to be different from what we consider it to be.

8

u/SuperV1234 https://romeo.training | C++ Mentoring & Consulting Jan 26 '17 edited Jan 26 '17

On the other hand, "lambda function" drives me nuts.

Well... cppreference may need some adjustments then

(EDIT: fixed it myself - the header for the lambda page was "Lambda functions")