Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Vocabulary for naming functor-like things

0 views
Skip to first unread message

Howard Gardner

unread,
May 13, 2006, 4:33:42 PM5/13/06
to
/*
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! ]

0 new messages