C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Vocabulary for naming functor-like things

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
Howard Gardner
Guest





PostPosted: Sat May 13, 2006 9:21 pm    Post subject: Vocabulary for naming functor-like things Reply with quote



/*
constructs like function and functor have common
names:

function is a function.

functor binds a call to a type, and all paramaeters to an
object.

I wrote some examples of other constructs:

function_call binds a function call to a type.

mixed_call binds a call to a type, and some of the parameters
to an object.

static_call binds a call to a type.

static_functor binds a call and all parameters to a type.

There are many other potential constructs too, but I think that's
plenty to get the point across: you can bind some combination of
(function, parameters) to some combination of (type, object), and
sometimes you can do it (statically or not).

Do these other constructs have common names?
*/

#include <fstream>
using std::cout;
using std::endl;

int function( int fA, int fB ){return fA + fB;}

struct functor
{
functor( int fA, int fB ):cA( fA ), cB( fB ){}
int operator()(){return function( cA, cB );}
int cA;
int cB;
};

struct function_call
{
int operator()( int fA, int fB ){return function( fA, fB );}
};

struct mixed_call
{
mixed_call( int fA ): cA( fA ){}
int operator()( int fB ){return function( cA, fB );}
int cA;
};

struct static_call
{
static int call( int fA, int fB ){return function( fA, fB );}
};

template< int kA, int kB >
struct static_functor
{
static int call(){return function( kA, kB );}
};

int main()
{
cout << function( 21, 21) << endl;

functor fFunctor( 14, 28 );
cout << fFunctor() << endl;

function_call fFunctionCall;
cout << fFunctionCall( 3, 39 ) << endl;

mixed_call fMixedCall( 11 );
cout << fMixedCall( 31 ) << endl;

cout << static_call::call( 232, -190 ) << endl;

cout << static_functor< 27, 15 >::call() << endl;
}

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.