473,385 Members | 1,548 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

making functors adaptable

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 ***
Feb 17 '06 #1
4 2058
"Fraser Ross" <fraserATmembers.v21.co.uk> wrote:
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?

Feb 17 '06 #2

"Rolf Magnus"
Is there any standard algorithm that uses function objects with no
arguments?

Theres generate_n.

Fraser.
*** Free account sponsored by SecureIX.com ***
*** Encrypt your Internet usage with a free VPN account from http://www.SecureIX.com ***
Feb 17 '06 #3

Fraser Ross wrote:
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.

Feb 17 '06 #4
Rolf Magnus wrote:
"Fraser Ross" <fraserATmembers.v21.co.uk> wrote:

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?


std::generate is the only one comes to mind.

V
--
Please remove capital As from my address when replying by mail
Feb 17 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: CoolPint | last post by:
Can anyone explain how I can make the following function accept an default arguement for the last parameter, which should be an optional functor? template <typename T, typename FUNCTOR> void...
41
by: AngleWyrm | last post by:
I have created a new container class, called the hat. It provides random selection of user objects, both with and without replacement, with non-uniform probabilities. Uniform probabilities are a...
2
by: nsgi_2004 | last post by:
Hi, I have been learning about functors and at first everything was clear. Make a class and overload operator () so that an object of the functor can be thought of as a function. However, I...
1
by: Matthias | last post by:
Hello, I basically want to implement a general resource manager which should have a caching and a loading policy so that I can exchange those. Here's some example code of how it should work: ...
10
by: SpOiLeR | last post by:
I have function bool IsGood (const std::string& sr); I want to use that function in std::not1 STL functor. I tried this: not1(IsGood) /* error : 'std::unary_negate<_Fn1> std::not1(const...
8
by: michael.lesniak | last post by:
Hello, I'm learning C++ for a couple of days and play a bit with the algorithms provided in the STL. One thing I don't understand is the fact that classes inherited of functors have to be...
4
by: tryptik | last post by:
Hello all, I have a question about iterators. I have a container of functors that operate on an std::string. The functors go something like this: class Functor { std::string...
2
by: Jon Slaughter | last post by:
I'm trying to mess with functors and the way I want it to work is that when I create a functor it will automatically add itself to an array. The attached code demonstrates what I mean. The...
4
by: Christopher | last post by:
I used to just use a plain old function pointer is a call to std::sort. My colleagues are telling me that I need to use a "functor". Ok, I google and see that a functor is a class with a public...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.