making functors adaptable

F

Fraser Ross

Functors taking 1 argument for operator() should inherit from
unary_function and those with 2 arguments should inherit from
binary_function. If a functor has zero arguments for its operator()
should it inherit from anything to make it adaptable? I've not heard of
anything before which is surprising. If books don't talk about it then
its an unanswered question to many people. Maybe its adaptable without
inheriting anything, which would explain the absence. It may be an
oversight of the STL.

Fraser.


*** Free account sponsored by SecureIX.com ***
*** Encrypt your Internet usage with a free VPN account from http://www.SecureIX.com ***
 
R

Rolf Magnus

Fraser Ross said:
Functors taking 1 argument for operator() should inherit from
unary_function and those with 2 arguments should inherit from
binary_function. If a functor has zero arguments for its operator()
should it inherit from anything to make it adaptable? I've not heard of
anything before which is surprising. If books don't talk about it then
its an unanswered question to many people. Maybe its adaptable without
inheriting anything, which would explain the absence. It may be an
oversight of the STL.

Is there any standard algorithm that uses function objects with no
arguments?
 
M

Maxim Yegorushkin

Fraser said:
Functors taking 1 argument for operator() should inherit from
unary_function and those with 2 arguments should inherit from
binary_function.

The only thing that the base classes do is declare typedefs for return
type and argument types.
If a functor has zero arguments for its operator()
should it inherit from anything to make it adaptable?

Just declare result_type typedef in your nullary functor.
I've not heard of anything before which is surprising. If books don't talk about it then
its an unanswered question to many people. Maybe its adaptable without
inheriting anything, which would explain the absence. It may be an
oversight of the STL.

Note that no stl algorithm or functor adaptor work with nullary
functors. boost::bind and boost::function do.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top