Boost logo

Boost :

From: Greg Dehaas (GregDehaas_at_[hidden])
Date: 2002-12-16 01:39:06


Thanks to Douglas Gregor for the bind1st and boost::bind help :)

I wrote some macros/etc that came out to something like this:

----------------------------------------------------------------------------
------------------------
<File=functors.h>
//Boost
#include <boost/function.hpp>
#include <boost/bind.hpp>

//Macros for binding functions + methods
#define BINDMETHOD5(object,function)
boost::bind(function,object,_1,_2,_3,_4,_5)
#define BINDFUNCTION5(function) boost::bind(function,_1,_2,_3,_4,_5)
#define BINDMETHOD4(object,function)
boost::bind(function,object,_1,_2,_3,_4)
#define BINDFUNCTION4(function) boost::bind(function,_1,_2,_3,_4)
#define BINDMETHOD3(object,function) boost::bind(function,object,_1,_2,_3)
#define BINDFUNCTION3(function) boost::bind(function,_1,_2,_3)
#define BINDMETHOD2(object,function) boost::bind(function,object,_1,_2)
#define BINDFUNCTION2(function) boost::bind(function,_1,_2)
#define BINDMETHOD1(object,function) boost::bind(function,object,_1)
#define BINDFUNCTION1(function) boost::bind(function,_1)
#define BINDMETHOD(object,function) BINDMETHOD1(object,function)
#define BINDFUNCTION(function) BINDFUNCTION1(object,function)

//Macros for functor creation
#define FUNCTOR boost::function
#define FUNCTOR1 boost::function1
#define FUNCTOR2 boost::function2
#define FUNCTOR3 boost::function3
#define FUNCTOR4 boost::function4
#define FUNCTOR5 boost::function5

/*To create functors, do the following:
        void FunctionName(int a, int b, int c)
                becomes
        boost::function3<void,int,int,int>
*/
----------------------------------------------------------------------------
------------------------

The FUNCTORx macros are just for convenience and appearance
Typically I would create a FUNCTORx datatype in a class somewhere
and then later use BINDMETHODx or BINDFUNCTIONx to bind some other
function/method to it
Fairly simple once you understand how boost does it :)
(Or perhaps it's because I don't exactly know boost very well)

Greg


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk